Versions Compared

Key

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

...

  • defining them directly through the SonarQube TM web interface using XPath expressions
  • or reusing custom ones 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 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>

...

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>