Skip to content

Commit

Permalink
feat: add regex support to ignore files based on pattern in fixer tool
Browse files Browse the repository at this point in the history
refactor: align flag variable declarations in main.go for consistency
  • Loading branch information
yyoshiki41 committed May 5, 2024
1 parent 0c0a4c8 commit dfb1e95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go/parser"
"go/token"
"os"
"regexp"
"strings"
)

Expand All @@ -17,6 +18,14 @@ var (
)

func fix(filename, functionName string) error {
if i := *ignoreFileFlag; i != "" {
if ok, err := regexp.MatchString(i, filename); err != nil {
return err
} else if ok {
return nil
}
}

start, end, err := lookup(filename, functionName)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (

// flags
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")
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")
)

func main() {
Expand Down

0 comments on commit dfb1e95

Please sign in to comment.