How to make a simple declaration of a rule with check in sonarqube?

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.

Hello,

Can someone from sonarsource please help me?

Best Regards,

Hi,

Several of SonarSource’s language analyzers are open source. Have you tried taking a look at them?

 
Ann

Hi,

Thanks for your reply.
If by “SonarSource’s language analyzers” you mean examples of rules implemented, then i found a few. They all seem to compete for complexity. One of the less complex i found is : GitHub - wttech/AEM-Rules-for-SonarQube: SonarQube plugin with set of rules detecting possible bugs and bad smells specific for AEM development..

My initial question is: Once i have declared a rule, is it impossible to specify it in the same file ? If not, how many files minimum are needed and what should they contain ?

I can’t seem to find any step by step tutorial to add rules plug-in Sonarqube. Does such a guide exist ?

Best Regards.

Hi,

Sorry, but there really aren’t any tutorials for supporting new languages. Your best bet really is to look at existing analyzers / plugins.

 
Ann