Skip to content

Commit 2f7fd03

Browse files
committed
use filepath.WalkDir instead of filepath.Walk
requires Go 1.16 or later
1 parent ffe36aa commit 2f7fd03

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
- name: Setup Go
1111
uses: actions/setup-go@v2
1212
with:
13-
go-version: '1.x'
13+
go-version: '1.16'
1414
- name: Run tests
1515
run: go test -cover ./...

analyze.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"go/ast"
1010
"go/parser"
1111
"go/token"
12+
"io/fs"
1213
"log"
1314
"os"
1415
"path/filepath"
@@ -39,17 +40,17 @@ func Analyze(paths []string, ignore *regexp.Regexp) Stats {
3940
}
4041

4142
func analyzeDir(dirname string, ignore *regexp.Regexp, stats Stats) Stats {
42-
filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
43-
if err == nil && isGoFile(info) {
43+
filepath.WalkDir(dirname, func(path string, entry fs.DirEntry, err error) error {
44+
if err == nil && isGoFile(entry) {
4445
stats = analyzeFile(path, ignore, stats)
4546
}
4647
return err
4748
})
4849
return stats
4950
}
5051

51-
func isGoFile(f os.FileInfo) bool {
52-
return !f.IsDir() && strings.HasSuffix(f.Name(), ".go")
52+
func isGoFile(entry fs.DirEntry) bool {
53+
return !entry.IsDir() && strings.HasSuffix(entry.Name(), ".go")
5354
}
5455

5556
func analyzeFile(path string, ignore *regexp.Regexp, stats Stats) Stats {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/fzipp/gocyclo
22

3-
go 1.15
3+
go 1.16

0 commit comments

Comments
 (0)