当前位置: 首页>>代码示例>>Java>>正文


Java Rule类代码示例

本文整理汇总了Java中org.sonar.check.Rule的典型用法代码示例。如果您正苦于以下问题:Java Rule类的具体用法?Java Rule怎么用?Java Rule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Rule类属于org.sonar.check包,在下文中一共展示了Rule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: load_rule_S100

import org.sonar.check.Rule; //导入依赖的package包/类
@Test
public void load_rule_S100() throws Exception {
  @Rule(key = "S100") class TestRule {
  }

  ruleMetadataLoader.addRulesByAnnotatedClass(newRepository, list(TestRule.class));
  newRepository.done();
  RulesDefinition.Repository repository = context.repository(RULE_REPOSITORY_KEY);
  RulesDefinition.Rule rule = repository.rule("S100");
  assertThat(rule).isNotNull();
  assertThat(rule.name()).isEqualTo("Function names should comply with a naming convention");
  assertThat(rule.htmlDescription()).isEqualTo("<p>description S100</p>");
  assertThat(rule.severity()).isEqualTo("MINOR");
  assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL);
  assertThat(rule.status()).isEqualTo(RuleStatus.READY);
  assertThat(rule.tags()).containsExactly("convention");
  DebtRemediationFunction remediation = rule.debtRemediationFunction();
  assertThat(remediation).isNotNull();
  assertThat(remediation.type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
  assertThat(remediation.baseEffort()).isEqualTo("5min");
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:22,代码来源:RuleMetadataLoaderTest.java

示例2: load_rule_S110

import org.sonar.check.Rule; //导入依赖的package包/类
@Test
public void load_rule_S110() throws Exception {
  @Rule(key = "S110") class TestRule {
  }
  ruleMetadataLoader.addRulesByAnnotatedClass(newRepository, list(TestRule.class));
  newRepository.done();
  RulesDefinition.Repository repository = context.repository(RULE_REPOSITORY_KEY);
  RulesDefinition.Rule rule = repository.rule("S110");
  assertThat(rule).isNotNull();
  DebtRemediationFunction remediation = rule.debtRemediationFunction();
  assertThat(remediation).isNotNull();
  assertThat(remediation.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
  assertThat(remediation.baseEffort()).isEqualTo("4h");
  assertThat(remediation.gapMultiplier()).isEqualTo("30min");
  assertThat(rule.gapDescription()).isEqualTo("Number of parents above the defined threshold");
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:17,代码来源:RuleMetadataLoaderTest.java

示例3: load_rules_key_based

import org.sonar.check.Rule; //导入依赖的package包/类
@Test
public void load_rules_key_based() throws Exception {
  ruleMetadataLoader.addRulesByRuleKey(newRepository, list("S110", "S100"));
  newRepository.done();

  RulesDefinition.Repository repository = context.repository(RULE_REPOSITORY_KEY);
  RulesDefinition.Rule ruleS110 = repository.rule("S110");
  assertThat(ruleS110).isNotNull();
  assertThat(ruleS110.name()).isEqualTo("Inheritance tree of classes should not be too deep");
  assertThat(ruleS110.htmlDescription()).isEqualTo("<p>description S110</p>");

  RulesDefinition.Rule ruleS100 = repository.rule("S100");
  assertThat(ruleS100).isNotNull();
  assertThat(ruleS100.name()).isEqualTo("Function names should comply with a naming convention");
  assertThat(ruleS100.htmlDescription()).isEqualTo("<p>description S100</p>");
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:17,代码来源:RuleMetadataLoaderTest.java

示例4: load_rule_S123

import org.sonar.check.Rule; //导入依赖的package包/类
@Test
public void load_rule_S123() throws Exception {
  @Rule(key = "S123")
  class TestRule {
  }
  ruleMetadataLoader.addRulesByAnnotatedClass(newRepository, list(TestRule.class));
  newRepository.done();

  RulesDefinition.Repository repository = context.repository(RULE_REPOSITORY_KEY);
  RulesDefinition.Rule rule = repository.rule("S123");
  assertThat(rule).isNotNull();
  DebtRemediationFunction remediation = rule.debtRemediationFunction();
  assertThat(remediation).isNotNull();
  assertThat(remediation.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
  assertThat(remediation.gapMultiplier()).isEqualTo("10min");
  assertThat(rule.gapDescription()).isNull();
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:18,代码来源:RuleMetadataLoaderTest.java

示例5: test

import org.sonar.check.Rule; //导入依赖的package包/类
@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");
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:22,代码来源:CustomScssRulesDefinitionTest.java

示例6: test

import org.sonar.check.Rule; //导入依赖的package包/类
@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");
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:22,代码来源:CustomLessRulesDefinitionTest.java

示例7: test

import org.sonar.check.Rule; //导入依赖的package包/类
@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");
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:22,代码来源:CustomCssRulesDefinitionTest.java

示例8: visitStyleSheet

import org.sonar.check.Rule; //导入依赖的package包/类
@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);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:18,代码来源:TabCharacterCheck.java

示例9: test

import org.sonar.check.Rule; //导入依赖的package包/类
@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());
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:18,代码来源:CssRulesDefinitionTest.java

示例10: test

import org.sonar.check.Rule; //导入依赖的package包/类
@Test
public void test() {
  MyCssCustomRulesDefinition rulesDefinition = new MyCssCustomRulesDefinition();

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

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

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

  RulesDefinition.Rule forbiddenPropertiesRule = repository.rule(ForbiddenPropertiesCheck.class.getAnnotation(Rule.class).key());
  assertThat(forbiddenPropertiesRule).isNotNull();
  assertThat(forbiddenPropertiesRule.name()).isEqualTo(ForbiddenPropertiesCheck.class.getAnnotation(Rule.class).name());
}
 
开发者ID:racodond,项目名称:sonar-css-custom-rules-plugin,代码行数:18,代码来源:MyCssCustomRulesDefinitionTest.java

示例11: test

import org.sonar.check.Rule; //导入依赖的package包/类
@Test
public void test() {
  MyLessCustomRulesDefinition rulesDefinition = new MyLessCustomRulesDefinition();

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

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

  assertThat(repository.name()).isEqualTo("My Less Custom Repository");
  assertThat(repository.language()).isEqualTo("less");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule interpolatedPropertiesRule = repository.rule(InterpolatedPropertiesCheck.class.getAnnotation(Rule.class).key());
  assertThat(interpolatedPropertiesRule).isNotNull();
  assertThat(interpolatedPropertiesRule.name()).isEqualTo(InterpolatedPropertiesCheck.class.getAnnotation(Rule.class).name());
}
 
开发者ID:racodond,项目名称:sonar-css-custom-rules-plugin,代码行数:18,代码来源:MyLessCustomRulesDefinitionTest.java

示例12: test

import org.sonar.check.Rule; //导入依赖的package包/类
@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());
}
 
开发者ID:racodond,项目名称:sonar-gherkin-plugin,代码行数:18,代码来源:MyGherkinCustomRulesDefinitionTest.java

示例13: visitFile

import org.sonar.check.Rule; //导入依赖的package包/类
@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;
    }
  }
}
 
开发者ID:racodond,项目名称:sonar-gherkin-plugin,代码行数:17,代码来源:TabCharacterCheck.java

示例14: visitGherkinDocument

import org.sonar.check.Rule; //导入依赖的package包/类
@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);
}
 
开发者ID:racodond,项目名称:sonar-gherkin-plugin,代码行数:18,代码来源:TrailingWhitespaceCheck.java

示例15: test

import org.sonar.check.Rule; //导入依赖的package包/类
@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");
}
 
开发者ID:racodond,项目名称:sonar-gherkin-plugin,代码行数:22,代码来源:CustomGherkinRulesDefinitionTest.java


注:本文中的org.sonar.check.Rule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。