Skip to content

Commit 6741874

Browse files
authored
Fix running single analyzer which isn't a rule bug (#1231)
* Fix running single analyzer which isn't a rule bug * remove uncessary diff (even if it's proper fmt)
1 parent a836898 commit 6741874

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

analyzers/analyzerslist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (al *AnalyzerList) AnalyzersInfo() (map[string]AnalyzerDefinition, map[stri
5151
type AnalyzerFilter func(string) bool
5252

5353
// NewAnalyzerFilter is a closure that will include/exclude the analyzer ID's based on
54-
// the supplied boolean value.
54+
// the supplied boolean value (false means don't remove, true means exclude).
5555
func NewAnalyzerFilter(action bool, analyzerIDs ...string) AnalyzerFilter {
5656
analyzerlist := make(map[string]bool)
5757
for _, analyzer := range analyzerIDs {

cmd/gosec/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ func loadConfig(configFile string) (gosec.Config, error) {
224224
if *flagEnableAudit {
225225
config.SetGlobal(gosec.Audit, "true")
226226
}
227-
// set global option IncludeRules ,when flag set or global option IncludeRules is nil
227+
// set global option IncludeRules, when flag set or global option IncludeRules is nil
228228
if v, _ := config.GetGlobal(gosec.IncludeRules); *flagRulesInclude != "" || v == "" {
229229
config.SetGlobal(gosec.IncludeRules, *flagRulesInclude)
230230
}
231-
// set global option ExcludeRules ,when flag set or global option IncludeRules is nil
231+
// set global option ExcludeRules, when flag set or global option ExcludeRules is nil
232232
if v, _ := config.GetGlobal(gosec.ExcludeRules); flagRulesExclude.String() != "" || v == "" {
233233
config.SetGlobal(gosec.ExcludeRules, flagRulesExclude.String())
234234
}
@@ -438,12 +438,13 @@ func main() {
438438
}
439439

440440
ruleList := loadRules(includeRules, excludeRules)
441-
if len(ruleList.Rules) == 0 {
442-
logger.Fatal("No rules are configured")
443-
}
444441

445442
analyzerList := loadAnalyzers(includeRules, excludeRules)
446443

444+
if len(ruleList.Rules) == 0 && len(analyzerList.Analyzers) == 0 {
445+
logger.Fatal("No rules/analyzers are configured")
446+
}
447+
447448
// Create the analyzer
448449
analyzer := gosec.NewAnalyzer(config, *flagScanTests, *flagExcludeGenerated, *flagTrackSuppressions, *flagConcurrency, logger)
449450
analyzer.LoadRules(ruleList.RulesInfo())

0 commit comments

Comments
 (0)