Product | Quality Gate | Coverage |
---|---|---|
Analyzer | ||
Plugin |
Static analysis of C# and VB.NET languages in SonarQube, SonarCloud and SonarLint code quality and security products. These Roslyn analyzers allow you to produce Clean Code that is safe, reliable, and maintainable by helping you find and correct bugs, vulnerabilities, and code smells in your codebase.
- 470+ C# rules and 210+ VB.​NET rules
- Metrics (cognitive complexity, duplications, number of lines, etc.)
- Import of test coverage reports from Visual Studio Code Coverage, dotCover, OpenCover, Coverlet, Altcover.
- Import of third-party Roslyn Analyzers results
- Support for custom rules
- Contact us on our Community Forum to provide feedback, ask for help, and request new rules or features.
- Create a GitHub Issue if you've found a bug, False-Positive or False-Negative.
- Building, testing and debugging the .NET analyzer
- Building, testing and debugging the Java plugin
- How to re-generate NuGet lock files
- Using the rspec.ps1 script
There are many ways you can contribute to the sonar-dotnet
project.
When contributing, please respect our Code of Conduct.
One of the easiest ways to contribute is to share your feedback with us (see give feedback) and also answer questions from our community forum. You can also monitor the activity on this repository (opened issues, opened PRs) to get more acquainted with what we do.
If you want to fix an issue, please read the Get started pages first and make sure that you follow our coding style.
Before submitting the PR, make sure all tests are passing (all checks must be green).
- We suggest you do not pick issues with the
Area: CFG
label (they are difficult, can have many side effects and are less likely to be accepted). - We suggest you do not implement new rules unless they are already specified for C# and/or VB.NET on our rules repository.
Note: Our CI does not get automatically triggered on the PRs from external contributors. A member of our team will review the code and trigger the CI on demand by adding a comment on the PR (see Azure Pipelines Comment triggers docs):
/azp run Sonar.Net
- It will run the full pipeline, including plugin tests and promotion
If you would like to work on this project full-time, we are hiring!
To request new rules, Contact us on our Community Forum.
If you have an idea for a rule but you are not sure that everyone needs it, you can implement your own Roslyn analyzer.
- You can start with this tutorial from Microsoft to write an analyzer.
- All Roslyn-based issues are picked up by the SonarScanner for .NET and pushed to SonarQube / SonarCloud as external issues.
- Also check out SonarQube Roslyn SDK to embed your Roslyn analyzer in a SonarQube plugin, if you want to manage your rules from SonarQube.
Open the rule in SonarQube / SonarCloud, scroll down, and (in case the rule has parameters), you can configure the parameters for each Quality Profile the rule is part of.
Use SonarLint Connected Mode to connect to SonarQube and SonarCloud.
The easiest way is to configure a Quality Profile in SonarCloud.
- Create a dummy repository and analyze it in SonarCloud (it's free for open-source).
- Configure the Quality Profile in SonarCloud for the project you created.
- Then connect SonarLint to that project, and it will download the configuration (ruleset and SonarLint.xml files) locally and update your project based on the Quality Profile.
The rules from standalone NuGet packages can be enabled or disabled in the same way as the other analyzers based on Roslyn, by using the .globalconfig
or .editorconfig
files.
See: https://learn.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2022#set-rule-severity-in-an-editorconfig-file
If the rules are parameterized, the parameter values can be changed using SonarLint.xml
additional files.
The first step is to create a new file, named SonarLint.xml
, that has the following structure:
<?xml version="1.0" encoding="utf-8"?>
<AnalysisInput xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Settings>
<Setting>
<Key>sonar.cs.analyzeGeneratedCode</Key>
<Value>false</Value>
</Setting>
</Settings>
<Rules>
<Rule>
<Key>S107</Key>
<Parameters>
<Parameter>
<Key>max</Key>
<Value>2</Value>
</Parameter>
</Parameters>
</Rule>
</Rules>
</AnalysisInput>
Then, update the projects to include this additional file:
<ItemGroup>
<AdditionalFiles Include="SonarLint.xml" />
</ItemGroup>
If you believe you have discovered a security vulnerability in Sonar's products, please check this document
Copyright 2014-2024 SonarSource.
Licensed under the SONAR Source-Available License v1.0