org.sonar.api.batch.rule.internal.NewActiveRule Java Examples

The following examples show how to use org.sonar.api.batch.rule.internal.NewActiveRule. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: LuaSquidSensorTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  NewActiveRule ar = new ActiveRulesBuilder().create(RuleKey.of("lua", "S1125")).setSeverity("BLOCKER");
  ActiveRules activeRules = new DefaultActiveRules(Collections.singletonList(ar));
  CheckFactory checkFactory = new CheckFactory(activeRules);
  FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
  when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
  sensor = new LuaSquidSensor(checkFactory, fileLinesContextFactory);
  tester = SensorContextTester.create(TEST_DIR);
}