Message-ID: <604664656.919.1432829941211.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_918_1595539535.1432829941210" ------=_Part_918_1595539535.1432829941210 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
There are two ways to extend coding rules:
Note that the Java API, if available, will be more fully-featured than w= hat's available for XPath, and is generally preferable.=20 =20 =20
The following languages can be extended with new rules written in Java: = COBOL and Java.
To go further, you can have a look at the following classes implementing= coding rules:
See how to extend COBOL rules.
SonarQube provides a quick and easy way to add new coding rules dir= ectly via the web interface for certain languages (C/C++, COBOL, Flex, Java= Script, PL/I, PL/SQL, and Python).
The rules must be written in XPath (version 1.0) t= o navigate the language's Abstract Syntax = Tree (AST). For each language, an SSLR Toolkit is provid= ed to help you navigate the AST. Each language's SSLR Toolkit is a standalo= ne application that displays the AST for a piece of code source that you fe= ed into it, allowing you to read the node names and attributes from your co= de sample and write your XPath expression. Knowing the XPath language = is the only prerequisite, and there are a lot of tutorials on XPath online = (see http://www.w3schools.com/xpath/ for example).<= /p>
The proper SSLR Toolkit can be downloaded from the language plugin page = or here:
While parsing source code, SonarQube builds an Abstract Syntax Tree (AST) for it, and the
The XPath language provides a way to write coding rules= by navigating this AST, and the SSLR Toolkit for the language will give yo= u the ability to test your new rules against your sample code.
Once your new rule is written, you can add it SonarQube:
Paste in the XPath rule (it should comply to XPath 1.0) you wrote an=
d tested using the SSLR toolkit:
Do not use document.write:
Always use curly braces for if/else statements: