5

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?

James King
  • 2,425
  • 7
  • 30
  • 45

1 Answers1

3

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.
  • Thank you very much, I will look at that today. My manager has also asked me if its possible to have a plugin which runs multiple regex, which are all stored on one file. Would this be possible has a store of quick and dirty way around it. To begin with I just need to check ESQL statements to ensure it matches up with the clients coding standards – James King Jul 31 '13 at 08:00