For IntelliJ IDEA and
Android Studio


private void myMethod () {RulesProfile r =
new RulesProfile()
String name;RulesProfile.create(name, language)
- AI code suggestions by Codota
}
@Override public ActiveRule getActiveRule(Rule rule) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(rule); if (activeRule != null) { return activeRule; } } return null; }
@Test public void importProfileWithRuleParameters() { ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = parse("importProfileWithRuleParameters.xml", validation); assertThat(validation.hasErrors()).isFalse(); assertThat(validation.hasWarnings()).isFalse(); ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp"); assertThat(rule.getParameter("format")).isEqualTo("foo"); assertThat(rule.getParameter("message")).isEqualTo("with special characters < > &"); }
@Test public void support_rule_templates() { QProfile qProfile = new QProfile("java-sw", "Sonar way", "java", null); when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile)); ActiveRulesBuilder activeRulesBuilder = new ActiveRulesBuilder(); activeRulesBuilder.create(RuleKey.of("java", "S001")).setTemplateRuleKey("T001").setLanguage("java").activate(); RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings.asConfig()); assertThat(profile.getActiveRule("java", "S001").getRule().getTemplate().getKey()).isEqualTo("T001"); } }
@Test public void activateRuleWithSpecificPriority() { RulesProfile profile = RulesProfile.create(); Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL); profile.activateRule(rule, RulePriority.MINOR); assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.MINOR); }
@Test public void importProfile() { ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = parse("importProfile.xml", validation); assertThat(profile.getLanguage()).isEqualTo("java"); assertThat(profile.getName()).isEqualTo("sonar way"); assertThat(validation.hasErrors()).isFalse(); assertThat(profile).isNotNull(); assertThat(profile.getActiveRule("checkstyle", "IllegalRegexp").getSeverity()).isEqualTo(RulePriority.CRITICAL); }
/** * Note: disabled rules are excluded. */ @CheckForNull public ActiveRule getActiveRule(Rule rule) { return getActiveRule(rule.getRepositoryKey(), rule.getKey()); }
@Test public void importProfileWithUnknownRuleParameter() { ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = parse("importProfileWithUnknownRuleParameter.xml", validation); assertThat(validation.getWarnings()).hasSize(1); ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp"); assertThat(rule.getParameter("unknown")).isNull(); }
@Test public void shouldParseOnlyWantedProfile() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { public Rule answer(InvocationOnMock iom) throws Throwable { return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]); } }); ValidationMessages messages = ValidationMessages.create(); RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages); assertThat(profile.getActiveRule("squid", "fake")).isNotNull(); assertThat(profile.getActiveRule("squid", "other")).isNull(); } }
@Test public void shouldParseAnnotatedClasses() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { public Rule answer(InvocationOnMock iom) throws Throwable { return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]); } }); ValidationMessages messages = ValidationMessages.create(); RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages); assertThat(profile.getName()).isEqualTo("Foo way"); assertThat(profile.getLanguage()).isEqualTo("java"); assertThat(profile.getActiveRule("squid", "fake").getSeverity()).isEqualTo(RulePriority.BLOCKER); assertThat(messages.hasErrors()).isFalse(); }
@Override public ActiveRule getActiveRule(String repositoryKey, String ruleKey) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(repositoryKey, ruleKey); if (activeRule != null) { return activeRule; } } return null; }
@Test public void activateRuleWithDefaultPriority() { RulesProfile profile = RulesProfile.create(); Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL); profile.activateRule(rule, null); assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.CRITICAL); }
/** * Note: disabled rules are excluded. */ @CheckForNull public ActiveRule getActiveRule(Rule rule) { return getActiveRule(rule.getRepositoryKey(), rule.getKey()); }
/** * Note: disabled rules are excluded. */ @CheckForNull public ActiveRule getActiveRule(Rule rule) { return getActiveRule(rule.getRepositoryKey(), rule.getKey()); }
@Override public ActiveRule getActiveRule(String repositoryKey, String ruleKey) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(repositoryKey, ruleKey); if (activeRule != null) { return activeRule; } } return null; }
@Override public ActiveRule getActiveRule(Rule rule) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(rule); if (activeRule != null) { return activeRule; } } return null; }