diff --git a/.golangci.yml b/.golangci.yml index 4932f9b..6bb1353 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ linters: - nlreturn - gci - exhaustivestruct + - varnamelen linters-settings: maligned: # print struct with more effective memory layout or not, false by default diff --git a/glob.go b/glob.go index fee0751..e30a9ab 100644 --- a/glob.go +++ b/glob.go @@ -212,7 +212,7 @@ func compileOptions(optFuncs []OptFunc, pattern string) *globOptions { func filesInDirectory(options *globOptions, dir string) ([]string, error) { var files []string - return files, fs.WalkDir(options.fs, dir, func(path string, info fs.DirEntry, err error) error { + err := fs.WalkDir(options.fs, dir, func(path string, info fs.DirEntry, err error) error { if err != nil { return err } @@ -223,6 +223,10 @@ func filesInDirectory(options *globOptions, dir string) ([]string, error) { files = append(files, path) return nil }) + if err != nil { + return files, fmt.Errorf("failed to get files in directory: %w", err) + } + return files, nil } func cleanFilepaths(paths []string, prefix string) []string { diff --git a/glob_test.go b/glob_test.go index 766b456..1f179f8 100644 --- a/glob_test.go +++ b/glob_test.go @@ -1,3 +1,4 @@ +// nolint: gocritic package fileglob import ( @@ -21,6 +22,7 @@ func TestGlob(t *testing.T) { // nolint:funlen t.Run("real", func(t *testing.T) { t.Parallel() is := is.New(t) + var w bytes.Buffer matches, err := Glob("*_test.go", WriteOptions(&w)) is.NoErr(err) @@ -93,7 +95,7 @@ func TestGlob(t *testing.T) { // nolint:funlen var w bytes.Buffer matches, err := Glob(pattern, MaybeRootFS, QuoteMeta, WriteOptions(&w)) - is.True(err != nil) //exepected an error + is.True(err != nil) // expected an error is.True(strings.HasSuffix(err.Error(), "file does not exist")) // should have been file does not exist is.Equal([]string{}, matches) is.Equal(fmt.Sprintf("&{fs:%s matchDirectoriesDirectly:false prefix:%s pattern:%s}", prefix, prefix, glob.QuoteMeta(abs)), w.String()) diff --git a/prefix_test.go b/prefix_test.go index 93c0674..7e43efe 100644 --- a/prefix_test.go +++ b/prefix_test.go @@ -1,3 +1,4 @@ +// nolint: gocritic package fileglob import ( @@ -25,7 +26,9 @@ func TestStaticPrefix(t *testing.T) { } for _, testCase := range testCases { + testCase := testCase t.Run(testCase.pattern, func(t *testing.T) { + t.Parallel() is := is.New(t) prefix, err := staticPrefix(testCase.pattern) is.NoErr(err) @@ -52,7 +55,9 @@ func TestContainsMatchers(t *testing.T) { } for _, testCase := range testCases { + testCase := testCase t.Run(testCase.pattern, func(t *testing.T) { + t.Parallel() is := is.New(t) _, err := ast.Parse(lexer.NewLexer(testCase.pattern)) is.NoErr(err) @@ -73,7 +78,9 @@ func TestValidPattern(t *testing.T) { } for _, testCase := range testCases { + testCase := testCase t.Run(testCase.pattern, func(t *testing.T) { + t.Parallel() is.New(t).Equal(testCase.valid, ValidPattern(testCase.pattern) == nil) }) }