Extending Coding Rules using XPath (since version 2.0)
Since version 2.1, grammar rule names are in uppercase, and each word in seperated by an underscore, such as: "COMPILATION_UNIT"
New coding rules can be added using XPath. See the related documentation.
Once you have packaged your custom rule in a dll file and added it to your FxCop/Gendarme/StyleCop installation, you need to:
- add an XML file describing this rule in the "$SONAR_HOME/extensions/rules/ENGINE" where $SONAR_HOME is the root directory of your sonar installation and ENGINE is either "fxcop"
- , "gendarme" or "stylecop".
- restart Sonar
- add those new rules to your quality profiles so that they are used during the next Sonar analysis.
Below details on the format of these files.
RULE_CLASS being the name of the .net rule class.
ASSEMBLY.DLL being the name of the dll assembly file containing the rule class.
The XML fragment above assumes that the dll is located in the same directory as the standard fxcop assembly rules files.
Note: to help writing this XML files, "vladonemo" has written a C# program that generates this file based on your custom rules DLL. You can check this out on GitHub, but be aware that this comes with no garanty.
Let's assume you have implemented a rule that checks if variable name follows a naming convention. You have implemented it in a class called "VariableConventionNameCheck", and you have compiled it into a "MyNamingConvetions.dll" assembly file.