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)
This commit is contained in:
Laurent Demailly 2024-09-20 01:56:50 -07:00 committed by GitHub
parent a83689867d
commit 6741874d9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 6 deletions

View file

@ -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 {

View file

@ -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())
}
@ -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())