]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: change some warnings to errors for consistency.
authorRob Pike <r@golang.org>
Tue, 5 Mar 2013 22:31:17 +0000 (14:31 -0800)
committerRob Pike <r@golang.org>
Tue, 5 Mar 2013 22:31:17 +0000 (14:31 -0800)
Fixes #4980.

R=golang-dev, rsc, dsymonds
CC=golang-dev
https://golang.org/cl/7479044

src/cmd/vet/doc.go
src/cmd/vet/main.go
src/cmd/vet/method.go
src/cmd/vet/print.go
src/cmd/vet/structtag.go
src/cmd/vet/taglit.go

index f164eaca2af8bc4e3d5671d4eeaf4c60bf10d1bc..eb1e436f0bb02f7acc919c3ef47707520dbbdbef 100644 (file)
@@ -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.
 
index 20f6cca1abafcd806aecf69c4c2aa66aed3c02ed..b354d8d77de32aca6587c251a367ff1e4ea44644 100644 (file)
@@ -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)
 }
index bf982dc7acad1f82ed3a4efd4c7ad9fa606ceed8..8064235f468db32c260b811b9c655222cc13a4c3 100644 (file)
@@ -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)
        }
 }
 
index fb0fb9f9b7a116a7c64e36b9831cded7fca0c27a..7bb99b011479e0b0b745c5cfa3e193bda8b473ae 100644 (file)
@@ -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)
                                }
                        }
                }
index 545e420c100c3cb482ff81b491ebe0bebbec18bf..d83578836835fa2253d473a42e1411b180d73b9a 100644 (file)
@@ -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
        }
 }
index 8ff1a419dab620c9461a2adc62f99ede4a484e7a..71bd7b71d053804c3c6a9e96b2adafa4df2691fe 100644 (file)
@@ -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