mirror of
https://github.com/golang/go
synced 2024-11-26 14:46:47 -07:00
cmd/vet: change some warnings to errors for consistency.
Fixes #4980. R=golang-dev, rsc, dsymonds CC=golang-dev https://golang.org/cl/7479044
This commit is contained in:
parent
b3915112b9
commit
8cf6e75e2a
@ -9,6 +9,12 @@ calls whose arguments do not align with the format string. Vet uses heuristics
|
||||
that do not guarantee all reports are genuine problems, but it can find errors
|
||||
not caught by the compilers.
|
||||
|
||||
Its exit code is 2 for erroneous invocation of the tool, 1 if a
|
||||
problem was reported, and 0 otherwise. Note that the tool does not
|
||||
check every possible problem and depends on unreliable heuristics
|
||||
so it should be used as guidance only, not as a firm indicator of
|
||||
program correctness.
|
||||
|
||||
By default all checks are performed, but if explicit flags are provided, only
|
||||
those identified by the flags are performed.
|
||||
|
||||
|
@ -186,17 +186,21 @@ func doPackage(names []string) {
|
||||
for _, name := range names {
|
||||
f, err := os.Open(name)
|
||||
if err != nil {
|
||||
errorf("%s: %s", name, err)
|
||||
// Warn but continue to next package.
|
||||
warnf("%s: %s", name, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
data, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
errorf("%s: %s", name, err)
|
||||
warnf("%s: %s", name, err)
|
||||
return
|
||||
}
|
||||
checkBuildTag(name, data)
|
||||
parsedFile, err := parser.ParseFile(fs, name, bytes.NewReader(data), 0)
|
||||
if err != nil {
|
||||
errorf("%s: %s", name, err)
|
||||
warnf("%s: %s", name, err)
|
||||
return
|
||||
}
|
||||
files = append(files, &File{fset: fs, name: name, file: parsedFile})
|
||||
astFiles = append(astFiles, parsedFile)
|
||||
@ -229,7 +233,8 @@ func doPackage(names []string) {
|
||||
|
||||
func visit(path string, f os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
errorf("walk error: %s", err)
|
||||
warnf("walk error: %s", err)
|
||||
return err
|
||||
}
|
||||
// One package per directory. Ignore the files themselves.
|
||||
if !f.IsDir() {
|
||||
@ -239,7 +244,7 @@ func visit(path string, f os.FileInfo, err error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// walkDir recursively walks the tree looking for .go files.
|
||||
// walkDir recursively walks the tree looking for Go packages.
|
||||
func walkDir(root string) {
|
||||
filepath.Walk(root, visit)
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func (f *File) checkCanonicalMethod(id *ast.Ident, t *ast.FuncType) {
|
||||
actual = strings.TrimPrefix(actual, "func")
|
||||
actual = id.Name + actual
|
||||
|
||||
f.Warnf(id.Pos(), "method %s should have signature %s", actual, expectFmt)
|
||||
f.Badf(id.Pos(), "method %s should have signature %s", actual, expectFmt)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ func (f *File) checkPrint(call *ast.CallExpr, name string, firstArg int) {
|
||||
if sel, ok := args[0].(*ast.SelectorExpr); ok {
|
||||
if x, ok := sel.X.(*ast.Ident); ok {
|
||||
if x.Name == "os" && strings.HasPrefix(sel.Sel.Name, "Std") {
|
||||
f.Warnf(call.Pos(), "first argument to %s is %s.%s", name, x.Name, sel.Sel.Name)
|
||||
f.Badf(call.Pos(), "first argument to %s is %s.%s", name, x.Name, sel.Sel.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func (f *File) checkCanonicalFieldTag(field *ast.Field) {
|
||||
|
||||
tag, err := strconv.Unquote(field.Tag.Value)
|
||||
if err != nil {
|
||||
f.Warnf(field.Pos(), "unable to read struct tag %s", field.Tag.Value)
|
||||
f.Badf(field.Pos(), "unable to read struct tag %s", field.Tag.Value)
|
||||
return
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ func (f *File) checkCanonicalFieldTag(field *ast.Field) {
|
||||
// new key:value to end and checking that
|
||||
// the tag parsing code can find it.
|
||||
if reflect.StructTag(tag+` _gofix:"_magic"`).Get("_gofix") != "_magic" {
|
||||
f.Warnf(field.Pos(), "struct field tag %s not compatible with reflect.StructTag.Get", field.Tag.Value)
|
||||
f.Badf(field.Pos(), "struct field tag %s not compatible with reflect.StructTag.Get", field.Tag.Value)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) {
|
||||
// Convert the package name to an import path, and compare to a whitelist.
|
||||
path := pkgPath(f, pkg.Name)
|
||||
if path == "" {
|
||||
f.Warnf(c.Pos(), "unresolvable package for %s.%s literal", pkg.Name, s.Sel.Name)
|
||||
f.Badf(c.Pos(), "unresolvable package for %s.%s literal", pkg.Name, s.Sel.Name)
|
||||
return
|
||||
}
|
||||
typeName := path + "." + s.Sel.Name
|
||||
|
Loading…
Reference in New Issue
Block a user