Added the ability to scan directories recursively.
As a build step it's often useful to run a linter over your whole
project and see what needs linting.
diff --git a/README b/README
index 378dbb4..cf08ec2 100644
--- a/README
+++ b/README
@@ -3,7 +3,7 @@
To install, run
go get github.com/golang/lint/golint
-Invoke golint with one or more filenames.
+Invoke golint with one or more filenames or directories.
The output of this tool is a list of suggestions in Vim quickfix format,
which is accepted by lots of different editors.
diff --git a/golint/golint.go b/golint/golint.go
index 6eecea4..2c9d7ce 100644
--- a/golint/golint.go
+++ b/golint/golint.go
@@ -12,6 +12,9 @@
"fmt"
"io/ioutil"
"log"
+ "os"
+ "path/filepath"
+ "strings"
"github.com/golang/lint"
)
@@ -23,10 +26,19 @@
// TODO(dsymonds): Support linting of stdin.
for _, filename := range flag.Args() {
- lintFile(filename)
+ if isDir(filename) {
+ lintDir(filename)
+ } else {
+ lintFile(filename)
+ }
}
}
+func isDir(filename string) bool {
+ fi, err := os.Stat(filename)
+ return err == nil && fi.IsDir()
+}
+
func lintFile(filename string) {
src, err := ioutil.ReadFile(filename)
if err != nil {
@@ -46,3 +58,12 @@
}
}
}
+
+func lintDir(dirname string) {
+ filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
+ if err == nil && !info.IsDir() && strings.HasSuffix(path, ".go") {
+ lintFile(path)
+ }
+ return err
+ })
+}