Add rules to COBOL


Currently we are using sonar-cobol-plugin in house, but now we want to add one rule to cobol. This rule is specific to our company, and basically consists in apply a regex, verify some content, and mark a issue.

For what I have read, Sonar can only have one plugin claiming one extension at a time. Is this a limitation?

If it is, how can I add a rule to COBOL through a plugin? How should I proceed?

Bruno Oliveira

Hi Bruno,

Have you read

Basically, you can create a plugin that will “extend” rules of SonarCobol.



Adding a custom rule (as suggested by Julien) is possible.

If you really don’t need the COBOL parsing capabilities of sonar-cobol to write your rules, you can also create a separate plugin which doesn’t “claim” COBOL extensions. That’s somehow what sonar-java does: it’s able to raise issues on pom.xml files which are XML files without causing any incompatibility with sonar-xml.


Thank you.

My doubt was about the concept of “claiming”. I thought that we couldn’t have two plugins “claiming” the COBOL file extensions.

What will I loose if i don’t claim Cobol extensions? Whats the difference of “claiming” and “not clamming” them?

I think you should simply create a plugin where the define method of the plugin class does not include a class extending org.sonar.api.resources.Language.

You can have a sensor which retrieves all files which SonarQube associates to the COBOL language (example for PHP) and raise issues on those files.

As you don’t declare the COBOL language to SonarQube, your plugin will be able to run alongside another plugin which declares the COBOL language (SonarCOBOL) but of course it will require this plugin to be present.