org.sonar.api.server.rule.RulesDefinition.Rule Java Examples
The following examples show how to use
org.sonar.api.server.rule.RulesDefinition.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: PmdRulesDefinitionTest.java From sonar-p3c-pmd with MIT License | 6 votes |
@Test public void should_use_text_parameter_for_xpath_rule() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); Rule xpathRule = Iterables.find(repository.rules(), new Predicate<Rule>() { @Override public boolean apply(Rule rule) { return rule.key().equals("XPathRule"); } }); assertThat(xpathRule.param("xpath").type().type()).isEqualTo(PropertyType.TEXT.name()); }
Example #2
Source File: PmdRulesDefinitionTest.java From sonar-p3c-pmd with MIT License | 5 votes |
@Test public void test() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(PmdConstants.REPOSITORY_NAME); assertThat(repository.language()).isEqualTo(Java.KEY); List<Rule> rules = repository.rules(); //assertThat(rules).hasSize(268); for (Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); assertThat(rule.severity()).isNotNull(); for (Param param : rule.params()) { assertThat(param.name()).isNotNull(); assertThat(param.description()) .overridingErrorMessage("Description is not set for parameter '" + param.name() + "' of rule '" + rule.key()) .isNotNull(); } if (!"XPathRule".equals(rule.key())) { assertThat(rule.debtRemediationFunction()) .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key()) .isNotNull(); assertThat(rule.debtSubCharacteristic()) .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key()) .isNotNull(); } } }
Example #3
Source File: PmdRulesDefinitionTest.java From sonar-p3c-pmd with MIT License | 5 votes |
@Test public void should_exclude_junit_rules() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); for (Rule rule : repository.rules()) { assertThat(rule.key()).excludes("JUnitStaticSuite"); } }
Example #4
Source File: EsqlRulesDefinitionTest.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private void assertRuleProperties(Repository repository) { Rule rule = repository.rule("UnusedRoutine"); assertThat(rule).isNotNull(); assertThat(rule.name()).isEqualTo("Unused routines should be removed"); assertThat(rule.debtRemediationFunction().type()).isEqualTo(Type.CONSTANT_ISSUE); assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL); assertThat(repository.rule("CommentRegularExpression").template()).isTrue(); }
Example #5
Source File: EsqlRulesDefinitionTest.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private void assertAllRuleParametersHaveDescription(Repository repository) { for (Rule rule : repository.rules()) { for (Param param : rule.params()) { assertThat(param.description()).as("description for " + param.key()).isNotEmpty(); } } }
Example #6
Source File: PmdUnitTestsRulesDefinitionTest.java From sonar-p3c-pmd with MIT License | 4 votes |
@Test public void test() { PmdUnitTestsRulesDefinition definition = new PmdUnitTestsRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.TEST_REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(PmdConstants.TEST_REPOSITORY_NAME); assertThat(repository.language()).isEqualTo(Java.KEY); List<Rule> rules = repository.rules(); assertThat(rules).hasSize(17); for (Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.key()).isIn( "JUnitStaticSuite", "JUnitSpelling", "JUnitAssertionsShouldIncludeMessage", "JUnitTestsShouldIncludeAssert", "TestClassWithoutTestCases", "UnnecessaryBooleanAssertion", "UseAssertEqualsInsteadOfAssertTrue", "UseAssertSameInsteadOfAssertTrue", "UseAssertNullInsteadOfAssertTrue", "SimplifyBooleanAssertion", "UseAssertTrueInsteadOfAssertEquals", "JUnitTestContainsTooManyAsserts", "JUnit4SuitesShouldUseSuiteAnnotation", "JUnit4TestShouldUseAfterAnnotation", "JUnit4TestShouldUseBeforeAnnotation", "JUnit4TestShouldUseTestAnnotation", "JUnitUseExpected"); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); assertThat(rule.severity()).isNotNull(); for (Param param : rule.params()) { assertThat(param.name()).isNotNull(); assertThat(param.description()) .overridingErrorMessage("Description is not set for parameter '" + param.name() + "' of rule '" + rule.key()) .isNotNull(); } if (!"XPathRule".equals(rule.key())) { assertThat(rule.debtRemediationFunction()) .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key()) .isNotNull(); assertThat(rule.debtSubCharacteristic()) .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key()) .isNotNull(); } } }
Example #7
Source File: TsRulesDefinitionTest.java From SonarTsPlugin with MIT License | 4 votes |
@Test public void ConfiguresAdditionalRules() { // cfg1 Rule rule1 = getRule("custom-rule-1"); assertNull(rule1); // cfg2 Rule rule2 = getRule("custom-rule-2"); assertNotNull(rule2); assertEquals("test rule #2", rule2.name()); assertEquals(Severity.MINOR, rule2.severity()); assertEquals("#2 description", rule2.htmlDescription()); assertEquals(null, rule2.debtRemediationFunction()); assertEquals(RuleType.CODE_SMELL, rule2.type()); // cfg3 Rule rule3 = getRule("custom-rule-3"); assertNotNull(rule3); assertEquals("test rule #3", rule3.name()); assertEquals(Severity.INFO, rule3.severity()); assertEquals("#3 description", rule3.htmlDescription()); assertEquals( DebtRemediationFunction.Type.CONSTANT_ISSUE, rule3.debtRemediationFunction().type() ); assertEquals(null, rule3.debtRemediationFunction().gapMultiplier()); assertEquals("15min", rule3.debtRemediationFunction().baseEffort()); assertEquals(RuleType.CODE_SMELL, rule3.type()); // cfg4 Rule rule4 = getRule("custom-rule-4"); assertNotNull(rule4); assertEquals("test rule #4", rule4.name()); assertEquals(Severity.MINOR, rule4.severity()); assertEquals("#4 description", rule4.htmlDescription()); assertEquals( DebtRemediationFunction.Type.LINEAR, rule4.debtRemediationFunction().type() ); assertEquals("5min", rule4.debtRemediationFunction().gapMultiplier()); assertEquals(null, rule4.debtRemediationFunction().baseEffort()); assertEquals(RuleType.BUG, rule4.type()); // cfg5 Rule rule5 = getRule("custom-rule-5"); assertNotNull(rule5); assertEquals("test rule #5", rule5.name()); assertEquals(Severity.MAJOR, rule5.severity()); assertEquals("#5 description", rule5.htmlDescription()); assertEquals(RuleType.VULNERABILITY, rule5.type()); assertEquals("30min", rule5.debtRemediationFunction().gapMultiplier()); assertEquals("15min", rule5.debtRemediationFunction().baseEffort()); }
Example #8
Source File: TsRulesDefinitionTest.java From SonarTsPlugin with MIT License | 4 votes |
private Rule getRule(String name) { return this.context.repository(TsRulesDefinition.REPOSITORY_NAME).rule(name); }