Skip to content

Commit 6b639fe

Browse files
committed
ensure severity and ID are set
resolved #623
1 parent e7edd8a commit 6b639fe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

motor/rule_applicator.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,20 @@ func buildResults(ctx ruleContext, ruleAction model.RuleAction, nodes []*yaml.No
10171017

10181018
runRuleResults := ruleFunction.RunRule([]*yaml.Node{node}, rfc)
10191019

1020+
// Ensure RuleId and RuleSeverity are populated from the rule context
1021+
// This is necessary for programmatic API usage where these fields might not be set
1022+
for i := range runRuleResults {
1023+
if runRuleResults[i].RuleId == "" {
1024+
runRuleResults[i].RuleId = ctx.rule.Id
1025+
}
1026+
if runRuleResults[i].RuleSeverity == "" {
1027+
runRuleResults[i].RuleSeverity = ctx.rule.Severity
1028+
}
1029+
if runRuleResults[i].Rule == nil {
1030+
runRuleResults[i].Rule = ctx.rule
1031+
}
1032+
}
1033+
10201034
// because this function is running in multiple threads, we need to sync access to the final result
10211035
// list, otherwise things can get a bit random.
10221036
lock.Lock()

0 commit comments

Comments
 (0)