fix: duplicate processing in ordered formatters (#24)

Fixes a bug with formatters processing paths out of order.

Signed-off-by: Brian McGee <brian@bmcgee.ie>

Reviewed-on: #24
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
Brian McGee 2024-01-12 15:15:51 +00:00 committed by Brian McGee
parent c7d0138a02
commit 15db7f459c
4 changed files with 8 additions and 6 deletions

View File

@ -57,7 +57,7 @@ func TestDependencyCycle(t *testing.T) {
})
_, err := cmd(t, "--config-file", configPath, "--tree-root", tempDir)
as.ErrorContains(err, "formatter cycle detected a -> b -> c")
as.ErrorContains(err, "formatter cycle detected")
}
func TestSpecifyingFormatters(t *testing.T) {

View File

@ -122,6 +122,10 @@ func (f *Formatter) SetChild(formatter *Formatter) {
// Wants is used to test if a Formatter wants path based on it's configured Includes and Excludes patterns.
// Returns true if the Formatter should be applied to path, false otherwise.
func (f *Formatter) Wants(path string) bool {
if f.parent != nil {
// we don't accept this path directly, our parent will forward it
return false
}
match := !PathMatches(path, f.excludes) && PathMatches(path, f.includes)
if match {
f.log.Debugf("match: %v", path)

View File

@ -3,9 +3,10 @@ package walk
import (
"context"
"fmt"
"github.com/go-git/go-git/v5"
"os"
"path/filepath"
"github.com/go-git/go-git/v5"
)
type gitWalker struct {
@ -18,14 +19,12 @@ func (g *gitWalker) Root() string {
}
func (g *gitWalker) Walk(ctx context.Context, fn filepath.WalkFunc) error {
idx, err := g.repo.Storer.Index()
if err != nil {
return fmt.Errorf("%w: failed to open index", err)
}
for _, entry := range idx.Entries {
select {
case <-ctx.Done():
return ctx.Err()
@ -38,7 +37,6 @@ func (g *gitWalker) Walk(ctx context.Context, fn filepath.WalkFunc) error {
return err
}
}
}
return nil

View File

@ -28,7 +28,7 @@
nativeBuildInputs =
# we need some formatters available for the tests
(import ./formatters.nix pkgs);
import ./formatters.nix pkgs;
preCheck = ''
XDG_CACHE_HOME=$(mktemp -d)