Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

  • defining them directly through the SonarQube TM web interface using XPath expressions
  • or reusing custom ones rules defined in external tools such as FxCop, Gendarme or StyleCop

...

You can reference your custom rules from FxCop and/or Gendarme and/or StyleCop in SonarQubeTM:

  1. Write a piece of XML to reference your custom coding rules. See formats below.
  2. Go to Settings > Configuration > General Settings > .Net FxCop or .Net Gendarme or C# StyleCop
  3. Paste this piece of your XML in .NET/C# XXX custom rules
  4. Click on Save .NET/C# XXX settings
  5. Restart your SonarQube TM server
  6. Activate your custom coding rules in your C# quality profiles

...

Code Block
<?xml version="1.0" encoding="UTF-8"?><rules>

  <rule key="RULE_CLASS">
    <!-- name, configKey and description are mandatory -->
    <name><![CDATA[ ... put here the human readable name of this rule ... ]]></name>
    <configKey><![CDATA[RULE_CLASS@$(FxCopDir)\Rules\ASSEMBLY.DLL]]></configKey>
    <description><![CDATA[ ... put here the human readable description of this rule ... ]]></description>
  </rule>

  <rule key="... >
    ...
  </rule>

</rules>

RULE_CLASS: name of the .NET rule class
ASSEMBLY.DLL: 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 write this XML filesfile, "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 it comes with no guarantee.

Example

...

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<rules>
  <rule key="VariableConventionNameCheck">
    <name>Variable<!-- name, configKey and description are mandatory -->
    <name>Variable name conventions</name>
    <configKey><![CDATA[VariableConventionNameCheck@$(FxCopDir)\Rules\MyNamingConvetions.dll]]></configKey>
    <description><![CDATA[ This rule checks that variables follow the company naming conventions ]]></description>
  </rule>
</rules>

...

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<rules>

  <rule key="RULE_CLASS">
    <name><!<!-- name, configKey and description are mandatory -->
    <name><![CDATA[ ... put here the human readable name of this rule ... ]]></name>
    <configKey><![CDATA[RULE_CLASS@ASSEMBLY.DLL]]></configKey>
    <description><![CDATA[ ... put here the human readable description of this rule ... ]]></description>
  </rule>

  <rule key="... >
    ...
  </rule>

</rules> 

...

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<rules>

  <rule key="ElementMustBeginWithUpperCaseLetter">
    <!-- name, configKey and description are mandatory -->
    <name><![CDATA[Element must begin with upper case letter]]></name>
    <configKey><![CDATA[Microsoft.StyleCop.CSharp.NamingRules#ElementMustBeginWithUpperCaseLetter]]></configKey>
    <description><![CDATA[Element must begin with upper case letter because ....]]></description>
  </rule>

  <rule key="... >
    ...
  </rule>

</rules>