org.sonar.check.Rule Java Examples

The following examples show how to use org.sonar.check.Rule. 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: CustomScssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 7 votes vote down vote up
@Test
public void test() {
  MyCustomScssRulesDefinition rulesDefinition = new MyCustomScssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("scss");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #2
Source File: MyGherkinCustomRulesDefinitionTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyGherkinCustomRulesDefinition rulesDefinition = new MyGherkinCustomRulesDefinition();

  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);

  RulesDefinition.Repository repository = context.repository("custom-gherkin");

  assertThat(repository.name()).isEqualTo("My Gherkin Custom Repository");
  assertThat(repository.language()).isEqualTo("gherkin");
  assertThat(repository.rules()).hasSize(2);

  RulesDefinition.Rule forbiddenKeysRule = repository.rule(ForbiddenTagCheck.class.getAnnotation(Rule.class).key());
  assertThat(forbiddenKeysRule).isNotNull();
  assertThat(forbiddenKeysRule.name()).isEqualTo(ForbiddenTagCheck.class.getAnnotation(Rule.class).name());
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
Source File: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
private RulesDefinition.NewRule createRule(RulesDefinition.NewExtendedRepository repo, Class clazz, Rule ruleAnnotation) {
    String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
    String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
    String description = StringUtils.defaultIfEmpty(loadDescription(ruleKey), "No description yet.");

    RulesDefinition.NewRule rule = repo.createRule(ruleKey);
    rule.setName(ruleName).setMarkdownDescription(description);
    rule.setSeverity(ruleAnnotation.priority().name());
    rule.setStatus(RuleStatus.valueOf(ruleAnnotation.status()));
    rule.setTags(ruleAnnotation.tags());

    setMetadata(rule, clazz);

    List<Field> fields = FieldUtils2.getFields(clazz, true);
    for (Field field : fields) {
        loadParameters(rule, field);
    }

    return rule;
}
 
Example #8
Source File: CustomGherkinRulesDefinitionTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyCustomGherkinRulesDefinition rulesDefinition = new MyCustomGherkinRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("gherkin");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #9
Source File: TrailingWhitespaceCheck.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void visitGherkinDocument(GherkinDocumentTree tree) {
  List<String> lines;
  try {
    lines = Files.readLines(getContext().getFile(), charset);
  } catch (IOException e) {
    throw new IllegalStateException("Check gherking:" + this.getClass().getAnnotation(Rule.class).key()
      + ": Error while reading " + getContext().getFile().getName(), e);
  }
  for (int i = 0; i < lines.size(); i++) {
    String line = lines.get(i);
    if (line.length() > 0 && Pattern.matches("[" + WHITESPACE + "]", line.subSequence(line.length() - 1, line.length()))) {
      addLineIssue(i + 1, "Remove the useless trailing whitespaces at the end of this line.");
    }
  }
  super.visitGherkinDocument(tree);
}
 
Example #10
Source File: TabCharacterCheck.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void visitFile(Tree tree) {
  List<String> lines;
  try {
    lines = Files.readLines(getContext().getFile(), charset);
  } catch (IOException e) {
    throw new IllegalStateException("Check gherkin:" + this.getClass().getAnnotation(Rule.class).key()
      + ": Error while reading " + getContext().getFile().getName(), e);
  }
  for (String line : lines) {
    if (line.contains("\t")) {
      addFileIssue("Replace all tab characters in this file by sequences of whitespaces.");
      break;
    }
  }
}
 
Example #11
Source File: CssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  CssRulesDefinition rulesDefinition = new CssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("css");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("css");
  assertThat(repository.rules()).hasSize(88);
  assertThat(CheckList.getEmbeddedCssChecks()).hasSize(repository.rules().size() - 6);


  RulesDefinition.Rule todoRule = repository.rule(TodoTagCheck.class.getAnnotation(Rule.class).key());
  assertThat(todoRule).isNotNull();
  assertThat(todoRule.name()).isEqualTo(TodoTagCheck.class.getAnnotation(Rule.class).name());
}
 
Example #12
Source File: TrailingWhitespaceCheck.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void visitStyleSheet(StyleSheetTree tree) {
  List<String> lines;
  try {
    lines = Files.readLines(getContext().getFile(), charset);
  } catch (IOException e) {
    throw new IllegalStateException("Check css:" + this.getClass().getAnnotation(Rule.class).key()
      + ": Error while reading " + getContext().getFile().getName(), e);
  }
  for (int i = 0; i < lines.size(); i++) {
    String line = lines.get(i);
    if (line.length() > 0 && Pattern.matches("[" + WHITESPACE + "]", line.subSequence(line.length() - 1, line.length()))) {
      addLineIssue(i + 1, "Remove the useless trailing whitespaces at the end of this line.");
    }
  }
  super.visitStyleSheet(tree);
}
 
Example #13
Source File: TabCharacterCheck.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void visitStyleSheet(StyleSheetTree tree) {
  List<String> lines;
  try {
    lines = Files.readLines(getContext().getFile(), charset);
  } catch (IOException e) {
    throw new IllegalStateException("Check css:" + this.getClass().getAnnotation(Rule.class).key()
      + ": Error while reading " + getContext().getFile().getName(), e);
  }
  for (String line : lines) {
    if (line.contains("\t")) {
      addFileIssue("Replace all tab characters in this file by sequences of whitespaces.");
      break;
    }
  }
  super.visitStyleSheet(tree);
}
 
Example #14
Source File: CustomCssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyCustomCssRulesDefinition rulesDefinition = new MyCustomCssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("css");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #15
Source File: CustomLessRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyCustomLessRulesDefinition rulesDefinition = new MyCustomLessRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("less");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #16
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotLoadRuleWhenRuleAnnotationIsNotPresent() {
    givenRulesLoaded(List.of(RuleWithoutRuleAnnotation.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule, is(nullValue()));
}
 
Example #17
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotSetTechnicalDebtWhenTechnicalDebtNotSetInMetadata() {
    givenRulesLoaded(List.of(RuleWithEmptyTechnicalDebt.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MINOR.toString()));
    Assert.assertThat(rule.tags().contains(Tags.AEM), is(true));
    Assert.assertThat(rule.debtRemediationFunction(), is(nullValue()));
}
 
Example #18
Source File: EsqlProfilesDefinitionTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void no_legacy_Key_in_profile_json() {
    Set<String> allKeys = CheckList.getChecks().stream().map(c -> {
        Annotation ruleAnnotation = c.getAnnotation(Rule.class);
        return ((Rule) ruleAnnotation).key();
    }).collect(Collectors.toSet());

    Set<String> sonarWayKeys = BuiltInQualityProfileJsonLoader.loadActiveKeysFromJsonProfile(SONAR_WAY_JSON);

    assertThat(sonarWayKeys).isSubsetOf(allKeys);
}
 
Example #19
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotSetTechnicalDebtWhenAnnotationNotPresent() {
    givenRulesLoaded(List.of(RuleWithoutMetadataAnnotation.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MINOR.toString()));
    Assert.assertThat(rule.tags().contains(Tags.AEM), is(true));
    Assert.assertThat(rule.debtRemediationFunction(), is(nullValue()));
}
 
Example #20
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetDefaultValuesWhenRuleAttributeWithNameOnly() {
    givenRulesLoaded(List.of(RuleWithOnlyNameAttribute.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule("com.cognifide.aemrules.extensions.RulesLoaderTest.RuleWithOnlyNameAttribute");

    Assert.assertThat(rule.markdownDescription(), is("No description yet."));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MAJOR.toString()));
    Assert.assertThat(rule.tags().size(), is(0));
    Assert.assertThat(rule.debtRemediationFunction().baseEffort(), is(TECHNICAL_DEBT));
}
 
Example #21
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadRuleWithAllSettings() {
    givenRulesLoaded(List.of(RuleWithAllSettings.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MINOR.toString()));
    Assert.assertThat(rule.tags().contains(Tags.AEM), is(true));
    Assert.assertThat(rule.debtRemediationFunction().baseEffort(), is(TECHNICAL_DEBT));
}
 
Example #22
Source File: AbstractBaseTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private static HtlScanner setupScanner(AbstractHtlCheck check, HtmlCheckVerifier htmlCheckVerifier) {
    HtlScanner scanner = new HtlScanner();
    scanner.addVisitor(new ExpectedIssueCollector(htmlCheckVerifier));
    if (check != null) {
        Class<? extends HtlCheck> htlCheck = check.getClass();
        Rule rule = HtlCheckClasses.getRule(htlCheck);
        RuleKey ruleKey = RuleKey.of(HtlCheckClasses.REPOSITORY_KEY, rule.key());
        check.setRuleKey(ruleKey);
    }
    scanner.addVisitor(check);
    return scanner;
}
 
Example #23
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadRuleWithProperty() {
    givenRulesLoaded(List.of(RuleWithRuleProperty.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);
    RulesDefinition.Param param = rule.param(RULE_PROPERTY_KEY);

    Assert.assertThat(param.description(), is(RULE_PROPERTY_DESCRIPTION));
    Assert.assertThat(param.defaultValue(), is(RULES_PROPERTY_DEFAULT_VALUE));
    Assert.assertThat(param.type().type(), is(RULES_PROPERTY_TYPE));
}
 
Example #24
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadRuleWithPropertyWithoutAttributes() {
    givenRulesLoaded(List.of(RuleWithRulePropertyWithoutAttributes.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);
    RulesDefinition.Param param = rule.param("testProperty");

    Assert.assertThat(param.description(), is(nullValue()));
    Assert.assertThat(param.defaultValue(), is(nullValue()));
    Assert.assertThat(param.type().type(), is("STRING"));
}
 
Example #25
Source File: HtlProfile.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Override
public void define(Context context) {
    NewBuiltInQualityProfile htl = context
        .createBuiltInQualityProfile(QUALITY_PROFILE_NAME, Htl.KEY);
    HtlCheckClasses.getCheckClasses().stream()
        .map(HtlCheckClasses::getRule)
        .map(Rule::key)
        .filter(Objects::nonNull)
        .forEach(ruleKey -> htl.activateRule(HtlCheckClasses.REPOSITORY_KEY, ruleKey));
    htl.done();
}
 
Example #26
Source File: GherkinRulesDefinitionTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  GherkinRulesDefinition rulesDefinition = new GherkinRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("gherkin");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("gherkin");
  assertThat(repository.rules()).hasSize(46);

  RulesDefinition.Rule lineLengthRule = repository.rule(TabCharacterCheck.class.getAnnotation(Rule.class).key());
  assertThat(lineLengthRule).isNotNull();
  assertThat(lineLengthRule.name()).isEqualTo(TabCharacterCheck.class.getAnnotation(Rule.class).name());
}
 
Example #27
Source File: EndLineCharactersCheck.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean fileContainsIllegalEndLineCharacters() {
  try {
    String fileContent = Files.asCharSource(getContext().getFile(), charset).read();
    return "CR".equals(endLineCharacters) && Pattern.compile("(?s)\n").matcher(fileContent).find()
      || "LF".equals(endLineCharacters) && Pattern.compile("(?s)\r").matcher(fileContent).find()
      || "CRLF".equals(endLineCharacters) && Pattern.compile("(?s)(\r(?!\n)|(?<!\r)\n)").matcher(fileContent).find();
  } catch (IOException e) {
    throw new IllegalStateException("Check gherkin:" + this.getClass().getAnnotation(Rule.class).key() + ": File cannot be read.", e);
  }
}
 
Example #28
Source File: MissingNewlineAtEndOfFileCheck.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void visitGherkinDocument(GherkinDocumentTree tree) {
  try (RandomAccessFile randomAccessFile = new RandomAccessFile(getContext().getFile(), "r")) {
    if (!endsWithNewline(randomAccessFile)) {
      addFileIssue("Add an empty new line at the end of this file.");
    }
  } catch (IOException e) {
    throw new IllegalStateException("Check gherkin:" + this.getClass().getAnnotation(Rule.class).key()
      + ": Error while reading " + getContext().getFile().getName(), e);
  }
  super.visitGherkinDocument(tree);
}
 
Example #29
Source File: ScssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  ScssRulesDefinition rulesDefinition = new ScssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("scss");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("scss");
  assertThat(repository.rules()).hasSize(100);

  RulesDefinition.Rule rule = repository.rule(ScssVariableNamingConventionCheck.class.getAnnotation(Rule.class).key());
  assertThat(rule).isNotNull();
  assertThat(rule.name()).isEqualTo(ScssVariableNamingConventionCheck.class.getAnnotation(Rule.class).name());
}
 
Example #30
Source File: LessRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  LessRulesDefinition rulesDefinition = new LessRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("less");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("less");
  assertThat(repository.rules()).hasSize(89);

  RulesDefinition.Rule rule = repository.rule(DeprecatedEscapingFunctionCheck.class.getAnnotation(Rule.class).key());
  assertThat(rule).isNotNull();
  assertThat(rule.name()).isEqualTo(DeprecatedEscapingFunctionCheck.class.getAnnotation(Rule.class).name());
}