feat(skillignore): add IgnoreStats struct with Active/PatternCount/IgnoredCount

This commit is contained in:
Willie
2026-03-18 00:19:30 +08:00
parent 4214cb1038
commit 2e9547a8de
2 changed files with 67 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
package skillignore
// IgnoreStats holds information about .skillignore files and their effect.
type IgnoreStats struct {
RootFile string // root .skillignore path ("" = not exist)
RepoFiles []string // repo-level .skillignore paths
Patterns []string // all active patterns (no blanks/comments)
IgnoredSkills []string // excluded skill relPaths
}
// Active reports whether any .skillignore file is in effect.
func (s *IgnoreStats) Active() bool {
return s.RootFile != "" || len(s.RepoFiles) > 0
}
// PatternCount returns the total number of active patterns.
func (s *IgnoreStats) PatternCount() int {
return len(s.Patterns)
}
// IgnoredCount returns the number of ignored skills.
func (s *IgnoreStats) IgnoredCount() int {
return len(s.IgnoredSkills)
}
+43
View File
@@ -0,0 +1,43 @@
package skillignore
import "testing"
func TestIgnoreStats_Active(t *testing.T) {
tests := []struct {
name string
s IgnoreStats
want bool
}{
{"root file", IgnoreStats{RootFile: "/path/.skillignore"}, true},
{"repo file", IgnoreStats{RepoFiles: []string{"_repo/.skillignore"}}, true},
{"both", IgnoreStats{RootFile: "/path", RepoFiles: []string{"_r"}}, true},
{"neither", IgnoreStats{}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Active(); got != tt.want {
t.Errorf("Active() = %v, want %v", got, tt.want)
}
})
}
}
func TestIgnoreStats_Counts(t *testing.T) {
s := IgnoreStats{
Patterns: []string{"test-*", "vendor/", "!important"},
IgnoredSkills: []string{"test-a", "test-b"},
}
if s.PatternCount() != 3 {
t.Errorf("PatternCount() = %d, want 3", s.PatternCount())
}
if s.IgnoredCount() != 2 {
t.Errorf("IgnoredCount() = %d, want 2", s.IgnoredCount())
}
}
func TestIgnoreStats_ZeroCounts(t *testing.T) {
s := IgnoreStats{}
if s.PatternCount() != 0 || s.IgnoredCount() != 0 {
t.Error("empty stats should have zero counts")
}
}