Custom rule for Mulesoft Code not working in SonarQube

Hi There,

I have recently implemented the sonarqube integration for Mule 4 applications following the below tutorial.

Publish Mule 4 Code Review and Coverage to SonarQube

I am now trying to write a custom rule, which will do the following things;

  1. Scan the pom.xml and verify the project name ends with “-api”, “-sapi”, “-eapi”, “-papi”. Below is the rule I added to the rules4.xml
<rule id="3"
     name="Mule Project Name Must End with -api/sapi/eapi/papi"
     description="The Mule project name should end with one of the following suffixes: -api, -sapi, -eapi, -papi."
     severity="MAJOR" applies="project" type="code_smell">
     not(matches(/project/name, '^(.*)-(api|sapi|papi|eapi)$'))
</rule>

But the scanner is not checking for it correctly. It shows the pom.xml file considered in the code sectoin of sonarqube after running the analysis.

  1. Also I am trying to write one more rule about the scheduler which is also not working fine.
<rule id="22"
     name="Scheduler frequency time unit must be set to MILLISECONDS"
     description="Ensure Scheduler frequency time unit is MILLISECONDS or uses the default."
     severity="MAJOR" type="code_smell"> 
     count(//mule:mule/mule:flow/scheduler) > 0
     or
     //mule:mule/mule:flow/scheduler/scheduler:frequency/@timeUnit !='MILLISECONDS'
</rule>

Even when the timeUnits is in Hours or minutes it is NOT tagging the code smell.

Any thoughts how anybody can support here please?

Regards
Kaushik V

Hi Kaushik,

We don’t support adding rules in this format. You should direct this question to the Mulesoft plugin maintainers and/or the blog post writer.

 
HTH,
Ann

What is an ideal way to start about writing custom rules in that case?

If not mule plugin, then for an xml, how do we write a rule in general?

Could you kindly provide some path to it?

Hi,

The docs should get you started.

 
HTH,
Ann