From f518253944afdd72f611215dda9b0e3e8688fc95 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Sun, 11 Feb 2018 15:20:44 +0300 Subject: [PATCH 1/2] [FIX] Cleanup code --- cmd/dep/ensure_test.go | 2 +- cmd/dep/gopath_scanner_test.go | 4 ++-- cmd/dep/prune.go | 2 +- cmd/dep/status.go | 2 +- cmd/dep/status_test.go | 3 +-- gps/_testdata/src/relimport/dotdot/a.go | 2 +- gps/deduce.go | 2 +- gps/filesystem_test.go | 12 ++++++------ gps/solve_basic_test.go | 14 +++++++------- gps/solve_bimodal_test.go | 4 ++-- hack/licenseok/main.go | 2 +- internal/importers/base/importer.go | 2 +- internal/test/integration/testproj.go | 2 +- internal/test/test.go | 4 ++-- manifest.go | 2 +- manifest_test.go | 10 +++++----- 16 files changed, 34 insertions(+), 35 deletions(-) diff --git a/cmd/dep/ensure_test.go b/cmd/dep/ensure_test.go index 15d16fd9..0b75d3bf 100644 --- a/cmd/dep/ensure_test.go +++ b/cmd/dep/ensure_test.go @@ -231,7 +231,7 @@ func TestValidateUpdateArgs(t *testing.T) { stderrOutput.Reset() // Fill up the locked projects - lockedProjects := []gps.LockedProject{} + lockedProjects := make([]gps.LockedProject, 0, len(c.lockedProjects)) for _, lp := range c.lockedProjects { pi := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(lp)} lockedProjects = append(lockedProjects, gps.NewLockedProject(pi, gps.NewVersion("v1.0.0"), []string{})) diff --git a/cmd/dep/gopath_scanner_test.go b/cmd/dep/gopath_scanner_test.go index bfab02e8..ad9f9b80 100644 --- a/cmd/dep/gopath_scanner_test.go +++ b/cmd/dep/gopath_scanner_test.go @@ -15,8 +15,8 @@ import ( "github.com/golang/dep/internal/test" ) -const testProject1 string = "github.com/sdboyer/deptest" -const testProject2 string = "github.com/sdboyer/deptestdos" +const testProject1 = "github.com/sdboyer/deptest" +const testProject2 = "github.com/sdboyer/deptestdos" // NewTestContext creates a unique context with its own GOPATH for a single test. func NewTestContext(h *test.Helper) *dep.Ctx { diff --git a/cmd/dep/prune.go b/cmd/dep/prune.go index bf406244..08d86cf2 100644 --- a/cmd/dep/prune.go +++ b/cmd/dep/prune.go @@ -172,7 +172,7 @@ fail: func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]string, error) { logger.Println("Calculating prune. Checking the following packages:") sort.Strings(keep) - toDelete := []string{} + var toDelete []string err := filepath.Walk(vendorDir, func(path string, info os.FileInfo, err error) error { if _, err := os.Lstat(path); err != nil { return nil diff --git a/cmd/dep/status.go b/cmd/dep/status.go index c14ab5b2..238dc967 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -301,7 +301,7 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error { func (cmd *statusCommand) validateFlags() error { // Operating mode flags. - opModes := []string{} + var opModes []string if cmd.old { opModes = append(opModes, "-old") diff --git a/cmd/dep/status_test.go b/cmd/dep/status_test.go index d18f9404..b8b3aea9 100644 --- a/cmd/dep/status_test.go +++ b/cmd/dep/status_test.go @@ -10,11 +10,10 @@ import ( "log" "path/filepath" "reflect" + "strings" "testing" "text/tabwriter" - "strings" - "github.com/golang/dep" "github.com/golang/dep/gps" "github.com/golang/dep/internal/test" diff --git a/gps/_testdata/src/relimport/dotdot/a.go b/gps/_testdata/src/relimport/dotdot/a.go index 6cfc99f2..aa1e8392 100644 --- a/gps/_testdata/src/relimport/dotdot/a.go +++ b/gps/_testdata/src/relimport/dotdot/a.go @@ -5,7 +5,7 @@ package dotdot import ( - relimport ".." + ".." ) var ( diff --git a/gps/deduce.go b/gps/deduce.go index d29481d4..f2e8e2b1 100644 --- a/gps/deduce.go +++ b/gps/deduce.go @@ -16,7 +16,7 @@ import ( "strings" "sync" - radix "github.com/armon/go-radix" + "github.com/armon/go-radix" "github.com/pkg/errors" ) diff --git a/gps/filesystem_test.go b/gps/filesystem_test.go index af29846f..24fe9e39 100644 --- a/gps/filesystem_test.go +++ b/gps/filesystem_test.go @@ -135,7 +135,7 @@ func TestDeriveFilesystemState(t *testing.T) { "simple-file", }, links: []fsLink{ - fsLink{ + { path: "link", to: "nonexisting", broken: true, @@ -150,7 +150,7 @@ func TestDeriveFilesystemState(t *testing.T) { "simple-file", }, links: []fsLink{ - fsLink{ + { path: "link", to: "", broken: true, @@ -164,12 +164,12 @@ func TestDeriveFilesystemState(t *testing.T) { fs: fsTestCase{ before: filesystemState{ links: []fsLink{ - fsLink{ + { path: "link1", to: "link2", circular: true, }, - fsLink{ + { path: "link2", to: "link1", circular: true, @@ -178,12 +178,12 @@ func TestDeriveFilesystemState(t *testing.T) { }, after: filesystemState{ links: []fsLink{ - fsLink{ + { path: "link1", to: "", circular: true, }, - fsLink{ + { path: "link2", to: "", circular: true, diff --git a/gps/solve_basic_test.go b/gps/solve_basic_test.go index 910b9d62..dcb2d37c 100644 --- a/gps/solve_basic_test.go +++ b/gps/solve_basic_test.go @@ -1355,7 +1355,7 @@ func (sm *depspecSourceManager) GetManifestAndLock(id ProjectIdentifier, v Versi } } - return nil, nil, fmt.Errorf("Project %s at version %s could not be found", id, v) + return nil, nil, fmt.Errorf("project %s at version %s could not be found", id, v) } func (sm *depspecSourceManager) ListPackages(id ProjectIdentifier, v Version) (pkgtree.PackageTree, error) { @@ -1404,7 +1404,7 @@ func (sm *depspecSourceManager) ListPackages(id ProjectIdentifier, v Version) (p } } - return pkgtree.PackageTree{}, fmt.Errorf("Project %s at version %s could not be found", pid.n, v) + return pkgtree.PackageTree{}, fmt.Errorf("project %s at version %s could not be found", pid.n, v) } func (sm *depspecSourceManager) ListVersions(id ProjectIdentifier) ([]PairedVersion, error) { @@ -1431,7 +1431,7 @@ func (sm *depspecSourceManager) ListVersions(id ProjectIdentifier) ([]PairedVers } if len(pvl) == 0 { - return nil, fmt.Errorf("Project %s could not be found", id) + return nil, fmt.Errorf("project %s could not be found", id) } return pvl, nil } @@ -1444,7 +1444,7 @@ func (sm *depspecSourceManager) RevisionPresentIn(id ProjectIdentifier, r Revisi } } - return false, fmt.Errorf("Project %s has no revision %s", id, r) + return false, fmt.Errorf("project %s has no revision %s", id, r) } func (sm *depspecSourceManager) SourceExists(id ProjectIdentifier) (bool, error) { @@ -1461,7 +1461,7 @@ func (sm *depspecSourceManager) SourceExists(id ProjectIdentifier) (bool, error) func (sm *depspecSourceManager) SyncSourceFor(id ProjectIdentifier) error { // Ignore err because it can't happen if exist, _ := sm.SourceExists(id); !exist { - return fmt.Errorf("Source %s does not exist", id) + return fmt.Errorf("source %s does not exist", id) } return nil } @@ -1480,7 +1480,7 @@ func (sm *depspecSourceManager) DeduceProjectRoot(ip string) (ProjectRoot, error return ProjectRoot(ip[:len(n)]), nil } } - return "", fmt.Errorf("Could not find %s, or any parent, in list of known fixtures", ip) + return "", fmt.Errorf("could not find %s, or any parent, in list of known fixtures", ip) } func (sm *depspecSourceManager) SourceURLsForPath(ip string) ([]*url.URL, error) { @@ -1547,7 +1547,7 @@ func (b *depspecBridge) listVersions(id ProjectIdentifier) ([]Version, error) { func (b *depspecBridge) verifyRootDir(path string) error { root := b.sm.(fixSM).rootSpec() if string(root.n) != path { - return fmt.Errorf("Expected only root project %q to verifyRootDir(), got %q", root.n, path) + return fmt.Errorf("expected only root project %q to verifyRootDir(), got %q", root.n, path) } return nil diff --git a/gps/solve_bimodal_test.go b/gps/solve_bimodal_test.go index 7dfa7562..a5d34211 100644 --- a/gps/solve_bimodal_test.go +++ b/gps/solve_bimodal_test.go @@ -1445,7 +1445,7 @@ func (sm *bmSourceManager) ListPackages(id ProjectIdentifier, v Version) (pkgtre } } - return pkgtree.PackageTree{}, fmt.Errorf("Project %s at version %s could not be found", id, v) + return pkgtree.PackageTree{}, fmt.Errorf("project %s at version %s could not be found", id, v) } func (sm *bmSourceManager) GetManifestAndLock(id ProjectIdentifier, v Version, an ProjectAnalyzer) (Manifest, Lock, error) { @@ -1460,7 +1460,7 @@ func (sm *bmSourceManager) GetManifestAndLock(id ProjectIdentifier, v Version, a } // TODO(sdboyer) proper solver-type errors - return nil, nil, fmt.Errorf("Project %s at version %s could not be found", id, v) + return nil, nil, fmt.Errorf("project %s at version %s could not be found", id, v) } // computeBimodalExternalMap takes a set of depspecs and computes an diff --git a/hack/licenseok/main.go b/hack/licenseok/main.go index f47c7715..6f049c4b 100644 --- a/hack/licenseok/main.go +++ b/hack/licenseok/main.go @@ -156,7 +156,7 @@ func addLicense(b []byte, path string, fmode os.FileMode) error { } func hashBang(b []byte) []byte { - var line []byte + var line = make([]byte, 0, len(b)) for _, c := range b { line = append(line, c) if c == '\n' { diff --git a/internal/importers/base/importer.go b/internal/importers/base/importer.go index 82dff700..9a5f5f85 100644 --- a/internal/importers/base/importer.go +++ b/internal/importers/base/importer.go @@ -68,7 +68,7 @@ func (i *Importer) lookupVersionForLockedProject(pi gps.ProjectIdentifier, c gps var branchConstraint gps.PairedVersion gps.SortPairedForUpgrade(versions) // Sort versions in asc order - matches := []gps.Version{} + var matches []gps.Version for _, v := range versions { if v.Revision() == rev { matches = append(matches, v) diff --git a/internal/test/integration/testproj.go b/internal/test/integration/testproj.go index 760e1cc5..1ae280ce 100644 --- a/internal/test/integration/testproj.go +++ b/internal/test/integration/testproj.go @@ -21,7 +21,7 @@ import ( ) const ( - projectRoot string = "src/github.com/golang/notexist" + projectRoot = "src/github.com/golang/notexist" ) // RunFunc defines the function signature for an integration test command to execute. diff --git a/internal/test/test.go b/internal/test/test.go index 9a7fbc8d..36c75ac3 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -34,8 +34,8 @@ var ( ) const ( - manifestName string = "Gopkg.toml" - lockName string = "Gopkg.lock" + manifestName = "Gopkg.toml" + lockName = "Gopkg.lock" ) func init() { diff --git a/manifest.go b/manifest.go index add9236f..453de7af 100644 --- a/manifest.go +++ b/manifest.go @@ -15,7 +15,7 @@ import ( "github.com/golang/dep/gps" "github.com/golang/dep/gps/pkgtree" - toml "github.com/pelletier/go-toml" + "github.com/pelletier/go-toml" "github.com/pkg/errors" ) diff --git a/manifest_test.go b/manifest_test.go index 28d5e43b..cfb699e0 100644 --- a/manifest_test.go +++ b/manifest_test.go @@ -476,7 +476,7 @@ func TestCheckRedundantPruneOptions(t *testing.T) { pruneOptions: gps.CascadingPruneOptions{ DefaultOptions: 15, PerProjectOptions: map[gps.ProjectRoot]gps.PruneOptionSet{ - "github.com/golang/dep": gps.PruneOptionSet{ + "github.com/golang/dep": { NestedVendor: pvtrue, UnusedPackages: pvtrue, NonGoFiles: pvtrue, @@ -495,7 +495,7 @@ func TestCheckRedundantPruneOptions(t *testing.T) { pruneOptions: gps.CascadingPruneOptions{ DefaultOptions: 1, PerProjectOptions: map[gps.ProjectRoot]gps.PruneOptionSet{ - "github.com/golang/dep": gps.PruneOptionSet{ + "github.com/golang/dep": { NestedVendor: pvtrue, UnusedPackages: pvfalse, NonGoFiles: pvfalse, @@ -514,12 +514,12 @@ func TestCheckRedundantPruneOptions(t *testing.T) { pruneOptions: gps.CascadingPruneOptions{ DefaultOptions: 7, PerProjectOptions: map[gps.ProjectRoot]gps.PruneOptionSet{ - "github.com/golang/dep": gps.PruneOptionSet{ + "github.com/golang/dep": { NestedVendor: pvtrue, NonGoFiles: pvtrue, GoTests: pvtrue, }, - "github.com/other/project": gps.PruneOptionSet{ + "github.com/other/project": { NestedVendor: pvtrue, UnusedPackages: pvfalse, GoTests: pvfalse, @@ -798,7 +798,7 @@ func TestToRawPruneOptions_Panic(t *testing.T) { pruneOptions := gps.CascadingPruneOptions{ DefaultOptions: 1, PerProjectOptions: map[gps.ProjectRoot]gps.PruneOptionSet{ - "github.com/carolynvs/deptest": gps.PruneOptionSet{ + "github.com/carolynvs/deptest": { NestedVendor: pvtrue, }, }, From 2f5dec17a7746db35143cbb3b50c42154fe484f5 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Sun, 11 Feb 2018 16:57:41 +0300 Subject: [PATCH 2/2] fix review comments --- gps/_testdata/src/relimport/dotdot/a.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gps/_testdata/src/relimport/dotdot/a.go b/gps/_testdata/src/relimport/dotdot/a.go index aa1e8392..6cfc99f2 100644 --- a/gps/_testdata/src/relimport/dotdot/a.go +++ b/gps/_testdata/src/relimport/dotdot/a.go @@ -5,7 +5,7 @@ package dotdot import ( - ".." + relimport ".." ) var (