The creation of a rule set for the external tool re-uses the concept of Extending Rules in C++ Analysers therefore the only thing needed is a xml file with the definition of the rules and their respective activation in SonarQube. The rules xml file needs to be installed under
The property sonar.cxx.externalrules.reportPath is used to point to the location of the report (relative to project root). The following table describes the format of the report
| Xml Description - RNG-Schema | Example |
|---|---|
<element name="results" xmlns="http://relaxng.org/ns/structure/1.0"> <zeroOrMore> <element name="error"> <attribute name="file"/> <attribute name="msg"/> <attribute name="id"/> <attribute name="line"> <data type="integer" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" /> </attribute> <text/> </element> </zeroOrMore> </element> | <?xml version="1.0"?> |
| Attribute | Description |
| file | source file, relative to project path |
| line | line of the violation |
| id | id of the rule, mapped a rule in SonarQube. See "Enable the rules in SonarQube server" below |
| msg | description of the violation |
| Tool | Source | Usage | Rules Profile / Needed scripts |
|---|---|---|---|
| cpplint | Create the rules profile and the modified cpplint python script as follow:
This will generate the following files:
After this you can run the cpplint_mod.py against any source file like this:
The output file report.txt needs to be converted to xml format described above. For convenience a perl script is available here and can be run as follow:
|
This is maintained by the community, so if you want to share additional rules profiles or tool do so by using the user mailing list |
The list above is provided without any warranty, therefore you may need to debug the scripts or tools in order to make them work |