Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
SonarQube
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>The C# Ecosystem can be extended with custom coding rules either by:</p><ul><li>defining them directly through the SonarQube web interface using XPath expressions</li><li>or reusing custom ones defined in external tools such as FxCop, Gendarme or StyleCop</li></ul><h1>Extending Coding Rules using XPath</h1><p>New coding rules can be added using XPath. See the related <a class="confluence-link" href="/display/SONAR/Extending+Coding+Rules#ExtendingCodingRules-extendingRulesXPath" data-anchor="extendingRulesXPath" data-linked-resource-id="183205932" data-linked-resource-type="page" data-linked-resource-default-alias="Extending Coding Rules#extendingRulesXPath" data-base-url="http://docs.codehaus.org">documentation</a>.</p><p>To navigate the AST, download the <a href="http://repository.codehaus.org/org/codehaus/sonar-plugins/dotnet/csharp/sslr-csharp-toolkit/2.1/sslr-csharp-toolkit-2.1.jar">SSLR CSharp Toolkit</a>.</p><table class="wysiwyg-macro" data-macro-name="note" data-macro-parameters="title=Migrating XPath rules from version 2.0 to 2.1+" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGU6dGl0bGU9TWlncmF0aW5nIFhQYXRoIHJ1bGVzIGZyb20gdmVyc2lvbiAyLjAgdG8gMi4xK30&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Since version 2.1, grammar rule names are in uppercase, and each word in seperated by an underscore, such as: "COMPILATION_UNIT"<br />In version 2.0, camel cases was used, such as: "compilationUnit"<br />To convert XPath expressions written for version 2.0 to ones valid in 2.1, simply add underscores between words and uppercase.</p></td></tr></table><h1>Reusing Custom Rules from External Tools</h1><p>You can reference your custom rules from FxCop and/or Gendarme and/or StyleCop in SonarQube:</p><ol><li>Write a piece of XML to reference your custom coding rules. See formats below.</li><li>Go to Settings > Configuration > General Settings > .Net FxCop or .Net Gendarme or C# StyleCop</li><li>Paste this piece of XML in .NET/C# XXX custom rules</li><li>Click on Save .NET/C# XXX settings</li><li>Restart your SonarQube server</li><li>Activate your custom coding rules in your C# <a href="http://docs.codehaus.org/display/SONAR/Quality+Profiles">quality profiles</a></li></ol><h2>FxCop Format</h2><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><?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> </pre></td></tr></table><p>RULE_CLASS: name of the .NET rule class<br /> ASSEMBLY.DLL: name of the dll assembly file containing the rule class<br /> The XML fragment above assumes that the dll is located in the same directory as the standard FxCop assembly rules files.</p><p><em>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 <a href="https://github.com/vladonemo/SonarFxCopRulesGenerator">on GitHub</a></em><em>, but be aware that this comes with no guarantee.</em></p><h4>Example</h4><p>Let's assume that you have implemented a rule that checks whether a variable name follows a specific naming convention or not. You have implemented it in a class called "VariableConventionNameCheck", and you have compiled it into a "MyNamingConvetions.dll" assembly file. Then, you should write the following piece of XML:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><?xml version="1.0" encoding="UTF-8"?> <rules> <rule key="VariableConventionNameCheck"> <!-- 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> </pre></td></tr></table><h2>Gendarme Format</h2><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><?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@ASSEMBLY.DLL]]></configKey> <description><![CDATA[ ... put here the human readable description of this rule ... ]]></description> </rule> <rule key="... > ... </rule> </rules> </pre></td></tr></table><p>RULE_CLASS: name of the .NET rule class<br /> ASSEMBLY.DLL: name of the dll assembly file containing the rule class. This file should be located in the installation directory of Gendarme, among the dll files provided by Gendarme out of the box. See the example of FxCop XML format, it is the same principle.</p><h2>StyleCop Format</h2><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><?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></pre></td></tr></table>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced