Browse Source

Revert "SONAR-19050 Update xoo-plugin : use new rule characteristics in some issues"

This reverts commit 1ffc41b136.
tags/10.1.0.73491
Duarte Meneses 1 year ago
parent
commit
9b1d4caa24

+ 5
- 8
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java View File

import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.sonar.api.SonarRuntime; import org.sonar.api.SonarRuntime;
import org.sonar.api.rule.RuleScope; import org.sonar.api.rule.RuleScope;
import org.sonar.api.rules.RuleCharacteristic;
import org.sonar.api.rules.RuleType; import org.sonar.api.rules.RuleType;
import org.sonar.api.server.rule.RuleDescriptionSection; import org.sonar.api.server.rule.RuleDescriptionSection;
import org.sonar.api.server.rule.RuleParamType; import org.sonar.api.server.rule.RuleParamType;


NewRule oneBugIssuePerTestLine = repo.createRule(OneBugIssuePerTestLineSensor.RULE_KEY).setName("One Bug Issue Per Test Line") NewRule oneBugIssuePerTestLine = repo.createRule(OneBugIssuePerTestLineSensor.RULE_KEY).setName("One Bug Issue Per Test Line")
.setScope(RuleScope.TEST) .setScope(RuleScope.TEST)
.setType(RuleType.BUG).setCharacteristic(RuleCharacteristic.COMPLIANT);
.setType(RuleType.BUG);
addAllDescriptionSections(oneBugIssuePerTestLine, "Generate a bug issue on each line of a test file. It requires the metric \"lines\"."); addAllDescriptionSections(oneBugIssuePerTestLine, "Generate a bug issue on each line of a test file. It requires the metric \"lines\".");


oneBugIssuePerTestLine oneBugIssuePerTestLine


NewRule hotspotWithRangeAndMultipleLocations = repo.createRule(MultilineHotspotSensor.RULE_KEY) NewRule hotspotWithRangeAndMultipleLocations = repo.createRule(MultilineHotspotSensor.RULE_KEY)
.setName("Creates hotspots with ranges/multiple locations") .setName("Creates hotspots with ranges/multiple locations")
.setType(RuleType.SECURITY_HOTSPOT)
.setCharacteristic(RuleCharacteristic.PORTABLE);
.setType(RuleType.SECURITY_HOTSPOT);
addAllDescriptionSections(hotspotWithRangeAndMultipleLocations, "Hotspot with range and multiple locations"); addAllDescriptionSections(hotspotWithRangeAndMultipleLocations, "Hotspot with range and multiple locations");



NewRule issueOnEachFileWithExtUnknown = repo.createRule(OneIssuePerUnknownFileSensor.RULE_KEY).setName("Creates issues on each file with extension 'unknown'"); NewRule issueOnEachFileWithExtUnknown = repo.createRule(OneIssuePerUnknownFileSensor.RULE_KEY).setName("Creates issues on each file with extension 'unknown'");
addAllDescriptionSections(issueOnEachFileWithExtUnknown, "This issue is generated on each file with extenstion 'unknown'"); addAllDescriptionSections(issueOnEachFileWithExtUnknown, "This issue is generated on each file with extenstion 'unknown'");


addAllDescriptionSections(oneBugIssuePerLine, "Generate a bug issue on each line of a file. It requires the metric \"lines\"."); addAllDescriptionSections(oneBugIssuePerLine, "Generate a bug issue on each line of a file. It requires the metric \"lines\".");


NewRule oneCodeSmellIssuePerLine = repo.createRule(OneCodeSmellIssuePerLineSensor.RULE_KEY).setName("One Code Smell Issue Per Line") NewRule oneCodeSmellIssuePerLine = repo.createRule(OneCodeSmellIssuePerLineSensor.RULE_KEY).setName("One Code Smell Issue Per Line")
.setType(RuleType.CODE_SMELL)
.setCharacteristic(RuleCharacteristic.STRUCTURED);
.setType(RuleType.CODE_SMELL);
oneCodeSmellIssuePerLine oneCodeSmellIssuePerLine
.setDebtRemediationFunction(oneCodeSmellIssuePerLine.debtRemediationFunctions().linear("9min")); .setDebtRemediationFunction(oneCodeSmellIssuePerLine.debtRemediationFunctions().linear("9min"));
addAllDescriptionSections(oneCodeSmellIssuePerLine, "Generate a code smell issue on each line of a file. It requires the metric \"lines\"."); addAllDescriptionSections(oneCodeSmellIssuePerLine, "Generate a code smell issue on each line of a file. It requires the metric \"lines\".");


NewRule oneVulnerabilityIssuePerModule = repo.createRule(OneVulnerabilityIssuePerModuleSensor.RULE_KEY).setName("One Vulnerability Issue Per Module") NewRule oneVulnerabilityIssuePerModule = repo.createRule(OneVulnerabilityIssuePerModuleSensor.RULE_KEY).setName("One Vulnerability Issue Per Module")
.setType(RuleType.VULNERABILITY).setCharacteristic(RuleCharacteristic.ROBUST);
.setType(RuleType.VULNERABILITY);
addAllDescriptionSections(oneVulnerabilityIssuePerModule, "Generate an issue on each module"); addAllDescriptionSections(oneVulnerabilityIssuePerModule, "Generate an issue on each module");


oneVulnerabilityIssuePerModule oneVulnerabilityIssuePerModule
NewRule hotspotWithSingleContext = repo.createRule(HotspotWithSingleContextSensor.RULE_KEY) NewRule hotspotWithSingleContext = repo.createRule(HotspotWithSingleContextSensor.RULE_KEY)
.setName("Find security hotspots, how_to_fix with single context") .setName("Find security hotspots, how_to_fix with single context")
.setType(RuleType.SECURITY_HOTSPOT) .setType(RuleType.SECURITY_HOTSPOT)
.setCharacteristic(RuleCharacteristic.SECURE)
.setActivatedByDefault(false) .setActivatedByDefault(false)
.addDescriptionSection(howToFixSectionWithContext("single_context")); .addDescriptionSection(howToFixSectionWithContext("single_context"));
addDescriptionSectionsWithoutContexts(hotspotWithSingleContext, "Search for Security Hotspots with single context in Xoo files"); addDescriptionSectionsWithoutContexts(hotspotWithSingleContext, "Search for Security Hotspots with single context in Xoo files");

+ 0
- 9
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java View File

import org.sonar.api.SonarQubeSide; import org.sonar.api.SonarQubeSide;
import org.sonar.api.impl.server.RulesDefinitionContext; import org.sonar.api.impl.server.RulesDefinitionContext;
import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.rules.RuleCharacteristic;
import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.Version; import org.sonar.api.utils.Version;
assertThat(rule.debtRemediationFunction().gapMultiplier()).isEqualTo("1min"); assertThat(rule.debtRemediationFunction().gapMultiplier()).isEqualTo("1min");
assertThat(rule.debtRemediationFunction().baseEffort()).isNull(); assertThat(rule.debtRemediationFunction().baseEffort()).isNull();
assertThat(rule.gapDescription()).isNotEmpty(); assertThat(rule.gapDescription()).isNotEmpty();
assertThat(rule.characteristic()).isNull();
assertThat(rule.ruleDescriptionSections()).isNotEmpty(); assertThat(rule.ruleDescriptionSections()).isNotEmpty();
assertThat(rule.ruleDescriptionSections().stream().anyMatch(rds -> rds.getContext().isPresent())).isTrue(); assertThat(rule.ruleDescriptionSections().stream().anyMatch(rds -> rds.getContext().isPresent())).isTrue();
} }
assertThat(repo.rules()).hasSize(2); assertThat(repo.rules()).hasSize(2);
} }


@Test
public void define_xoo_rule_with_characteristic() {
RulesDefinition.Repository repo = context.repository("xoo");
RulesDefinition.Rule oneCodeSmellIssuePerLine = repo.rule("OneCodeSmellIssuePerLine");
assertThat(oneCodeSmellIssuePerLine.characteristic()).isEqualTo(RuleCharacteristic.STRUCTURED);
}

private RulesDefinition.Repository getRepository() { private RulesDefinition.Repository getRepository() {
RulesDefinition.Repository repo = context.repository("xoo"); RulesDefinition.Repository repo = context.repository("xoo");
assertThat(repo).isNotNull(); assertThat(repo).isNotNull();

Loading…
Cancel
Save