Skip to content

Commit

Permalink
feat(rules): improve rule dx
Browse files Browse the repository at this point in the history
  • Loading branch information
gotbadger committed Feb 27, 2024
1 parent 1f04488 commit 0efa92c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/commands/artifact/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ func (r *runner) Report(
}
}

if len(r.scanSettings.Rules) == 0 {
return false, fmt.Errorf("no rules found for supported language, default rules could not be downloaded or possibly disabled without using --external-rule-dir")
}

return reportData.ReportFailed, nil
}

Expand Down
9 changes: 6 additions & 3 deletions internal/commands/process/settings/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,21 @@ func validateRuleOptionIDs(
invalidRuleIDs = append(invalidRuleIDs, id)
}
}

var invalidSkipRuleIDs []string
for id := range options.SkipRule {
_, existsInDefinition := definitions[id]
_, existsInBuiltInDefinition := builtInDefinitions[id]

if !existsInBuiltInDefinition && !existsInDefinition {
invalidRuleIDs = append(invalidRuleIDs, id)
invalidSkipRuleIDs = append(invalidSkipRuleIDs, id)
}
}

if len(invalidSkipRuleIDs) > 0 {
output.StdErrLog(fmt.Sprintf("Warning: rule IDs %s given to be skipped but were not found", strings.Join(invalidSkipRuleIDs, ",")))
}
if len(invalidRuleIDs) > 0 {
return fmt.Errorf("invalid rule IDs in only/skip option: %s", strings.Join(invalidRuleIDs, ","))
return fmt.Errorf("invalid rule IDs in only option: %s", strings.Join(invalidRuleIDs, ","))
}

return nil
Expand Down

0 comments on commit 0efa92c

Please sign in to comment.