Skip to content

Commit

Permalink
fix: Replace godirwalk with filepath.WalkDir
Browse files Browse the repository at this point in the history
  • Loading branch information
zerok committed Oct 4, 2024
1 parent c5180bf commit e8e183b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/gobwas/glob v0.2.3
github.com/google/go-cmp v0.6.0
github.com/google/go-jsonnet v0.20.0
github.com/karrick/godirwalk v1.17.0
github.com/pkg/errors v0.9.1
github.com/posener/complete v1.2.3
github.com/rs/zerolog v1.33.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down
37 changes: 15 additions & 22 deletions pkg/jsonnet/files.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package jsonnet

import (
"io/fs"
"os"
"path/filepath"

"github.com/gobwas/glob"
"github.com/karrick/godirwalk"
)

// FindFiles takes a file / directory and finds all Jsonnet files
Expand All @@ -21,31 +21,24 @@ func FindFiles(target string, excludes []glob.Glob) ([]string, error) {

var files []string

// godirwalk is faster than filepath.Walk, 'cause no os.Stat required
err = godirwalk.Walk(target, &godirwalk.Options{
Callback: func(rawPath string, de *godirwalk.Dirent) error {
// Normalize slashes for Windows
path := filepath.ToSlash(rawPath)
err = filepath.WalkDir(target, func(path string, d fs.DirEntry, err error) error {

Check failure on line 24 in pkg/jsonnet/files.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'err' seems to be unused, consider removing or renaming it as _ (revive)
path = filepath.ToSlash(path)
if d.IsDir() {
return nil
}

if de.IsDir() {
// excluded?
for _, g := range excludes {
if g.Match(path) {
return nil
}
}

// excluded?
for _, g := range excludes {
if g.Match(path) {
return nil
}
}

// only .jsonnet or .libsonnet
if ext := filepath.Ext(path); ext == ".jsonnet" || ext == ".libsonnet" {
files = append(files, path)
}
return nil
},
// faster, no sort required
Unsorted: true,
// only .jsonnet or .libsonnet
if ext := filepath.Ext(path); ext == ".jsonnet" || ext == ".libsonnet" {
files = append(files, path)
}
return nil
})
if err != nil {
return nil, err
Expand Down

0 comments on commit e8e183b

Please sign in to comment.