1
0
mirror of https://github.com/golang/go synced 2024-11-08 01:56:14 -07:00

cmd: go get golang.org/x/tools@d88ec18 && go mod vendor

This brings in CL 261725, which applies the vet buildtag checker
to ignored files.

For #41184.

Change-Id: I5f241db5a71fa84d0af0b9e9f8a75ff5bb3dd116
Reviewed-on: https://go-review.googlesource.com/c/go/+/261958
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Russ Cox 2020-10-13 14:19:20 -04:00
parent 52669c4a68
commit 1671509ea3
7 changed files with 42 additions and 24 deletions

View File

@ -9,5 +9,5 @@ require (
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449 golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect
golang.org/x/tools v0.0.0-20200918232735-d647fc253266 golang.org/x/tools v0.0.0-20201013174405-d88ec18c69c7
) )

View File

@ -30,8 +30,8 @@ golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73Ih
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200918232735-d647fc253266 h1:k7tVuG0g1JwmD3Jh8oAl1vQ1C3jb4Hi/dUl1wWDBJpQ= golang.org/x/tools v0.0.0-20201013174405-d88ec18c69c7 h1:z+ozLsKwDztt1oIueYsv07oF+mXNYIiwU0PQVXwmhlo=
golang.org/x/tools v0.0.0-20200918232735-d647fc253266/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20201013174405-d88ec18c69c7/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=

View File

@ -95,12 +95,13 @@ type Pass struct {
Analyzer *Analyzer // the identity of the current analyzer Analyzer *Analyzer // the identity of the current analyzer
// syntax and type information // syntax and type information
Fset *token.FileSet // file position information Fset *token.FileSet // file position information
Files []*ast.File // the abstract syntax tree of each file Files []*ast.File // the abstract syntax tree of each file
OtherFiles []string // names of non-Go files of this package OtherFiles []string // names of non-Go files of this package
Pkg *types.Package // type information about the package IgnoredFiles []string // names of ignored source files in this package
TypesInfo *types.Info // type information about the syntax trees Pkg *types.Package // type information about the package
TypesSizes types.Sizes // function for computing sizes of types TypesInfo *types.Info // type information about the syntax trees
TypesSizes types.Sizes // function for computing sizes of types
// Report reports a Diagnostic, a finding about a specific location // Report reports a Diagnostic, a finding about a specific location
// in the analyzed source code such as a potential mistake. // in the analyzed source code such as a potential mistake.

View File

@ -121,13 +121,14 @@ package being analyzed, and provides operations to the Run function for
reporting diagnostics and other information back to the driver. reporting diagnostics and other information back to the driver.
type Pass struct { type Pass struct {
Fset *token.FileSet Fset *token.FileSet
Files []*ast.File Files []*ast.File
OtherFiles []string OtherFiles []string
Pkg *types.Package IgnoredFiles []string
TypesInfo *types.Info Pkg *types.Package
ResultOf map[*Analyzer]interface{} TypesInfo *types.Info
Report func(Diagnostic) ResultOf map[*Analyzer]interface{}
Report func(Diagnostic)
... ...
} }
@ -139,6 +140,12 @@ files such as assembly that are part of this package. See the "asmdecl"
or "buildtags" analyzers for examples of loading non-Go files and reporting or "buildtags" analyzers for examples of loading non-Go files and reporting
diagnostics against them. diagnostics against them.
The IgnoredFiles field provides the names, but not the contents,
of ignored Go and non-Go source files that are not part of this package
with the current build configuration but may be part of other build
configurations. See the "buildtags" analyzer for an example of loading
and checking IgnoredFiles.
The ResultOf field provides the results computed by the analyzers The ResultOf field provides the results computed by the analyzers
required by this one, as expressed in its Analyzer.Requires field. The required by this one, as expressed in its Analyzer.Requires field. The
driver runs the required analyzers first and makes their results driver runs the required analyzers first and makes their results

View File

@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"go/ast" "go/ast"
"go/parser"
"strings" "strings"
"unicode" "unicode"
@ -33,6 +34,20 @@ func runBuildTag(pass *analysis.Pass) (interface{}, error) {
return nil, err return nil, err
} }
} }
for _, name := range pass.IgnoredFiles {
if strings.HasSuffix(name, ".go") {
f, err := parser.ParseFile(pass.Fset, name, nil, parser.ParseComments)
if err != nil {
// Not valid Go source code - not our job to diagnose, so ignore.
return nil, nil
}
checkGoFile(pass, f)
} else {
if err := checkOtherFile(pass, name); err != nil {
return nil, err
}
}
}
return nil, nil return nil, nil
} }
@ -132,13 +147,6 @@ func checkLine(line string, pastCutoff bool) error {
} }
func checkArguments(fields []string) error { func checkArguments(fields []string) error {
// The original version of this checker in vet could examine
// files with malformed build tags that would cause the file to
// be always ignored by "go build". However, drivers for the new
// analysis API will analyze only the files selected to form a
// package, so these checks will never fire.
// TODO(adonovan): rethink this.
for _, arg := range fields[1:] { for _, arg := range fields[1:] {
for _, elem := range strings.Split(arg, ",") { for _, elem := range strings.Split(arg, ",") {
if strings.HasPrefix(elem, "!!") { if strings.HasPrefix(elem, "!!") {

View File

@ -63,6 +63,7 @@ type Config struct {
ImportPath string ImportPath string
GoFiles []string GoFiles []string
NonGoFiles []string NonGoFiles []string
IgnoredFiles []string
ImportMap map[string]string ImportMap map[string]string
PackageFile map[string]string PackageFile map[string]string
Standard map[string]bool Standard map[string]bool
@ -333,6 +334,7 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
Fset: fset, Fset: fset,
Files: files, Files: files,
OtherFiles: cfg.NonGoFiles, OtherFiles: cfg.NonGoFiles,
IgnoredFiles: cfg.IgnoredFiles,
Pkg: pkg, Pkg: pkg,
TypesInfo: info, TypesInfo: info,
TypesSizes: tc.Sizes, TypesSizes: tc.Sizes,

View File

@ -45,7 +45,7 @@ golang.org/x/mod/zip
golang.org/x/sys/internal/unsafeheader golang.org/x/sys/internal/unsafeheader
golang.org/x/sys/unix golang.org/x/sys/unix
golang.org/x/sys/windows golang.org/x/sys/windows
# golang.org/x/tools v0.0.0-20200918232735-d647fc253266 # golang.org/x/tools v0.0.0-20201013174405-d88ec18c69c7
## explicit ## explicit
golang.org/x/tools/go/analysis golang.org/x/tools/go/analysis
golang.org/x/tools/go/analysis/internal/analysisflags golang.org/x/tools/go/analysis/internal/analysisflags