Skip to content

Commit

Permalink
fix: linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 10, 2022
1 parent 5a22066 commit c593736
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -10,6 +10,7 @@ linters:
- nlreturn
- gci
- exhaustivestruct
- varnamelen
linters-settings:
maligned:
# print struct with more effective memory layout or not, false by default
Expand Down
6 changes: 5 additions & 1 deletion glob.go
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion glob_test.go
@@ -1,3 +1,4 @@
// nolint: gocritic
package fileglob

import (
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
7 changes: 7 additions & 0 deletions prefix_test.go
@@ -1,3 +1,4 @@
// nolint: gocritic
package fileglob

import (
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
})
}
Expand Down

0 comments on commit c593736

Please sign in to comment.