Hello
I am using Sonarqube V9.4 and i wished to add custom rules for a new language. After many difficulties, i succeeded in adding the plugin with two empty rules.
The problem i have is how to add verification of the code. You’ll find below the declaration of one rule i made. Can someone please tell me what to add in this piece of code to carry out the check ? My main problem is that all the available examples i found never have a complete definition of the rule and check at one place.
Is it possible in sonarqube to add a check of type: if a specific condition then check failed ?
public final class AmlLintRulesDefinition implements RulesDefinition {
public static final String REPOSITORY = "aml";
public static final String LANGUAGE = "aml";
public static final RuleKey RULE_ON_LINE_1 = RuleKey.of(REPOSITORY, "line1");
@Override
public void define(Context context) {
NewRepository repository = context.createRepository(REPOSITORY, LANGUAGE).setName("My Custom Analyzer");
NewRule x1Rule = repository.createRule(RULE_ON_LINE_1.rule())
.setName("Stupid aml rule")
.setHtmlDescription("Generates an issue on every line 1 of files")
// optional tags
.setTags("style", "stupid")
// optional status. Default value is READY.
.setStatus(RuleStatus.BETA)
// default severity when the rule is activated on a Quality profile. Default value is MAJOR.
.setSeverity(Severity.MINOR);
x1Rule.setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min"));
// don't forget to call done() to finalize the definition
repository.done();
}
Thanks for the help.
Best Regards.