Skip to content

Commit

Permalink
fix: glob patterns for includes and excludes
Browse files Browse the repository at this point in the history
Prefix with **/
  • Loading branch information
brianmcgee committed Dec 23, 2023
1 parent 12452b0 commit 12aa9a7
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions internal/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package format
import (
"context"
"os/exec"
"strings"
"time"

"github.com/charmbracelet/log"
Expand Down Expand Up @@ -44,10 +43,7 @@ func (f *Formatter) Init(name string) error {
// todo refactor common code below
if len(f.Includes) > 0 {
for _, pattern := range f.Includes {
if !strings.Contains(pattern, "/") {
pattern = "**/" + pattern
}
g, err := glob.Compile(pattern)
g, err := glob.Compile("**/" + pattern)
if err != nil {
return errors.Annotatef(err, "failed to compile include pattern '%v' for formatter '%v'", pattern, f.Name)
}
Expand All @@ -57,10 +53,7 @@ func (f *Formatter) Init(name string) error {

if len(f.Excludes) > 0 {
for _, pattern := range f.Excludes {
if !strings.Contains(pattern, "/") {
pattern = "**/" + pattern
}
g, err := glob.Compile(pattern)
g, err := glob.Compile("**/" + pattern)
if err != nil {
return errors.Annotatef(err, "failed to compile exclude pattern '%v' for formatter '%v'", pattern, f.Name)
}
Expand All @@ -72,10 +65,11 @@ func (f *Formatter) Init(name string) error {
}

func (f *Formatter) Wants(path string) bool {
if PathMatches(path, f.excludes) {
return false
match := !PathMatches(path, f.excludes) && PathMatches(path, f.includes)
if match {
f.log.Debugf("match: %v", path)
}
return PathMatches(path, f.includes)
return match
}

func (f *Formatter) Put(path string) {
Expand Down

0 comments on commit 12aa9a7

Please sign in to comment.