Skip to content

Commit

Permalink
refactor(fixer.go, main.go): replace regex with glob pattern for file…
Browse files Browse the repository at this point in the history
… ignoring

- Change variable naming and logic in `fixer.go` to use `filepath.Glob` for matching files, enhancing flexibility and usability.
- Update flag description in `main.go` to reflect the change from regex to glob pattern, improving clarity for end-users.
  • Loading branch information
yyoshiki41 committed May 5, 2024
1 parent dfb1e95 commit 5bc430c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go/parser"
"go/token"
"os"
"regexp"
"path/filepath"
"strings"
)

Expand All @@ -18,11 +18,15 @@ var (
)

func fix(filename, functionName string) error {
if i := *ignoreFileFlag; i != "" {
if ok, err := regexp.MatchString(i, filename); err != nil {
if p := *ignoreFileFlag; p != "" {
matches, err := filepath.Glob(p)
if err != nil {
return err
} else if ok {
return nil
}
for _, match := range matches {
if match == filename {
return nil
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
jsonFlag = flag.String("json", "", "JSON file generated by deadcode")
fileFlag = flag.String("file", "", "File to remove function from")
functionFlag = flag.String("function", "", "Function to remove")
ignoreFileFlag = flag.String("ignore", "", "Ignore files matching this regex")
ignoreFileFlag = flag.String("ignore", "", "Ignore files matching glob pattern")
)

func main() {
Expand Down

0 comments on commit 5bc430c

Please sign in to comment.