Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed references to SSLR toolkit for VB.NET and C#


  1. Writing custom rules in Java via a SonarQube plugin
  2. Adding XPath rules directly through the SonarQube web interface

Note that the first way must be preferred when available because the support of XPath will be eventually droppedJava API, if available, will be more fully-featured than what's available for XPath, and is generally preferable.


Before implementing a new coding rule, you should consider whether it is specific to your own context or might benefit others. If it might benefit others, you can propose them on the developer list. If the SonarQube team find your proposed rules interesting, they may be implemented directly in the related language plugin. It means less maintenance for you, and benefit to others.


SonarQube provides a quick and easy way to add new coding rules directly via the web interface for certain languages (C/C++, C#COBOL, Cobol, Flex, Java, JavaScript, PL/I, PL/SQL, and Python and VB.NET).

The rules must be written in XPath (version 1.0) to navigate the language's Abstract Syntax Tree (AST). For each language, an SSLR Toolkit is provided to help you navigate the AST. Each language's SSLR Toolkit is a standalone application that displays the AST for a piece of code source that you feed into it, allowing you to read the node names and attributes from your code sample and write your XPath expression. The proper SSLR Toolkit can be downloaded from the language plugin page. So, knowing the Knowing the XPath language is the only prerequisite, and there are a lot of tutorials on XPath online (see for example).

The proper SSLR Toolkit can be downloaded from the language plugin page or here:


For an SSLR preview, consider the following JavaScript source code sample: