diff --git a/new/detector/composition/javascript/javascript.go b/new/detector/composition/javascript/javascript.go index 896016fe5..fbcadc835 100644 --- a/new/detector/composition/javascript/javascript.go +++ b/new/detector/composition/javascript/javascript.go @@ -105,11 +105,21 @@ func New(rules map[string]*settings.Rule, classifier *classification.Classifier) detectors = append(detectors, detector) composition.closers = append(composition.closers, detector.Close) + presenceRules := map[string]bool{} + for _, rule := range jsRules { + if rule.TriggerRuleOnPresenceOf != "" { + presenceRules[rule.TriggerRuleOnPresenceOf] = true + } + } + for ruleName, rule := range jsRules { patterns := rule.Patterns localRuleName := ruleName - composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName) + if !rule.IsAuxilary || presenceRules[ruleName] { + composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName) + } + go func() { customDetector, err := custom.New( lang, diff --git a/new/detector/composition/ruby/ruby.go b/new/detector/composition/ruby/ruby.go index ea27d0fe8..502fbcebd 100644 --- a/new/detector/composition/ruby/ruby.go +++ b/new/detector/composition/ruby/ruby.go @@ -103,11 +103,20 @@ func New(rules map[string]*settings.Rule, classifier *classification.Classifier) detectors = append(detectors, detector) composition.closers = append(composition.closers, detector.Close) + presenceRules := map[string]bool{} + for _, rule := range rubyRules { + if rule.TriggerRuleOnPresenceOf != "" { + presenceRules[rule.TriggerRuleOnPresenceOf] = true + } + } + for ruleName, rule := range rubyRules { patterns := rule.Patterns localRuleName := ruleName - composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName) + if !rule.IsAuxilary || presenceRules[ruleName] { + composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName) + } go func() { customDetector, err := custom.New( diff --git a/pkg/commands/process/settings/rules.go b/pkg/commands/process/settings/rules.go index 19c56997e..8773635b5 100644 --- a/pkg/commands/process/settings/rules.go +++ b/pkg/commands/process/settings/rules.go @@ -207,6 +207,7 @@ func buildRules(definitions map[string]RuleDefinition, enabledRules map[string]s ParamParenting: auxiliaryDefinition.ParamParenting, Patterns: auxiliaryDefinition.Patterns, Stored: auxiliaryDefinition.Stored, + IsAuxilary: true, } } } diff --git a/pkg/commands/process/settings/settings.go b/pkg/commands/process/settings/settings.go index 7cbba0147..a187bdf8c 100644 --- a/pkg/commands/process/settings/settings.go +++ b/pkg/commands/process/settings/settings.go @@ -132,6 +132,7 @@ type Rule struct { Patterns []RulePattern `mapstructure:"patterns" json:"patterns" yaml:"patterns"` DocumentationUrl string `mapstructure:"documentation_url" json:"documentation_url" yaml:"documentation_url"` TriggerRuleOnPresenceOf string `mapstructure:"trigger_rule_on_presence_of" json:"trigger_rule_on_presence_of" yaml:"trigger_rule_on_presence_of"` + IsAuxilary bool `mapstructure:"is_auxilary" json:"is_auxilary" yaml:"is_auxilary"` // FIXME: remove after refactor of sql Metavars map[string]MetaVar `mapstructure:"metavars" json:"metavars" yaml:"metavars"`