Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/cli/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/glincker/stacklit/internal/config"
"github.com/glincker/stacklit/internal/git"
"github.com/glincker/stacklit/internal/schema"
"github.com/glincker/stacklit/internal/walker"
Expand Down Expand Up @@ -32,8 +33,9 @@ func newDiffCmd() *cobra.Command {
return fmt.Errorf("stacklit.json has no merkle_hash; run 'stacklit generate' to rebuild")
}

// 2. Walk current source files
files, err := walker.Walk(".", nil)
// 2. Walk current source files, excluding Stacklit's own generated outputs.
cfg := config.Load(".")
files, err := walker.Walk(".", cfg.ScanIgnore())
if err != nil {
return fmt.Errorf("failed to walk source files: %w", err)
}
Expand Down
13 changes: 13 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ func Load(root string) *Config {

return cfg
}

// ScanIgnore returns ignore patterns plus Stacklit output files so generated artifacts
// never feed back into the next scan.
func (c *Config) ScanIgnore() []string {
ignore := append([]string{}, c.Ignore...)
for _, out := range []string{c.Output.JSON, c.Output.Mermaid, c.Output.HTML} {
if out == "" {
continue
}
ignore = append(ignore, filepath.ToSlash(out))
}
return ignore
}
19 changes: 19 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,22 @@ func TestLoadMalformed(t *testing.T) {
t.Errorf("expected default max_depth=4 after malformed file, got %d", cfg.MaxDepth)
}
}

func TestScanIgnoreIncludesOutputs(t *testing.T) {
cfg := DefaultConfig()
cfg.Ignore = []string{"custom/"}
cfg.Output.JSON = "out\\stacklit.json"
cfg.Output.Mermaid = "docs\\DEPENDENCIES.md"
cfg.Output.HTML = "stacklit.html"

got := cfg.ScanIgnore()
want := []string{"custom/", "out/stacklit.json", "docs/DEPENDENCIES.md", "stacklit.html"}
if len(got) != len(want) {
t.Fatalf("expected %d ignore patterns, got %d: %v", len(want), len(got), got)
}
for i := range want {
if got[i] != want[i] {
t.Fatalf("expected ignore[%d]=%q, got %q (all=%v)", i, want[i], got[i], got)
}
}
}
2 changes: 1 addition & 1 deletion internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Run(opts Options) (*Result, error) {
}

// 3. Walk the filesystem, honouring extra ignore patterns from config.
files, err := walker.Walk(root, cfg.Ignore)
files, err := walker.Walk(root, cfg.ScanIgnore())
if err != nil {
return nil, fmt.Errorf("walking %s: %w", root, err)
}
Expand Down
3 changes: 3 additions & 0 deletions internal/walker/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func Walk(root string, extraIgnore []string) ([]string, error) {
return relErr
}

// Normalize path separators so generated output and ignore matching stay stable across OSes.
rel = filepath.ToSlash(rel)

Comment on lines +102 to +104
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that walker normalizes walked paths with filepath.ToSlash(rel), extraIgnore patterns containing OS-native separators (e.g., "dir\file.go" coming from Windows configs or filepath.Join) will no longer match and will silently stop ignoring files. Consider normalizing extraIgnore entries to forward slashes (and/or documenting that patterns must use '/'), so ignore behavior remains consistent across OSes after this change.

Copilot uses AI. Check for mistakes.
// Skip the root itself.
if rel == "." {
return nil
Expand Down
10 changes: 5 additions & 5 deletions internal/walker/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestWalkSourceFiles(t *testing.T) {
// Must include Go source files.
wantIncluded := []string{
"main.go",
filepath.Join("internal", "handler.go"),
filepath.Join("internal", "handler_test.go"),
filepath.ToSlash(filepath.Join("internal", "handler.go")),
filepath.ToSlash(filepath.Join("internal", "handler_test.go")),
}
for _, want := range wantIncluded {
if !fileSet[want] {
Expand All @@ -46,8 +46,8 @@ func TestWalkSourceFiles(t *testing.T) {

// Must exclude gitignored directories.
wantExcluded := []string{
filepath.Join("vendor", "lib.go"),
filepath.Join("node_modules", "pkg.js"),
filepath.ToSlash(filepath.Join("vendor", "lib.go")),
filepath.ToSlash(filepath.Join("node_modules", "pkg.js")),
}
for _, exclude := range wantExcluded {
if fileSet[exclude] {
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestWalkAlwaysIgnoresDirs(t *testing.T) {
}

for _, d := range ignoredDirs {
p := filepath.Join(d, "file.go")
p := filepath.ToSlash(filepath.Join(d, "file.go"))
if fileSet[p] {
t.Errorf("expected %q inside always-ignore dir to be excluded", p)
}
Expand Down
Loading