Skip to content

Commit

Permalink
Fix running single analyzer which isn't a rule bug (#1231)
Browse files Browse the repository at this point in the history
* Fix running single analyzer which isn't a rule bug

* remove uncessary diff (even if it's proper fmt)
  • Loading branch information
ldemailly committed Sep 20, 2024
1 parent a836898 commit 6741874
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
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

0 comments on commit 6741874

Please sign in to comment.