Skip to content

Commit

Permalink
🐛 fix rule parsing when sub-trees are invalid, this is common now tha…
Browse files Browse the repository at this point in the history
…t we have tests folder

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed May 21, 2024
1 parent 8bc31b2 commit b7d7212
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions parser/rule_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (r *RuleParser) LoadRules(filepath string) ([]engine.RuleSet, map[string]pr
}
var ruleSet *engine.RuleSet
rules := []engine.Rule{}
foundTree := false
parserErr := &parserErrors{}
for _, f := range files {
info, err := os.Stat(path.Join(filepath, f.Name()))
Expand All @@ -122,7 +121,6 @@ func (r *RuleParser) LoadRules(filepath string) ([]engine.RuleSet, map[string]pr
continue
}
if info.IsDir() {
foundTree = true
r, m, err := r.LoadRules(path.Join(filepath, f.Name()))
if err != nil {
parserErr.errs = append(parserErr.errs, err)
Expand All @@ -141,6 +139,12 @@ func (r *RuleParser) LoadRules(filepath string) ([]engine.RuleSet, map[string]pr
ruleSet = r.loadRuleSet(filepath)
continue
}
// skip rule tests
if strings.HasSuffix(f.Name(), ".test.yaml") ||
strings.HasSuffix(f.Name(), ".test.yml") {
r.Log.V(7).Info("excluding test file from parsing", "file", f.Name())
continue
}
r, m, err := r.LoadRule(path.Join(filepath, f.Name()))
if err != nil {
parserErr.errs = append(parserErr.errs, err)
Expand All @@ -154,9 +158,6 @@ func (r *RuleParser) LoadRules(filepath string) ([]engine.RuleSet, map[string]pr
}
}

if ruleSet == nil && !foundTree {
return nil, nil, fmt.Errorf("unable to find %v", RULE_SET_GOLDEN_FILE_NAME)
}
if ruleSet != nil {
ruleSet.Rules = rules
ruleSets = append(ruleSets, *ruleSet)
Expand Down
2 changes: 1 addition & 1 deletion provider/internal/builtin/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,6 @@ func (b *builtinServiceClient) isFileIncluded(absolutePath string) bool {
return true
}
}
b.log.V(5).Info("excluding file from search", "file", absolutePath)
b.log.V(7).Info("excluding file from search", "file", absolutePath)
return false
}

0 comments on commit b7d7212

Please sign in to comment.