Skip to content

Commit

Permalink
🐛 fail early w/o --rules on non-Java apps
Browse files Browse the repository at this point in the history
Signed-off-by: David Zager <[email protected]>
  • Loading branch information
djzager committed Aug 6, 2024
1 parent 56b3b68 commit a67ed56
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
if len(foundProviders) == 1 && foundProviders[0] == dotnetFrameworkProvider {
return analyzeCmd.analyzeDotnetFramework(cmd.Context())
}

// default rulesets are only java rules
// may want to change this in the future
if len(foundProviders) > 0 && len(analyzeCmd.rules) == 0 {
if _, ok := analyzeCmd.providersMap[javaProvider]; !ok {
return fmt.Errorf("No providers found with default rules. Use --rules option")
}
}

xmlOutputDir, err := analyzeCmd.ConvertXML(cmd.Context())
if err != nil {
log.Error(err, "failed to convert xml rules")
Expand Down Expand Up @@ -1269,7 +1278,6 @@ func (a *analyzeCommand) RunAnalysisOverrideProviderSettings(ctx context.Context
fmt.Sprintf("--context-lines=%d", a.contextLines),
}

a.enableDefaultRulesets = false
if a.enableDefaultRulesets {
args = append(args,
fmt.Sprintf("--rules=%s/", RulesetPath))
Expand Down Expand Up @@ -1382,13 +1390,6 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string, v
fmt.Sprintf("--output-file=%s", AnalysisOutputMountPath),
fmt.Sprintf("--context-lines=%d", a.contextLines),
}
// default rulesets are only java rules
// may want to change this in the future
if !a.needsBuiltin {
if _, ok := a.providersMap[javaProvider]; !ok {
a.enableDefaultRulesets = false
}
}
if a.enableDefaultRulesets {
args = append(args,
fmt.Sprintf("--rules=%s/", RulesetPath))
Expand Down

0 comments on commit a67ed56

Please sign in to comment.