diff options
author | Lukasz Jarocki <lukasz.jarocki@sonarsource.com> | 2022-07-06 14:07:44 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-07-08 20:02:48 +0000 |
commit | 685a8905315ce2fb830c91684ea3c9a3b3ad06a8 (patch) | |
tree | 34a23c8347d78fa43422803b44403191ef709378 /plugins/sonar-xoo-plugin/src | |
parent | 39f4503d689f20e83edfbd48d24d1d37acc46c20 (diff) | |
download | sonarqube-685a8905315ce2fb830c91684ea3c9a3b3ad06a8.tar.gz sonarqube-685a8905315ce2fb830c91684ea3c9a3b3ad06a8.zip |
SONAR-16614 added detected context to one of the sensors
Diffstat (limited to 'plugins/sonar-xoo-plugin/src')
3 files changed, 8 insertions, 8 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java index 720110853f1..74c713014a4 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java @@ -29,10 +29,11 @@ import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.Version; import org.sonar.xoo.Xoo; import org.sonar.xoo.Xoo2; +import static org.sonar.xoo.rule.XooRulesDefinition.AVAILABLE_CONTEXTS; + public class OneIssuePerLineSensor implements Sensor { public static final String RULE_KEY = "OneIssuePerLine"; @@ -73,12 +74,9 @@ public class OneIssuePerLineSensor implements Sensor { .on(file) .at(file.selectLine(line)) .message("This issue is generated on each line")) - .overrideSeverity(severity != null ? Severity.valueOf(severity) : null); - if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) { - newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); - } else { - newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); - } + .overrideSeverity(severity != null ? Severity.valueOf(severity) : null) + .setRuleDescriptionContextKey(AVAILABLE_CONTEXTS[0]) + .gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); newIssue.save(); } } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java index 38ed2bad0bf..6656e760034 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java @@ -48,11 +48,12 @@ import static org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version.Y2021; */ public class XooRulesDefinition implements RulesDefinition { + public static final String[] AVAILABLE_CONTEXTS = { "JavaScript", "JQuery", "Express.js", "React", "Axios" }; + public static final String XOO_REPOSITORY = "xoo"; public static final String XOO2_REPOSITORY = "xoo2"; private static final String TEN_MIN = "10min"; - private static final String[] AVAILABLE_CONTEXTS = { "JavaScript", "JQuery", "Express.js", "React", "Axios" }; @Nullable private final Version version; diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java index c64ed9b68dc..3ed3cf22683 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java @@ -85,6 +85,7 @@ public class OneIssuePerLineSensorTest { assertThat(context.allIssues()).hasSize(10); // One issue per line for (Issue issue : context.allIssues()) { assertThat(issue.overriddenSeverity()).isEqualTo(Severity.MINOR); + assertThat(issue.ruleDescriptionContextKey()).contains(XooRulesDefinition.AVAILABLE_CONTEXTS[0]); } } |