aboutsummaryrefslogtreecommitdiff
path: root/internal/behavior/store.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/behavior/store.go')
-rw-r--r--internal/behavior/store.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/internal/behavior/store.go b/internal/behavior/store.go
index f2e9350..d31fe84 100644
--- a/internal/behavior/store.go
+++ b/internal/behavior/store.go
@@ -84,7 +84,11 @@ func WalkYAMLDir(dir string, fn func(path, id string, data []byte) error) error
}
return err
}
- if d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") {
+ if d.IsDir() {
+ return nil
+ }
+ id, ok := yamlID(d.Name())
+ if !ok {
return nil
}
if excludedContentPath(dir, path) {
@@ -97,11 +101,23 @@ func WalkYAMLDir(dir string, fn func(path, id string, data []byte) error) error
}
return readErr
}
- id := strings.TrimSuffix(d.Name(), ".yaml")
return fn(path, id, data)
})
}
+// yamlID returns the id (filename without extension) for a .yaml or .yml file.
+// The runtime trigger loader accepts .yml, so validation discovery must too,
+// otherwise such a file loads and fires while every check ignores it.
+func yamlID(name string) (string, bool) {
+ if strings.HasSuffix(name, ".yaml") {
+ return strings.TrimSuffix(name, ".yaml"), true
+ }
+ if strings.HasSuffix(name, ".yml") {
+ return strings.TrimSuffix(name, ".yml"), true
+ }
+ return "", false
+}
+
type Duplicate struct {
ID string
Paths []string
@@ -110,13 +126,16 @@ type Duplicate struct {
func CheckDuplicateIDs(dir string) []Duplicate {
seen := make(map[string][]string)
filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
- if err != nil || d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") {
+ if err != nil || d.IsDir() {
+ return nil
+ }
+ id, ok := yamlID(d.Name())
+ if !ok {
return nil
}
if excludedContentPath(dir, path) {
return nil
}
- id := strings.TrimSuffix(d.Name(), ".yaml")
seen[id] = append(seen[id], path)
return nil
})