Skip to content

Commit

Permalink
use filepath.WalkDir instead of filepath.Walk
Browse files Browse the repository at this point in the history
requires Go 1.16 or later
  • Loading branch information
fzipp committed Jul 17, 2021
1 parent ffe36aa commit 2f7fd03
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -10,6 +10,6 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.x'
go-version: '1.16'
- name: Run tests
run: go test -cover ./...
9 changes: 5 additions & 4 deletions analyze.go
Expand Up @@ -9,6 +9,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/fs"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -39,17 +40,17 @@ 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 err == nil && isGoFile(entry) {
stats = analyzeFile(path, ignore, stats)
}
return err
})
return stats
}

func isGoFile(f os.FileInfo) bool {
return !f.IsDir() && strings.HasSuffix(f.Name(), ".go")
func isGoFile(entry fs.DirEntry) bool {
return !entry.IsDir() && strings.HasSuffix(entry.Name(), ".go")
}

func analyzeFile(path string, ignore *regexp.Regexp, stats Stats) Stats {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,3 +1,3 @@
module github.com/fzipp/gocyclo

go 1.15
go 1.16

0 comments on commit 2f7fd03

Please sign in to comment.