]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16614 added detected context to one of the sensors
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Wed, 6 Jul 2022 12:07:44 +0000 (14:07 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 8 Jul 2022 20:02:48 +0000 (20:02 +0000)
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java

index 720110853f132a83d8716ba3b6fc56505aa1a90a..74c713014a4b5e54fa5084b0432183cdee3ddb96 100644 (file)
@@ -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();
     }
   }
index 38ed2bad0bfad79d855635ae5569ade6db3d7d58..6656e76003404b2c224c38aacff9707ab358121e 100644 (file)
@@ -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;
index c64ed9b68dc8c2ef125fc9dc454a7ec6b859dcb3..3ed3cf2268369dc5c14321e7d9a032d0c5bb464e 100644 (file)
@@ -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]);
     }
   }