aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/fzipp/gocyclo/analyze.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/fzipp/gocyclo/analyze.go')
-rw-r--r--vendor/github.com/fzipp/gocyclo/analyze.go35
1 files changed, 19 insertions, 16 deletions
diff --git a/vendor/github.com/fzipp/gocyclo/analyze.go b/vendor/github.com/fzipp/gocyclo/analyze.go
index c053e83e6..2d8bcff25 100644
--- a/vendor/github.com/fzipp/gocyclo/analyze.go
+++ b/vendor/github.com/fzipp/gocyclo/analyze.go
@@ -9,6 +9,7 @@ import (
"go/ast"
"go/parser"
"go/token"
+ "io/fs"
"log"
"os"
"path/filepath"
@@ -39,8 +40,11 @@ func Analyze(paths []string, ignore *regexp.Regexp) Stats {
}
func analyzeDir(dirname string, ignore *regexp.Regexp, stats Stats) Stats {
- filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
- if err == nil && isGoFile(info) {
+ filepath.WalkDir(dirname, func(path string, entry fs.DirEntry, err error) error {
+ if isSkipDir(entry) {
+ return filepath.SkipDir
+ }
+ if err == nil && isGoFile(entry) {
stats = analyzeFile(path, ignore, stats)
}
return err
@@ -48,8 +52,19 @@ func analyzeDir(dirname string, ignore *regexp.Regexp, stats Stats) Stats {
return stats
}
-func isGoFile(f os.FileInfo) bool {
- return !f.IsDir() && strings.HasSuffix(f.Name(), ".go")
+var skipDirs = map[string]bool{
+ "testdata": true,
+ "vendor": true,
+}
+
+func isSkipDir(entry fs.DirEntry) bool {
+ return entry.IsDir() && (skipDirs[entry.Name()] ||
+ (strings.HasPrefix(entry.Name(), ".") && entry.Name() != "." && entry.Name() != "..") ||
+ strings.HasPrefix(entry.Name(), "_"))
+}
+
+func isGoFile(entry fs.DirEntry) bool {
+ return !entry.IsDir() && strings.HasSuffix(entry.Name(), ".go")
}
func analyzeFile(path string, ignore *regexp.Regexp, stats Stats) Stats {
@@ -137,15 +152,3 @@ func funcName(fn *ast.FuncDecl) string {
}
return fn.Name.Name
}
-
-// recvString returns a string representation of recv of the
-// form "T", "*T", or "BADRECV" (if not a proper receiver type).
-func recvString(recv ast.Expr) string {
- switch t := recv.(type) {
- case *ast.Ident:
- return t.Name
- case *ast.StarExpr:
- return "*" + recvString(t.X)
- }
- return "BADRECV"
-}