use of org.sonarsource.sonarlint.core.rule.extractor.RulesDefinitionExtractor in project sonarlint-core by SonarSource.
the class RuleExtractorMediumTests method extractAllRules.
@Test
void extractAllRules() throws Exception {
Set<Language> enabledLanguages = Set.of(Language.values());
var config = new PluginInstancesRepository.Configuration(allJars, enabledLanguages, empty());
try (var pluginInstancesRepository = new PluginInstancesRepository(config)) {
var allRules = new RulesDefinitionExtractor().extractRules(pluginInstancesRepository, enabledLanguages, false);
if (COMMERCIAL_ENABLED) {
assertThat(allJars).hasSize(19);
assertThat(allRules).hasSize(ALL_RULES_COUNT_WITH_COMMERCIAL);
assertThat(logTester.logs(ClientLogOutput.Level.WARN)).containsExactlyInAnyOrder("Plugin 'rpg' embeds dependencies. This will be deprecated soon. Plugin should be updated.", "Plugin 'cobol' embeds dependencies. This will be deprecated soon. Plugin should be updated.", "Plugin 'swift' embeds dependencies. This will be deprecated soon. Plugin should be updated.");
} else {
assertThat(allJars).hasSize(10);
assertThat(allRules).hasSize(ALL_RULES_COUNT_WITHOUT_COMMERCIAL);
}
var pythonRule = allRules.stream().filter(r -> r.getKey().equals("python:S139")).findFirst();
assertThat(pythonRule).hasValueSatisfying(rule -> {
assertThat(rule.getKey()).isEqualTo("python:S139");
assertThat(rule.getType()).isEqualTo("CODE_SMELL");
assertThat(rule.getSeverity()).isEqualTo("MINOR");
assertThat(rule.getLanguage()).isEqualTo(Language.PYTHON);
assertThat(rule.getName()).isEqualTo("Comments should not be located at the end of lines of code");
assertThat(rule.isActiveByDefault()).isFalse();
assertThat(rule.getParams()).hasSize(1).hasEntrySatisfying("legalTrailingCommentPattern", param -> {
assertThat(param.defaultValue()).isEqualTo("^#\\s*+[^\\s]++$");
assertThat(param.description()).isNull();
assertThat(param.key()).isEqualTo("legalTrailingCommentPattern");
assertThat(param.multiple()).isFalse();
assertThat(param.name()).isEqualTo("legalTrailingCommentPattern");
assertThat(param.possibleValues()).isEmpty();
assertThat(param.type()).isEqualTo(SonarLintRuleParamType.STRING);
});
assertThat(rule.getDefaultParams()).containsOnly(entry("legalTrailingCommentPattern", "^#\\s*+[^\\s]++$"));
assertThat(rule.getDeprecatedKeys()).isEmpty();
assertThat(rule.getHtmlDescription()).contains("<p>This rule verifies that single-line comments are not located");
assertThat(rule.getTags()).containsOnly("convention");
});
}
}
use of org.sonarsource.sonarlint.core.rule.extractor.RulesDefinitionExtractor in project sonarlint-core by SonarSource.
the class RuleExtractorMediumTests method loadNoRuleIfThereIsNoPlugin.
@Test
void loadNoRuleIfThereIsNoPlugin() throws Exception {
Set<Language> enabledLanguages = Set.of(Language.values());
var config = new PluginInstancesRepository.Configuration(Set.of(), enabledLanguages, empty());
try (var pluginInstancesRepository = new PluginInstancesRepository(config)) {
var allRules = new RulesDefinitionExtractor().extractRules(pluginInstancesRepository, enabledLanguages, false);
assertThat(allRules).isEmpty();
}
}
use of org.sonarsource.sonarlint.core.rule.extractor.RulesDefinitionExtractor in project sonarlint-core by SonarSource.
the class RuleExtractorMediumTests method extractAllRules_include_rule_templates.
@Test
void extractAllRules_include_rule_templates() throws Exception {
Set<Language> enabledLanguages = Set.of(Language.values());
var config = new PluginInstancesRepository.Configuration(allJars, enabledLanguages, empty());
try (var pluginInstancesRepository = new PluginInstancesRepository(config)) {
var allRules = new RulesDefinitionExtractor().extractRules(pluginInstancesRepository, enabledLanguages, true);
if (COMMERCIAL_ENABLED) {
assertThat(allJars).hasSize(19);
assertThat(allRules).hasSize(ALL_RULES_COUNT_WITH_COMMERCIAL + NON_COMMERCIAL_RULE_TEMPLATES_COUNT + COMMERCIAL_RULE_TEMPLATES_COUNT);
assertThat(logTester.logs(ClientLogOutput.Level.WARN)).containsExactlyInAnyOrder("Plugin 'rpg' embeds dependencies. This will be deprecated soon. Plugin should be updated.", "Plugin 'cobol' embeds dependencies. This will be deprecated soon. Plugin should be updated.", "Plugin 'swift' embeds dependencies. This will be deprecated soon. Plugin should be updated.");
} else {
assertThat(allJars).hasSize(10);
assertThat(allRules).hasSize(ALL_RULES_COUNT_WITHOUT_COMMERCIAL + NON_COMMERCIAL_RULE_TEMPLATES_COUNT);
}
}
}
use of org.sonarsource.sonarlint.core.rule.extractor.RulesDefinitionExtractor 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