Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube - help in creating a new language plugin

I am creating a new plugin for SonarQube which allows developers to perform static code analysis on ESQL code.

Using Maven I can build a shell of a plugin, which produces the JAR file which I can place in the correct folder in order for it to be added to SonarQube.

The next stage is to write the Java classes for the rules, however I am unsure on what and where these look like. I am using the example from the following GIT repository: https://github.com/SonarSource/sonar-examples/tree/master/plugins/sonar-reference-plugin

Do I simply create a new package with some classes? And how do I actually rules?

like image 375
James King Avatar asked Oct 22 '22 04:10

James King


1 Answers

If you want to write a rule engine for the ESQL language, this means that you must first write a parser for this language. And only after you completed this stage, you will create a rule engine based on that parser (with visitor classes that navigate through the AST and that create issues under specific circumstances).

You can take a look at how we implemented the Javascript plugin (see the code of version 1.3):

  • the "javascript-squid" module is where the parser is written
  • the "javascript-checks" module is where the rule engine (based on the parser) is written
  • the "sonar-javascript-plugin" module is the actual plugin, which embeds the parser and the rule engine and which provides all the required glue around them.
like image 159
Fabrice - SonarSource Team Avatar answered Oct 28 '22 00:10

Fabrice - SonarSource Team