golint: Add a flag to cause a non-zero exit when suggestions are made.
Fixes #65.
diff --git a/golint/golint.go b/golint/golint.go
index eb39199..83b0e26 100644
--- a/golint/golint.go
+++ b/golint/golint.go
@@ -19,7 +19,11 @@
"github.com/golang/lint"
)
-var minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it")
+var (
+ minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it")
+ setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found")
+ suggestions int
+)
func usage() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
@@ -56,6 +60,11 @@
default:
lintFiles(flag.Args()...)
}
+
+ if *setExitStatus && suggestions > 0 {
+ fmt.Fprintf(os.Stderr, "Found %d lint suggestions; failing.\n", suggestions)
+ os.Exit(1)
+ }
}
func isDir(filename string) bool {
@@ -88,6 +97,7 @@
for _, p := range ps {
if p.Confidence >= *minConfidence {
fmt.Printf("%v: %s\n", p.Position, p.Text)
+ suggestions++
}
}
}