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.
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)
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() {
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)
}
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)
}
}
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)
}
}
}
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
}
// 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
}
}
// 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