diff --git a/go/packages/golist.go b/go/packages/golist.go index 873ec12943..2c1bfde8d1 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -465,6 +465,10 @@ func runNamedQueries(cfg *Config, driver driver, response *responseDeduper, quer } files, err := ioutil.ReadDir(modRoot) + if err != nil { + panic(err) // See above. + } + for _, f := range files { if strings.HasSuffix(f.Name(), ".go") { simpleMatches = append(simpleMatches, rel) @@ -532,7 +536,7 @@ func runNamedQueries(cfg *Config, driver driver, response *responseDeduper, quer // We're only trying to look at stuff in the module cache, so // disable the network. This should speed things up, and has // prevented errors in at least one case, #28518. - tmpCfg.Env = append(append([]string{"GOPROXY=off"}, cfg.Env...)) + tmpCfg.Env = append([]string{"GOPROXY=off"}, cfg.Env...) var err error tmpCfg.Dir, err = ioutil.TempDir("", "gopackages-modquery") @@ -580,17 +584,29 @@ func roots(cfg *Config) ([]gopathwalk.Root, string, error) { var roots []gopathwalk.Root // Always add GOROOT. - roots = append(roots, gopathwalk.Root{filepath.Join(goroot, "/src"), gopathwalk.RootGOROOT}) + roots = append(roots, gopathwalk.Root{ + Path: filepath.Join(goroot, "/src"), + Type: gopathwalk.RootGOROOT, + }) // If modules are enabled, scan the module dir. if modDir != "" { - roots = append(roots, gopathwalk.Root{modDir, gopathwalk.RootCurrentModule}) + roots = append(roots, gopathwalk.Root{ + Path: modDir, + Type: gopathwalk.RootCurrentModule, + }) } // Add either GOPATH/src or GOPATH/pkg/mod, depending on module mode. for _, p := range gopath { if modDir != "" { - roots = append(roots, gopathwalk.Root{filepath.Join(p, "/pkg/mod"), gopathwalk.RootModuleCache}) + roots = append(roots, gopathwalk.Root{ + Path: filepath.Join(p, "/pkg/mod"), + Type: gopathwalk.RootModuleCache, + }) } else { - roots = append(roots, gopathwalk.Root{filepath.Join(p, "/src"), gopathwalk.RootGOPATH}) + roots = append(roots, gopathwalk.Root{ + Path: filepath.Join(p, "/src"), + Type: gopathwalk.RootGOPATH, + }) } } @@ -983,7 +999,7 @@ func invokeGo(cfg *Config, args ...string) (*bytes.Buffer, error) { // (the Graphic characters without spaces) and may also exclude the // characters !"#$%&'()*,:;<=>?[\]^`{|} and the Unicode replacement character U+FFFD. return unicode.IsOneOf([]*unicode.RangeTable{unicode.L, unicode.M, unicode.N, unicode.P, unicode.S}, r) && - strings.IndexRune("!\"#$%&'()*,:;<=>?[\\]^`{|}\uFFFD", r) == -1 + !strings.ContainsRune("!\"#$%&'()*,:;<=>?[\\]^`{|}\uFFFD", r) } if len(stderr.String()) > 0 && strings.HasPrefix(stderr.String(), "# ") { if strings.HasPrefix(strings.TrimLeftFunc(stderr.String()[len("# "):], isPkgPathRune), "\n") { diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index e3c70080b8..c67fa2c35b 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -96,7 +96,7 @@ func testLoadImportsGraph(t *testing.T, exporter packagestest.Exporter) { } // Check graph topology. - graph, all := importGraph(initial) + graph, _ := importGraph(initial) wantGraph := ` container/list golang.org/fake/a @@ -135,7 +135,7 @@ func testLoadImportsGraph(t *testing.T, exporter packagestest.Exporter) { } // Check graph topology. - graph, all = importGraph(initial) + graph, all := importGraph(initial) wantGraph = ` container/list golang.org/fake/a @@ -227,7 +227,7 @@ func testLoadImportsGraph(t *testing.T, exporter packagestest.Exporter) { if err != nil { t.Fatal(err) } - graph, all = importGraph(initial) + graph, _ = importGraph(initial) wantGraph = ` * golang.org/fake/subdir/d * golang.org/fake/subdir/d [golang.org/fake/subdir/d.test] @@ -1576,11 +1576,11 @@ func testSizes(t *testing.T, exporter packagestest.Exporter) { } } -// TestContains_FallbackSticks ensures that when there are both contains and non-contains queries +// TestContainsFallbackSticks ensures that when there are both contains and non-contains queries // the decision whether to fallback to the pre-1.11 go list sticks across both sets of calls to // go list. -func TestContains_FallbackSticks(t *testing.T) { packagestest.TestAll(t, testContains_FallbackSticks) } -func testContains_FallbackSticks(t *testing.T, exporter packagestest.Exporter) { +func TestContainsFallbackSticks(t *testing.T) { packagestest.TestAll(t, testContainsFallbackSticks) } +func testContainsFallbackSticks(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", Files: map[string]interface{}{ @@ -2590,7 +2590,7 @@ func constant(p *packages.Package, name string) *types.Const { } func copyAll(srcPath, dstPath string) error { - return filepath.Walk(srcPath, func(path string, info os.FileInfo, err error) error { + return filepath.Walk(srcPath, func(path string, info os.FileInfo, _ error) error { if info.IsDir() { return nil } diff --git a/go/packages/packagestest/expect.go b/go/packages/packagestest/expect.go index ef41606ff0..ad769fffd3 100644 --- a/go/packages/packagestest/expect.go +++ b/go/packages/packagestest/expect.go @@ -156,7 +156,7 @@ func (e *Exported) getNotes() error { } l, err := expect.Parse(e.ExpectFileSet, filename, content) if err != nil { - return fmt.Errorf("Failed to extract expectations: %v", err) + return fmt.Errorf("failed to extract expectations: %v", err) } notes = append(notes, l...) } diff --git a/go/packages/packagestest/export.go b/go/packages/packagestest/export.go index 2361efb22d..234c8b3f9d 100644 --- a/go/packages/packagestest/export.go +++ b/go/packages/packagestest/export.go @@ -240,7 +240,7 @@ func Copy(source string) Writer { if !stat.Mode().IsRegular() { // cannot copy non-regular files (e.g., directories, // symlinks, devices, etc.) - return fmt.Errorf("Cannot copy non regular file %s", source) + return fmt.Errorf("cannot copy non regular file %s", source) } contents, err := ioutil.ReadFile(source) if err != nil {