use of org.sonarsource.sonarlint.core.rule.extractor.SonarLintRuleDefinition in project sonarlint-core by SonarSource.
the class StandaloneSonarLintEngineImpl method identifyActiveRules.
private Collection<ActiveRule> identifyActiveRules(StandaloneAnalysisConfiguration configuration) {
Set<String> excludedRules = configuration.excludedRules().stream().map(RuleKey::toString).collect(toSet());
Set<String> includedRules = configuration.includedRules().stream().map(RuleKey::toString).filter(r -> !excludedRules.contains(r)).collect(toSet());
Collection<SonarLintRuleDefinition> filteredActiveRules = new ArrayList<>();
filteredActiveRules.addAll(allRulesDefinitionsByKey.values().stream().filter(SonarLintRuleDefinition::isActiveByDefault).filter(isExcludedByConfiguration(excludedRules)).collect(Collectors.toList()));
filteredActiveRules.addAll(allRulesDefinitionsByKey.values().stream().filter(r -> !r.isActiveByDefault()).filter(isIncludedByConfiguration(includedRules)).collect(Collectors.toList()));
return filteredActiveRules.stream().map(rd -> {
var activeRule = new ActiveRule(rd.getKey(), rd.getLanguage().getLanguageKey());
Map<String, String> effectiveParams = new HashMap<>(rd.getDefaultParams());
Optional.ofNullable(configuration.ruleParameters().get(RuleKey.parse(rd.getKey()))).ifPresent(effectiveParams::putAll);
activeRule.setParams(effectiveParams);
return activeRule;
}).collect(Collectors.toList());
}
use of org.sonarsource.sonarlint.core.rule.extractor.SonarLintRuleDefinition in project sonarlint-core by SonarSource.
the class RuleExtractorMediumTests method onlyLoadRulesOfEnabledLanguages.
@Test
void onlyLoadRulesOfEnabledLanguages() throws Exception {
Set<Language> enabledLanguages = EnumSet.of(Language.JAVA, // Enable JS but not TS
Language.JS, Language.PHP, Language.PYTHON);
if (COMMERCIAL_ENABLED) {
// Enable C but not C++
enabledLanguages.add(Language.C);
}
var config = new PluginInstancesRepository.Configuration(allJars, enabledLanguages, empty());
try (var pluginInstancesRepository = new PluginInstancesRepository(config)) {
var allRules = new RulesDefinitionExtractor().extractRules(pluginInstancesRepository, enabledLanguages, false);
assertThat(allRules.stream().map(SonarLintRuleDefinition::getLanguage)).hasSameElementsAs(enabledLanguages);
}
}
Aggregations