Tabnine Logo
Rule.create
Code IndexAdd Tabnine to your IDE (free)

How to use
create
method
in
org.sonar.api.rules.Rule

Best Java code snippets using org.sonar.api.rules.Rule.create (Showing top 20 results out of 315)

origin: SonarSource/sonarqube

 @Override
 public RulesProfile createProfile(ValidationMessages validation) {
  final RulesProfile profile = RulesProfile.create("Sonar way", Xoo.KEY);

  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.INFO);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY), RulePriority.CRITICAL);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HotspotSensor.RULE_KEY), RulePriority.CRITICAL);

  return profile;
 }
}
origin: SonarSource/sonarqube

 @Override
 public List<Rule> createRules() {
  Rule rule = Rule.create("checkstyle", "ConstantName");
  rule.createParameter("format");
  return Arrays.asList(rule);
 }
}
origin: SonarSource/sonarqube

 @Override
 public RulesProfile createProfile(ValidationMessages messages) {
  RulesProfile profile = RulesProfile.create("Sonar way", Xoo2.KEY);

  profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.MINOR);

  return profile;
 }
}
origin: SonarSource/sonarqube

 public Rule answer(InvocationOnMock iom) throws Throwable {
  Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
  rule.createParameter("format");
  rule.createParameter("message");
  return rule;
 }
});
origin: SonarSource/sonarqube

 @Override
 public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
  RulesProfile rulesProfile = RulesProfile.create();
  rulesProfile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, "x1"), RulePriority.CRITICAL);
  return rulesProfile;
 }
}
origin: SonarSource/sonarqube

 @Override
 public List<Rule> createRules() {
  Rule rule = Rule.create("checkstyle", "ConstantName", "Constant Name");
  rule.setDescription("Checks that constant names conform to the specified format");
  rule.setConfigKey("Checker/TreeWalker/ConstantName");
  rule.setSeverity(RulePriority.BLOCKER);
  rule.setStatus(Rule.STATUS_BETA);
  rule.setTags(new String[] {"style", "clumsy"});
  rule.createParameter("format").setDescription("Regular expression").setDefaultValue("A-Z").setType("REGULAR_EXPRESSION");
  return Arrays.asList(rule);
 }
}
origin: SonarSource/sonarqube

 @Override
 public RulesProfile createProfile(ValidationMessages validation) {
  final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY);
  profile.setDefaultProfile(true);

  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);

  return profile;
 }
}
origin: SonarSource/sonarqube

 @Override
 public RulesProfile createProfile(ValidationMessages messages) {
  RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY);
  profile.setDefaultProfile(true);

  // so UGLY
  profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);

  return profile;
 }
}
origin: SonarSource/sonarqube

@Test
public void should_set_valid_status() {
 Rule rule = Rule.create().setStatus(Rule.STATUS_DEPRECATED);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_DEPRECATED);
 rule = Rule.create().setStatus(Rule.STATUS_REMOVED);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_REMOVED);
 rule = Rule.create().setStatus(Rule.STATUS_BETA);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_BETA);
 rule = Rule.create().setStatus(Rule.STATUS_READY);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_READY);
}
origin: SonarSource/sonarqube

 @Override
 public RulesProfile createProfile(ValidationMessages validation) {
  RulesProfile profile1 = RulesProfile.create("Profile 1", "xoo");
  profile1.activateRule(Rule.create("repo1", "defaultSeverity"), null);
  profile1.activateRule(Rule.create("repo1", "overrideSeverity"), RulePriority.CRITICAL);
  Rule ruleWithParam = Rule.create("repo1", "overrideParam");
  ruleWithParam.setParams(Arrays.asList(new RuleParam(ruleWithParam, "param", "", "")));
  ActiveRule arWithParam = profile1.activateRule(ruleWithParam, null);
  arWithParam.setParameter("param", "value");
  return profile1;
 }
}
origin: SonarSource/sonarqube

@Test
public void default_priority_is_major() {
 Rule rule = Rule.create();
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 rule = new Rule("name", "key");
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 rule.setSeverity(RulePriority.BLOCKER);
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
 rule.setSeverity(null);
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
}
origin: SonarSource/sonarqube

@Test
public void should_remove_new_line_characters_in_name_with_setter() {
 Rule rule = Rule.create();
 for (String example : getExamplesContainingNewLineCharacter()) {
  rule.setName(example);
  assertThat(rule.getName()).isEqualTo("test");
 }
}
origin: SonarSource/sonarqube

@Test
public void searchRulesByConfigKey() {
 RulesProfile profile = RulesProfile.create();
 profile.activateRule(Rule.create("repo", "key1", "name1"), null);
 profile.activateRule(Rule.create("repo", "key2", "name2").setConfigKey("config2"), null);
 assertThat(profile.getActiveRuleByConfigKey("repo", "unknown")).isNull();
 assertThat(profile.getActiveRuleByConfigKey("repo", "config2").getRuleKey()).isEqualTo("key2");
}
origin: SonarSource/sonarqube

@Test
public void shouldMatchRule() {
 RuleKey rule = Rule.create("checkstyle", "IllegalRegexp", "").ruleKey();
 assertThat(new IssuePattern("*", "*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "checkstyle:*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "checkstyle:IllegalRegexp").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "checkstyle:Illegal*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "*:*Illegal*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "pmd:IllegalRegexp").matchRule(rule)).isFalse();
 assertThat(new IssuePattern("*", "pmd:*").matchRule(rule)).isFalse();
 assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").matchRule(rule)).isFalse();
}
origin: SonarSource/sonarqube

@Test
public void match_rule() {
 RuleKey rule = Rule.create("checkstyle", "IllegalRegexp", "").ruleKey();
 assertThat(new IssuePattern("*", "*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "checkstyle:*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "checkstyle:IllegalRegexp").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "checkstyle:Illegal*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "*:*Illegal*").matchRule(rule)).isTrue();
 assertThat(new IssuePattern("*", "pmd:IllegalRegexp").matchRule(rule)).isFalse();
 assertThat(new IssuePattern("*", "pmd:*").matchRule(rule)).isFalse();
 assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").matchRule(rule)).isFalse();
}
origin: SonarSource/sonarqube

@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);
}
origin: SonarSource/sonarqube

@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);
}
origin: SonarSource/sonarqube

@Test
public void exportProfile() throws IOException, SAXException {
 Writer writer = new StringWriter();
 RulesProfile profile = RulesProfile.create("sonar way", "java");
 profile.activateRule(Rule.create("checkstyle", "IllegalRegexp", "illegal regexp"), RulePriority.BLOCKER);
 new XMLProfileSerializer().write(profile, writer);
 assertSimilarXml("exportProfile.xml", writer.toString());
}
origin: SonarSource/sonarqube

 @Override
 public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
  RulesProfile rulesProfile = RulesProfile.create();
  rulesProfile.activateRule(Rule.create(rule.getRepositoryKey(), rule.getRuleKey()), RulePriority.CRITICAL);
  return rulesProfile;
 }
}
origin: SonarSource/sonarqube

@Test
public void description_should_be_cleaned() {
 Rule rule = Rule.create().setDescription("    my description         ");
 Assert.assertEquals("my description", rule.getDescription());
 rule.setDescription(null);
 assertThat(rule.getDescription()).isNull();
}
org.sonar.api.rulesRulecreate

Javadoc

Create with all required fields

Popular methods of Rule

  • getKey
  • getConfigKey
  • setConfigKey
    Sets the configuration key
  • setName
    Sets the rule name
  • setSeverity
  • getName
  • getRepositoryKey
  • ruleKey
  • setDescription
    Sets the rule description
  • createParameter
  • getSeverity
  • setTags
    For definition of rule only
  • getSeverity,
  • setTags,
  • <init>,
  • getParam,
  • getParams,
  • setKey,
  • setStatus,
  • getDescription,
  • setRepositoryKey

Popular in Java

  • Creating JSON documents from java classes using gson
  • requestLocationUpdates (LocationManager)
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JPanel (javax.swing)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now