Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


The XPath language provides a way to write coding rules by navigating this AST, and the SSLR Toolkit for the language will give you the ability to test your new rules against your sample code.

To create a new rule in SonarQube:

  1. Login as an administrator
  2. Go to Configuration > Quality Profile
  3. Select one of the quality profiles whose for the language you want wish to add a new the rule to
  4. Look for the XPath rule template:
  5. Copy this template to create a new rule:
  6. Write your Paste in the XPath rule (it should comply to XPath 1.0) you wrote and tested using the SSLR toolkit:

    Here are two examples of JavaScript XPath rules:

    Do not use document.write

    Code Block
    //callExpression/memberExpression[count(*) = 3 and primaryExpression[@tokenValue = "document"] and identifierName[@tokenValue = "write"]]

    Always use curly braces for if/else statements:

    Code Block



  7. Once written, activate those rules and run an analysis.
  8. Issues on those XPath rules are now logged: