-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from loeffel-io/feature/loeffel-io/glob-ignor…
…e-index feat: add glob ignore index
- Loading branch information
Showing
10 changed files
with
130 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "glob", | ||
srcs = ["glob.go"], | ||
importpath = "github.com/loeffel-io/ls-lint/v2/internal/glob", | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//internal/rule", | ||
"@com_github_bmatcuk_doublestar_v4//:doublestar", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package glob | ||
|
||
import ( | ||
"github.com/bmatcuk/doublestar/v4" | ||
"github.com/loeffel-io/ls-lint/v2/internal/rule" | ||
"io/fs" | ||
"strings" | ||
) | ||
|
||
func Index[IndexValue bool | map[string][]rule.Rule](filesystem fs.FS, index map[string]IndexValue, files bool) (err error) { | ||
for key, value := range index { | ||
var matches []string | ||
|
||
if !strings.ContainsAny(key, "*{}") { | ||
continue | ||
} | ||
|
||
if matches, err = doublestar.Glob(filesystem, key); err != nil { | ||
return err | ||
} | ||
|
||
if len(matches) == 0 { | ||
delete(index, key) | ||
continue | ||
} | ||
|
||
for _, match := range matches { | ||
var matchInfo fs.FileInfo | ||
|
||
if matchInfo, err = fs.Stat(filesystem, match); err != nil { | ||
return err | ||
} | ||
|
||
if !files && !matchInfo.IsDir() { | ||
continue | ||
} | ||
|
||
index[match] = value | ||
delete(index, key) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters