@Test public void rules() { RulesDefinition rulesDefinition = new KotlinRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7,2), SonarQubeSide.SERVER)); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); RulesDefinition.Repository repository = context.repository("kotlin"); assertThat(repository.name()).isEqualTo("SonarAnalyzer"); assertThat(repository.language()).isEqualTo("kotlin"); RulesDefinition.Rule rule = repository.rule("S1764"); assertThat(rule).isNotNull(); assertThat(rule.name()).isEqualTo("Identical expressions should not be used on both sides of a binary operator"); assertThat(rule.type()).isEqualTo(RuleType.BUG); assertThat(rule.htmlDescription()).startsWith("<p>Using the same value on either side"); RulesDefinition.Rule ruleWithConfig = repository.rule("S100"); RulesDefinition.Param param = ruleWithConfig.param("format"); assertThat(param.defaultValue()).isEqualTo("^[a-zA-Z][a-zA-Z0-9]*$"); }
@Override public void define(Context context) { NewRepository repository = context .createRepository(KotlinPlugin.KOTLIN_REPOSITORY_KEY, KotlinPlugin.KOTLIN_LANGUAGE_KEY) .setName(KotlinPlugin.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_FOLDER, KotlinProfileDefinition.PATH_TO_JSON, sonarRuntime); ArrayList<Class> checks = new ArrayList<>(KotlinCheckList.checks()); checks.add(CommentedCodeCheck.class); ruleMetadataLoader.addRulesByAnnotatedClass(repository, checks); RulesDefinitionUtils.setDefaultValuesForParameters(repository, checks, Language.KOTLIN); repository.done(); }
KotlinRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(KotlinPlugin.KOTLIN_REPOSITORY_KEY, KotlinPlugin.KOTLIN_LANGUAGE_KEY) .setName(KotlinPlugin.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_FOLDER, KotlinProfileDefinition.PATH_TO_JSON, sonarRuntime); ArrayList<Class> checks = new ArrayList<>(KotlinCheckList.checks()); checks.add(CommentedCodeCheck.class); ruleMetadataLoader.addRulesByAnnotatedClass(repository, checks); RulesDefinitionUtils.setDefaultValuesForParameters(repository, checks, Language.KOTLIN); repository.done(); } }
KotlinRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(KotlinPlugin.KOTLIN_REPOSITORY_KEY, KotlinPlugin.KOTLIN_LANGUAGE_KEY) .setName(KotlinPlugin.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_FOLDER, KotlinProfileDefinition.PATH_TO_JSON, sonarRuntime); ArrayList<Class> checks = new ArrayList<>(KotlinCheckList.checks()); checks.add(CommentedCodeCheck.class); ruleMetadataLoader.addRulesByAnnotatedClass(repository, checks); RulesDefinitionUtils.setDefaultValuesForParameters(repository, checks, Language.KOTLIN); repository.done(); } KotlinRulesDefinition(SonarRuntime sonarRuntime); }
KotlinRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(KotlinPlugin.KOTLIN_REPOSITORY_KEY, KotlinPlugin.KOTLIN_LANGUAGE_KEY) .setName(KotlinPlugin.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_FOLDER, KotlinProfileDefinition.PATH_TO_JSON, sonarRuntime); ArrayList<Class> checks = new ArrayList<>(KotlinCheckList.checks()); checks.add(CommentedCodeCheck.class); ruleMetadataLoader.addRulesByAnnotatedClass(repository, checks); RulesDefinitionUtils.setDefaultValuesForParameters(repository, checks, Language.KOTLIN); repository.done(); } KotlinRulesDefinition(SonarRuntime sonarRuntime); @Override void define(Context context); }
KotlinRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(KotlinPlugin.KOTLIN_REPOSITORY_KEY, KotlinPlugin.KOTLIN_LANGUAGE_KEY) .setName(KotlinPlugin.REPOSITORY_NAME); RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_FOLDER, KotlinProfileDefinition.PATH_TO_JSON, sonarRuntime); ArrayList<Class> checks = new ArrayList<>(KotlinCheckList.checks()); checks.add(CommentedCodeCheck.class); ruleMetadataLoader.addRulesByAnnotatedClass(repository, checks); RulesDefinitionUtils.setDefaultValuesForParameters(repository, checks, Language.KOTLIN); repository.done(); } KotlinRulesDefinition(SonarRuntime sonarRuntime); @Override void define(Context context);  }