org.sonar.api.rule.RuleKey Java Examples

The following examples show how to use org.sonar.api.rule.RuleKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GherkinSquidSensorTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_execute_and_save_issues_on_UTF8_file() {
  inputFile("my-feature.feature", Charsets.UTF_8);

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .build();
  checkFactory = new CheckFactory(activeRules);

  createGherkinSquidSensor().execute(context);

  assertThat(context.allIssues()).hasSize(3);
}
 
Example #2
Source File: ApexSquidSensor.java    From enforce-sonarqube-plugin with MIT License 6 votes vote down vote up
/**
 * Saves issues form input file and source file.
 *
 * @param sonarFile input file.
 * @param squidFile source file.
 */
private void saveIssues(InputFile sonarFile, SourceFile squidFile) {
    Collection<CheckMessage> messages = squidFile.getCheckMessages();
    messages.forEach(message -> {
        RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
        Issuable issuable = resourcePerspectives.as(Issuable.class, sonarFile);

        if (issuable != null) {
            Issue issue = issuable.newIssueBuilder()
                    .ruleKey(ruleKey)
                    .line(message.getLine())
                    .message(message.getText(Locale.ENGLISH))
                    .build();
            issuable.addIssue(issue);
        }
    });
}
 
Example #3
Source File: EsqlSensor.java    From sonar-esql-plugin with Apache License 2.0 6 votes vote down vote up
private static void savePreciseIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, PreciseIssue issue) {
    NewIssue newIssue = sensorContext.newIssue();

    newIssue
            .forRule(ruleKey)
            .at(newLocation(inputFile, newIssue, issue.primaryLocation()));

    if (issue.cost() != null) {
        newIssue.gap(issue.cost());
    }

    for (IssueLocation secondary : issue.secondaryLocations()) {
        newIssue.addLocation(newLocation(inputFile, newIssue, secondary));
    }
    newIssue.save();
}
 
Example #4
Source File: RubocopSensor.java    From sonar-ruby-plugin with MIT License 6 votes vote down vote up
private void saveNewIssue(RubocopIssue issue, InputFile inputFile, Set<String> ruleNames, SensorContext sensorContext) {
    // Make sure the rule we're violating is one we recognise - if not, we'll
    // fall back to the generic 'rubocop-issue' rule
    String ruleName = issue.getRuleName();
    if (!ruleNames.contains(ruleName)) {
        ruleName = RubyRulesDefinition.RUBY_LINT_UNKNOWN_RULE.key;
    }

    NewIssue newIssue =
        sensorContext
            .newIssue()
            .forRule(RuleKey.of("rubocop", ruleName));

    NewIssueLocation newIssueLocation =
        newIssue
            .newLocation()
            .on(inputFile)
            .message(issue.getFailure())
            .at(inputFile.selectLine(issue.getPosition().getLine()));

    newIssue.at(newIssueLocation);
    newIssue.save();
}
 
Example #5
Source File: ScssAnalyzerSensorTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
  inputFile("parsingError.scss");

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(CheckList.SCSS_REPOSITORY_KEY, "S2260"))
    .activate()
    .build();

  checkFactory = new CheckFactory(activeRules);

  context.setActiveRules(activeRules);
  createScssSquidSensor().execute(context);
  Collection<Issue> issues = context.allIssues();
  assertThat(issues).hasSize(1);
  Issue issue = issues.iterator().next();
  assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
 
Example #6
Source File: LessAnalyzerSensorTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
  inputFile("parsingError.less");

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(CheckList.LESS_REPOSITORY_KEY, "S2260"))
    .activate()
    .build();

  checkFactory = new CheckFactory(activeRules);

  context.setActiveRules(activeRules);
  createLessSquidSensor().execute(context);
  Collection<Issue> issues = context.allIssues();
  assertThat(issues).hasSize(1);
  Issue issue = issues.iterator().next();
  assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
 
Example #7
Source File: GherkinSquidSensorTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
  String relativePath = "parsing-error.feature";
  inputFile(relativePath, Charsets.UTF_8);

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, "S2260"))
    .activate()
    .build();

  checkFactory = new CheckFactory(activeRules);

  context.setActiveRules(activeRules);
  createGherkinSquidSensor().execute(context);
  Collection<Issue> issues = context.allIssues();
  assertThat(issues).hasSize(1);
  Issue issue = issues.iterator().next();
  assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
 
Example #8
Source File: FlowSquidSensor.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void saveViolations(SensorContext context, InputFile inputFile, SourceFile squidFile) {
  Collection<CheckMessage> messages = squidFile.getCheckMessages();
  logger.debug("+++Nr of violations found: " + messages.size());
  if (messages != null) {
    for (CheckMessage message : messages) {
      Object c = message.getCheck();
      if (c instanceof FlowCheck) {
        FlowCheck fc = (FlowCheck) c;
        if (squidFile.getInt(FlowMetric.IS_TOP_LEVEL) != 1 && fc.isTopLevelCheck()) {
          logger.debug("+++Ignoring toplevelCheck for file: " + squidFile.getKey());
        } else {
          RuleKey ruleKey;
          if (fc.isNodeCheck()) {
            ruleKey = nodeChecks.ruleKey(fc);
          } else {
            ruleKey = flowChecks.ruleKey(fc);
          }
          FlowIssue.create(context, ruleKey, message.getCost())
              .setPrimaryLocation(inputFile, message).save();
        }
      }
    }
  }
}
 
Example #9
Source File: GherkinSquidSensorTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_execute_and_save_issues_on_UTF8_file_french() {
  inputFile("my-feature-fr.feature", Charsets.UTF_8);

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .build();
  checkFactory = new CheckFactory(activeRules);

  createGherkinSquidSensor().execute(context);

  assertThat(context.allIssues()).hasSize(3);
}
 
Example #10
Source File: CssAnalyzerSensorTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
  inputFile("parsingError.css");

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(CheckList.CSS_REPOSITORY_KEY, "S2260"))
    .activate()
    .build();

  checkFactory = new CheckFactory(activeRules);

  context.setActiveRules(activeRules);
  createCssSquidSensor().execute(context);
  Collection<Issue> issues = context.allIssues();
  assertThat(issues).hasSize(1);
  Issue issue = issues.iterator().next();
  assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
 
Example #11
Source File: EsqlSensorTest.java    From sonar-esql-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void parsing_error() {
    String relativePath = "cpd/parsingError.esql";
    inputFile(relativePath);

    String parsingErrorCheckKey = "ParsingError";

    ActiveRules activeRules = (new ActiveRulesBuilder())
            .addRule(new NewActiveRule.Builder().setName("ParsingError").setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, parsingErrorCheckKey)).build())
            .build();

    checkFactory = new CheckFactory(activeRules);

    context.setActiveRules(activeRules);
    createSensor().execute(context);
    Collection<Issue> issues = context.allIssues();
    assertThat(issues).hasSize(1);
    Issue issue = issues.iterator().next();
    assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(3);
    assertThat(issue.primaryLocation().message()).isEqualTo("Parse error");

    assertThat(context.allAnalysisErrors()).hasSize(1);
}
 
Example #12
Source File: GherkinSquidSensorTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_execute_and_save_issues_on_UTF8_with_BOM_file_french() {
  inputFile("my-feature-bom-fr.feature", Charsets.UTF_8);

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .build();
  checkFactory = new CheckFactory(activeRules);

  createGherkinSquidSensor().execute(context);

  assertThat(context.allIssues()).hasSize(3);
}
 
Example #13
Source File: LeinNvdSensor.java    From sonar-clojure with MIT License 6 votes vote down vote up
private void saveVulnerabilities(List<Vulnerability> vulnerabilities, SensorContext context) {
    Optional<InputFile> fileOptional = getFile("project.clj", context.fileSystem());

    fileOptional.ifPresent(projectFile -> {
        for (Vulnerability v : vulnerabilities) {
            LOG.debug("Processing vulnerability: " +v.toString());
            RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, "nvd-" + v.getSeverity().toLowerCase());
            NewIssue newIssue = context.newIssue().forRule(ruleKey);
            NewIssueLocation primaryLocation = newIssue
                    .newLocation()
                    .on(projectFile)
                    .message(v.getName()
                            + ";" + v.getCwes()
                            + ";" + v.getFileName())
                    .at(projectFile.selectLine(1));
            newIssue.at(primaryLocation);
            newIssue.save();
        }
    });
}
 
Example #14
Source File: AbstractSensor.java    From sonar-clojure with MIT License 6 votes vote down vote up
protected void saveIssue(Issue issue, SensorContext context) {
    try {
        Optional<InputFile> fileOptional = getFile(issue.getFilePath(), context.fileSystem());

        if (fileOptional.isPresent()) {
            InputFile file = fileOptional.get();
            RuleKey ruleKey = RuleKey.of(ClojureLintRulesDefinition.REPOSITORY_KEY, issue.getExternalRuleId().trim());

            NewIssue newIssue = context.newIssue().forRule(ruleKey);

            NewIssueLocation primaryLocation = newIssue
                    .newLocation()
                    .on(file)
                    .message(issue.getDescription().trim());

            primaryLocation.at(file.selectLine(issue.getLine()));

            newIssue.at(primaryLocation);
            newIssue.save();
        } else {
            LOG.warn("Not able to find a file with path '{}'", issue.getFilePath());
        }
    } catch (Exception e) {
        LOG.error("Can not save the issue due to: " + e.getMessage());
    }
}
 
Example #15
Source File: LuaSquidSensor.java    From sonar-lua with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void saveViolations(SensorContext context, InputFile inputFile, SourceFile squidFile) {
  Collection<CheckMessage> messages = squidFile.getCheckMessages();
  if (messages != null) {

    for (CheckMessage message : messages) {
      RuleKey ruleKey = checks.ruleKey((SquidCheck<LexerlessGrammar>) message.getCheck());
      NewIssue newIssue = context.newIssue()
        .forRule(ruleKey)
        .gap(message.getCost());
      Integer line = message.getLine();
      NewIssueLocation location = newIssue.newLocation()
        .on(inputFile)
        .message(message.getText(Locale.ENGLISH));
      if (line != null) {
        location.at(inputFile.selectLine(line));
      }
      newIssue.at(location);
      newIssue.save();
    }
  }
}
 
Example #16
Source File: AbstractAnsibleSensor.java    From sonar-ansible with Apache License 2.0 6 votes vote down vote up
/**
 * Saves the found issues in SonarQube
 *
 * @param context the context
 * @param inputFile the file where the issue was found
 * @param line the line where the issue was found
 * @param ruleId the Id of the rule that raised the issue
 * @param message a message describing the issue
 */
protected void saveIssue(SensorContext context, InputFile inputFile, int line, String ruleId, String message) {
    RuleKey ruleKey = getRuleKey(context, ruleId);

    // Old rules (ansible-lint < 3.5) had id ANSIBLE... but now it is E... so we may need to add the heading E back
    if (ruleKey == null) {
        ruleKey = getRuleKey(context, "E" + ruleId);
    }

    if (ruleKey == null) {
        LOGGER.debug("Rule " + ruleId + " ignored, not found in repository");
        return;
    }

    NewIssue newIssue = context.newIssue().forRule(ruleKey);
    NewIssueLocation location = newIssue.newLocation()
            .on(inputFile)
            .message(message)
            .at(inputFile.selectLine(line));
    newIssue.at(location).save();
    LOGGER.debug("Issue {} saved for {}", ruleId, inputFile.filename());
}
 
Example #17
Source File: MessageUtilsTest.java    From sonar-gerrit-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void validateIssueSubstitution() {
    // given
    PostJobIssue issue = mock(PostJobIssue.class);
    when(issue.isNew()).thenReturn(true);
    when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "XX12"));
    when(issue.message()).thenReturn("You have a problem there");
    when(issue.severity()).thenReturn(Severity.BLOCKER);
    // when
    MapSettings settings = new MapSettings();
    settings.setProperty(PropertyKey.GERRIT_ISSUE_COMMENT,
        "[${issue.isNew}] New: ${issue.ruleKey} on ${sonar.host.url} Severity: ${issue.severity}, Message: ${issue.message}")
        .setProperty("sonar.host.url", "http://sq.example.com/");
    // then
    assertThat(MessageUtils.createIssueMessage(settings.getString(PropertyKey.GERRIT_ISSUE_COMMENT), settings,
        issue)).isEqualTo(
        "[true] New: squid:XX12 on http://sq.example.com/ Severity: BLOCKER, Message: You have a problem there");
}
 
Example #18
Source File: GherkinSquidSensorTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void should_execute_and_save_issues_on_UTF8_with_BOM_file() {
  inputFile("my-feature-bom.feature", Charsets.UTF_8);

  ActiveRules activeRules = (new ActiveRulesBuilder())
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key()))
    .activate()
    .build();
  checkFactory = new CheckFactory(activeRules);

  createGherkinSquidSensor().execute(context);

  assertThat(context.allIssues()).hasSize(3);
}
 
Example #19
Source File: GerritPostJobTest.java    From sonar-gerrit-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldConvertIssueToComment() {
    GerritConfiguration gerritConfiguration = new GerritConfiguration(settings);
    GerritFacadeFactory gerritFacadeFactory = mock(GerritFacadeFactory.class);

    RuleKey ruleKey = RuleKey.of("test-repo", "sonar-1");
    PostJobIssue postJobIssue = mock(PostJobIssue.class);
    when(postJobIssue.line()).thenReturn(12);
    when(postJobIssue.severity()).thenReturn(Severity.INFO);
    when(postJobIssue.message()).thenReturn("Should be a message test");
    when(postJobIssue.ruleKey()).thenReturn(ruleKey);
    when(postJobIssue.isNew()).thenReturn(Boolean.TRUE);

    GerritPostJob gerritPostJob = new GerritPostJob(settings, gerritConfiguration, gerritFacadeFactory);
    ReviewLineComment reviewLineComment = gerritPostJob.issueToComment(postJobIssue);
    Assertions.assertEquals(new Integer(12), reviewLineComment.getLine());
    Assertions.assertEquals(0, reviewLineComment.getSeverity());
    Assertions.assertEquals("[New: true] INFO(test-repo:sonar-1) found: Should be a message test", reviewLineComment.getMessage());
}
 
Example #20
Source File: EsqlSensorTest.java    From sonar-esql-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void custom_rule() throws Exception {
    inputFile("file.esql");
    ActiveRules activeRules = (new ActiveRulesBuilder())
            .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("customKey", "key")).build()).build();
    checkFactory = new CheckFactory(activeRules);
    createSensorWithCustomRules().execute(context);

    Collection<Issue> issues = context.allIssues();
    assertThat(issues).hasSize(1);
    Issue issue = issues.iterator().next();
    assertThat(issue.gap()).isEqualTo(42);
    assertThat(issue.primaryLocation().message()).isEqualTo("Message of custom rule");
    assertThat(issue.primaryLocation().textRange())
            .isEqualTo(new DefaultTextRange(new DefaultTextPointer(1, 0), new DefaultTextPointer(1, 24)));
}
 
Example #21
Source File: EsqlSensorTest.java    From sonar-esql-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void analysis_with_issues_should_not_add_error_to_context() {
    inputFile("file.esql");

    ActiveRules activeRules = (new ActiveRulesBuilder())
            .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, "MissingNewlineAtEndOfFile")).build())
            .build();
    checkFactory = new CheckFactory(activeRules);

    createSensor().execute(context);

    Collection<Issue> issues = context.allIssues();
    assertThat(issues).hasSize(1);

    assertThat(context.allAnalysisErrors()).isEmpty();
}
 
Example #22
Source File: HtlSensor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
/**
 * Create HtlScanner with Visitors.
 */
private HtlScanner setupScanner() {
    HtlScanner scanner = new HtlScanner();

    for (HtlCheck check : checks.getAll()) {
        RuleKey ruleKey = checks.ruleKeyFor(check);
        check.setRuleKey(ruleKey);
        if (check instanceof DefaultHtlVisitor) {
            DefaultHtlVisitor nodeVisitor = (DefaultHtlVisitor) check;
            scanner.addVisitor(nodeVisitor);
        }
    }
    return scanner;
}
 
Example #23
Source File: HtlFilesAnalyzer.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private static RuleKey setupParsingErrorRuleKey(HtlChecks checks) {
    return checks.getAll().stream()
        .filter(check -> check.getClass().isAnnotationPresent(ParsingErrorRule.class))
        .findFirst()
        .map(checks::ruleKeyFor)
        .orElse(null);
}
 
Example #24
Source File: HtlChecks.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Nullable
public RuleKey ruleKeyFor(HtlCheck check) {
    RuleKey ruleKey = null;

    for (Checks<HtlCheck> checks : checksByRepository) {
        ruleKey = checks.ruleKey(check);

        if (ruleKey != null) {
            break;
        }
    }
    return ruleKey;
}
 
Example #25
Source File: EsqlSensor.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
private static void saveLineIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, LineIssue issue) {
    NewIssue newIssue = sensorContext.newIssue();

    NewIssueLocation primaryLocation = newIssue.newLocation()
            .message(issue.message())
            .on(inputFile)
            .at(inputFile.selectLine(issue.line()));

    saveIssue(newIssue, primaryLocation, ruleKey, issue);
}
 
Example #26
Source File: HtlSensorTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private CheckFactory getCheckFactory(Repository htlRepository) {
    List<NewActiveRule> ar = new ArrayList<>();
    for (RulesDefinition.Rule rule : htlRepository.rules()) {
        ar.add(new NewActiveRule.Builder().setRuleKey(RuleKey.of(HtlCheckClasses.REPOSITORY_KEY, rule.key())).build());
    }
    return new CheckFactory(new DefaultActiveRules(ar));
}
 
Example #27
Source File: GerritPostJobTest.java    From sonar-gerrit-plugin with Apache License 2.0 5 votes vote down vote up
private PostJobIssue createPostJobIssueMock(int line, InputPath inputPath, Severity severity, String rule, String msg, Boolean isNew) {
    PostJobIssue postJobIssue = mock(PostJobIssue.class);
    when(postJobIssue.line()).thenReturn(line);
    when(postJobIssue.inputComponent()).thenReturn(inputPath);
    when(postJobIssue.severity()).thenReturn(severity);
    when(postJobIssue.ruleKey()).thenReturn(RuleKey.of("SQ-repo", rule));
    when(postJobIssue.message()).thenReturn(msg);
    when(postJobIssue.isNew()).thenReturn(isNew);
    return postJobIssue;
}
 
Example #28
Source File: EsqlChecks.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public RuleKey ruleKeyFor(EsqlCheck check) {
  RuleKey ruleKey;

  for (Checks<EsqlCheck> checks : checksByRepository) {
    ruleKey = checks.ruleKey(check);

    if (ruleKey != null) {
      return ruleKey;
    }
  }
  return null;
}
 
Example #29
Source File: EsqlSensorTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void save_issue() throws Exception {
    inputFile("file.esql");

    ActiveRules activeRules = (new ActiveRulesBuilder())
            .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, "MissingNewlineAtEndOfFile")).build())
            .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of(CheckList.REPOSITORY_KEY, "InitializeVariables")).build())
            .build();

    checkFactory = new CheckFactory(activeRules);
    createSensor().execute(context);
    Collection<Issue> issues = context.allIssues();
    assertThat(issues).hasSize(2);
}
 
Example #30
Source File: EsqlSensor.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
private static void saveIssue(NewIssue newIssue, NewIssueLocation primaryLocation, RuleKey ruleKey, Issue issue) {
    newIssue
            .forRule(ruleKey)
            .at(primaryLocation);

    if (issue.cost() != null) {
        newIssue.gap(issue.cost());
    }

    newIssue.save();
}