Skip to content

Commit

Permalink
Updated documentation to reflect the latest changes (#7821)
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource authored Aug 22, 2023
1 parent 8cdbbd3 commit 94dde8e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,40 @@ The easiest way is to configure a Quality Profile in SonarCloud.

### Standalone NuGet

Standalone NuGet packages can be configured the same way as SonarLint in connected mode. You can use SonarLint and SonarCloud to generate the ruleset and rule configuration file SonarLint.xml as described above and embed them into your project.

You can see how we do it in our own repository for SonarLint Connected mode (and you can reuse the same concept for the NuGet package):

* We reference in each production-code project this [Directory.Build.targets](analyzers/src/Directory.Build.targets).
* This file points to the following ruleset: [sonaranalyzer-dotnetCSharp.ruleset](analyzers/.sonarlint/sonaranalyzer-dotnetCSharp.ruleset).
* And the following [SonarLint.xml](analyzers/.sonarlint/sonaranalyzer-dotnet/CSharp/SonarLint.xml).
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.

First step is to create a new file, named `SonarLint.xml`, that has the following structure:
```xml
<?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:
```xml
<ItemGroup>
<AdditionalFiles Include="SonarLint.xml" />
</ItemGroup>
```

## Internal resources

Expand Down
1 change: 1 addition & 0 deletions analyzers/SonarAnalyzer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common Solution Items", "Co
src\Signing.cs = src\Signing.cs
packaging\SonarAnalyzer.CSharp.nuspec = packaging\SonarAnalyzer.CSharp.nuspec
packaging\SonarAnalyzer.VisualBasic.nuspec = packaging\SonarAnalyzer.VisualBasic.nuspec
..\README.md = ..\README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B7233F78-E142-4882-B084-7C83BE472109}"
Expand Down

0 comments on commit 94dde8e

Please sign in to comment.