1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:04:44 -07:00

go/packages: fix staticcheck warnings

Ran gopls with staticcheck enabled and found these warnings.

Change-Id: I0b41c0daa19ac98c778d643530c9cb3f5f994399
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201442
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-10-16 14:52:08 -04:00
parent 6f5e27347a
commit eec4c98bf5
4 changed files with 31 additions and 15 deletions

View File

@ -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") {

View File

@ -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
}

View File

@ -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...)
}

View File

@ -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 {