fix import ordering (#2322)

This commit is contained in:
Egon Elbre 2019-06-25 12:46:29 +03:00 committed by GitHub
parent fa802dc429
commit 6502143e79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 43 additions and 25 deletions

View File

@ -8,15 +8,14 @@ import (
"strconv"
"testing"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/dbutil/pgutil"
"storj.io/storj/internal/dbutil/pgutil/pgtest"
"storj.io/storj/internal/migrate"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
)
func TestCreate_Sqlite(t *testing.T) {

View File

@ -10,15 +10,14 @@ import (
"math/rand"
"testing"
"storj.io/storj/pkg/eestream"
"storj.io/storj/pkg/encryption"
"storj.io/storj/pkg/storj"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/memory"
"storj.io/storj/internal/testcontext"
"storj.io/storj/pkg/eestream"
"storj.io/storj/pkg/encryption"
"storj.io/storj/pkg/storj"
)
const (

View File

@ -14,13 +14,12 @@ import (
"go.uber.org/zap/zaptest"
"golang.org/x/sync/errgroup"
"storj.io/storj/pkg/peertls/tlsopts"
"storj.io/storj/internal/memory"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testplanet"
"storj.io/storj/pkg/kademlia"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/peertls/tlsopts"
"storj.io/storj/pkg/storj"
"storj.io/storj/pkg/transport"
)

View File

@ -8,8 +8,6 @@ import (
"fmt"
"testing"
"storj.io/storj/satellite/console"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vivint/infectious"
@ -25,6 +23,7 @@ import (
"storj.io/storj/pkg/storage/segments"
"storj.io/storj/pkg/storage/streams"
"storj.io/storj/pkg/storj"
"storj.io/storj/satellite/console"
)
const (

View File

@ -9,10 +9,10 @@ import (
"os"
"testing"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
)
func setenv(key, value string) func() {

View File

@ -7,15 +7,14 @@ import (
"crypto/x509"
"testing"
"storj.io/storj/pkg/peertls/extensions"
"storj.io/storj/pkg/peertls/tlsopts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testpeertls"
"storj.io/storj/pkg/identity"
"storj.io/storj/pkg/peertls"
"storj.io/storj/pkg/peertls/extensions"
"storj.io/storj/pkg/peertls/tlsopts"
"storj.io/storj/pkg/storj"
)

View File

@ -49,6 +49,7 @@ func main() {
Mode: packages.LoadAllSyntax,
Env: os.Environ(),
BuildFlags: buildFlags,
Tests: true,
}, pkgNames...)
if err != nil {
@ -85,19 +86,30 @@ func main() {
incorrectPkgs := []string{}
for _, pkg := range pkgs {
if !correctPackage(pkg) {
incorrectPkgs = append(incorrectPkgs, pkg.String())
incorrectPkgs = append(incorrectPkgs, pkg.PkgPath)
correct = false
}
}
if !correct {
fmt.Fprintln(os.Stderr, "Error: imports are not in the correct order for package/s: ", incorrectPkgs)
fmt.Fprintln(os.Stderr, "Correct order should be: std packages -> external packages -> storj.io packages.")
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Error: imports are not in the correct order for package/s: ")
for _, pkg := range incorrectPkgs {
fmt.Fprintln(os.Stderr, "\t"+pkg)
}
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Correct order should be: \n\tstd packages -> external packages -> storj.io packages.")
os.Exit(1)
}
}
func correctPackage(pkg *packages.Package) bool {
// ignore generated test binaries
if strings.HasSuffix(pkg.ID, ".test") {
return true
}
correct := true
for i, file := range pkg.Syntax {
path := pkg.CompiledGoFiles[i]
@ -160,6 +172,7 @@ func correctOrder(specgroups [][]ast.Spec) bool {
}
specgroups = specgroups[1:]
}
if len(specgroups) == 0 {
return true
}
@ -182,7 +195,18 @@ func correctOrder(specgroups [][]ast.Spec) bool {
}
std, other, storj = countGroup(specgroups[0])
return other > 0 && std+storj == 0
return other >= 0 && std+storj == 0
}
func printAll(groups [][]ast.Spec) {
defer fmt.Println("---")
for i, group := range groups {
fmt.Println("===", i)
for _, imp := range group {
imp := imp.(*ast.ImportSpec)
fmt.Println("\t", imp.Path.Value)
}
}
}
func countGroup(p []ast.Spec) (std, other, storj int) {

View File

@ -7,13 +7,12 @@ import (
"crypto/rand"
"testing"
"storj.io/storj/internal/testidentity"
"github.com/golang/protobuf/ptypes"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testidentity"
"storj.io/storj/pkg/auth/signing"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/storj"

View File

@ -8,13 +8,12 @@ import (
"testing"
"time"
"storj.io/storj/internal/testidentity"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testidentity"
"storj.io/storj/pkg/storj"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/storagenodedb/storagenodedbtest"

View File

@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testidentity"
"storj.io/storj/internal/testplanet"