Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running single analyzer which isn't a rule bug #1231

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analyzers/analyzerslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (al *AnalyzerList) AnalyzersInfo() (map[string]AnalyzerDefinition, map[stri
type AnalyzerFilter func(string) bool

// NewAnalyzerFilter is a closure that will include/exclude the analyzer ID's based on
// the supplied boolean value.
// the supplied boolean value (false means don't remove, true means exclude).
func NewAnalyzerFilter(action bool, analyzerIDs ...string) AnalyzerFilter {
analyzerlist := make(map[string]bool)
for _, analyzer := range analyzerIDs {
Expand Down
11 changes: 6 additions & 5 deletions cmd/gosec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ func loadConfig(configFile string) (gosec.Config, error) {
if *flagEnableAudit {
config.SetGlobal(gosec.Audit, "true")
}
// set global option IncludeRules ,when flag set or global option IncludeRules is nil
// set global option IncludeRules, when flag set or global option IncludeRules is nil
if v, _ := config.GetGlobal(gosec.IncludeRules); *flagRulesInclude != "" || v == "" {
config.SetGlobal(gosec.IncludeRules, *flagRulesInclude)
}
// set global option ExcludeRules ,when flag set or global option IncludeRules is nil
// set global option ExcludeRules, when flag set or global option ExcludeRules is nil
if v, _ := config.GetGlobal(gosec.ExcludeRules); flagRulesExclude.String() != "" || v == "" {
config.SetGlobal(gosec.ExcludeRules, flagRulesExclude.String())
}
Expand Down Expand Up @@ -438,12 +438,13 @@ func main() {
}

ruleList := loadRules(includeRules, excludeRules)
if len(ruleList.Rules) == 0 {
logger.Fatal("No rules are configured")
}

analyzerList := loadAnalyzers(includeRules, excludeRules)

if len(ruleList.Rules) == 0 && len(analyzerList.Analyzers) == 0 {
logger.Fatal("No rules/analyzers are configured")
}

// Create the analyzer
analyzer := gosec.NewAnalyzer(config, *flagScanTests, *flagExcludeGenerated, *flagTrackSuppressions, *flagConcurrency, logger)
analyzer.LoadRules(ruleList.RulesInfo())
Expand Down
Loading