Permalink
Browse files

golint: Add a flag to cause a non-zero exit when suggestions are made.

Fixes #65.
  • Loading branch information...
1 parent 8f348af commit 58f662d2fc0598c6c36a92ae29af1caa6ec89d7a @dsymonds dsymonds committed Apr 26, 2016
Showing with 11 additions and 1 deletion.
  1. +11 −1 golint/golint.go
View
@@ -19,7 +19,11 @@ import (
"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 @@ func main() {
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 @@ func lintFiles(filenames ...string) {
for _, p := range ps {
if p.Confidence >= *minConfidence {
fmt.Printf("%v: %s\n", p.Position, p.Text)
+ suggestions++
}
}
}

1 comment on commit 58f662d

@marcuswestin

Nice! Thanks!

Please sign in to comment.