Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the wiki #6383

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 43 additions & 36 deletions docs/wiki.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
# Wiki

## Overview
We’ve rebuilt the most popular 100+ FxCop rules as live analyzers to help you detect problems in your code and make it super easy for you to fix them on the spot with quick fixes. Installing the NuGet or Extension gives you the same great code analysis as before with FXCop but now the analysis is live as-you-type and has quick-fixes.

## Install Instructions
You can download the FXCop live code analyzers as a [NuGet package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/) or as a Visual Studio extension ([VS2017](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MicrosoftCodeAnalysis2017) or [VS2019](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MicrosoftCodeAnalysis2019)).
We've rebuilt the most popular FxCop rules and additional more rules as live analyzers to help you detect problems in your code and make it super easy for you to fix them on the spot with quick fixes. You can get the analyzers via [`Microsoft.CodeAnalysis.NetAnalyzers` NuGet package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers) or from the .NET SDK. This gives you the same great code analysis as before with FXCop but now the analysis is live as-you-type and has quick-fixes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid mentioning specific NuGet package, or .NET SDK or any acquisition modes here and instead just add a help link to https://learn.microsoft.com/dotnet/fundamentals/code-analysis/overview?tabs=net-7 which has all the relevant information.


## Apply a Code Fix for a Rule
Place your cursor in the span of the squiggle/dotted line and press `Ctrl+.` to trigger the lightbulb menu. From the lightbulb, you will see all available quick actions.
> Note: not all 100 code analysis rules in this extension have fixes associated with them.
## Install instructions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I think we should avoid repeating Install related information in our wiki as it is already covered in .NET code analysis docs.


<img src="https://github.com/dotnet/roslyn-analyzers/blob/main/docs/MakeStatic.PNG">
You can get the analyzers from NuGet package, from the .NET SDK, or from Visual Studio extension (deprecated in VS 2022).

## Configure a Rule (Enable, Disable, Suppress, Baseline)
* **Configure a rule on/off and change severity** – in the Solution Explorer, navigate to the "References" node under your project. Right-click on the Analyzers sub-node and select "Open Active Rule Set". Using the GUI, you can set the severity of any rule to "None", "Info", "Warning", or "Error". Note: If you have a .NET Core project, you must manually add a file name “ProjectName.ruleset”.
* **Suppress a rule** – place your cursor inside the span of the squiggle and press “Ctrl+.” to trigger the lightbulb menu. From there you should see the option to Suppress in file (via #pragma) or via a global Suppression file. Alternatively, you can go to the Error List and right-click to suppress.
* **Bulk-suppression / Baselining** – To suppress all active issues, you can select all issues in the Error List, right-click, and navigate to “Suppress” or you can right-click on your project in the Solution Explorer and navigate to Analyze > Run Code Analysis and Suppress Active Issues.
### NuGet package

<img src = "https://github.com/dotnet/roslyn-analyzers/blob/main/docs/SuppressErrorList.PNG">
To get the analyzers from the NuGet package, you need to add the package in your `csproj` or `Directory.Build.props` in an `ItemGroup` as follows:

## Severity Levels for Analyzers
* **None** – rule violations at this severity level will not have a visual adornment in the editor nor appear in the Error List/scroll bar.
* **Suggestion** – rule violations at this severity level will be adorned with a gray, dotted line and will appear as "Messages" in the Error List and gray boxes in the scroll bar.
* **Warning** – rule violations at this severity level will be adorned with a green, squiggly line and will appear as "Warnings" in the Error List and green boxes in the scroll bar.
* **Error** – rule violations at this severity level will be adorned with a red, squiggly line and will appear as "Errors" in the Error List and red boxes in the scroll bar.

## FAQ
* **Why am I only seeing rule violations in open files rather than my entire solution?**
```xml
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="PackageVersionGoesHere" PrivateAssets="all" />
```

This is because "Full Solution Analysis" is off by default. To turn on live code analysis for your entire solution, go to Tools>Options>Text Editor> [C# | Basic] > Advanced > Enable full solution analysis.
### .NET SDK

* **Do I need a .ruleset file in every project?**
Starting in .NET 5, these analyzers are included with the .NET SDK. If your project targets .NET 5 or later, code analysis is enabled by default. If your project targets a different .NET implementation, for example, .NET Core, .NET Standard, or .NET Framework, you must manually enable code analysis by setting the [EnableNETAnalyzers](https://learn.microsoft.com/dotnet/core/project-sdk/msbuild-props#enablenetanalyzers) property to `true`.

Yes. Ruleset files work on a per-project basis. When we move to EditorConfig, the configuration file will apply at the directory-level.
### Visual Studio extension (VSIX) (deprecated)

* **How do I report issues/bugs I find? How do I report a false-positive?**
You can also get the analyzers as a Visual Studio extension ([VS2017](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MicrosoftCodeAnalysis2017) or [VS2019](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MicrosoftCodeAnalysis2019)). This is deprecated in VS 2022.

## Apply a code fix for a rule

Place your cursor in the span of the squiggle/dotted line and press `Ctrl+.` to trigger the lightbulb menu. From the lightbulb, you will see all available quick actions.
Copy link
Member

@mavasani mavasani Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid all the text here and instead just add a help link to https://learn.microsoft.com/visualstudio/ide/quick-actions


Please file any issues/bugs on our GitHub repository [dotnet/roslyn-analyzers](https://github.com/dotnet/roslyn-analyzers/issues).
> Note: not all code analysis rules have fixes associated with them.

* **Does this work with EditorConfig?**
![make static codefix image](MakeStatic.PNG)

Not yet. The plan is to use EditorConfig going forward rather than .ruleset files.
## Configure a rule

* **What is the difference between this extension and the NuGet package? How do I get the NuGet package?**
- **Change a rule severity**: In a [configuration file](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-files), add `dotnet_diagnostic.<rule_id>.severity = <severity>`. For more information, see [How to suppress code analysis warnings](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/suppress-warnings) and [Configuration options for code analysis](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-options).
- **Suppress a rule** – place your cursor inside the span of the squiggle and press `Ctrl+.` to trigger the lightbulb menu. From there you should see the option to Suppress in file (via #pragma) or via a global Suppression file. Alternatively, you can go to the Error List and right-click to suppress.
- **Bulk-suppression / Baselining** – To suppress all active issues, you can select all issues in the Error List, right-click, and navigate to “Suppress” or you can right-click on your project in the Solution Explorer and navigate to Analyze > Run Code Analysis and Suppress Active Issues.

![Suppress via error list](SuppressErrorList.PNG)

## Severity levels for analyzers

- `none` – rule violations at this severity level will not have a visual adornment in the editor nor appear in the Error List/scroll bar.
- `suggestion` – rule violations at this severity level will be adorned with a gray, dotted line and will appear as "Messages" in the Error List and gray boxes in the scroll bar.
- `warning` – rule violations at this severity level will be adorned with a green, squiggly line and will appear as "Warnings" in the Error List and green boxes in the scroll bar.
- `error` – rule violations at this severity level will be adorned with a red, squiggly line and will appear as "Errors" in the Error List and red boxes in the scroll bar.

## FAQ

There is no difference in the rules, just in how they function. An extension applies at the solution-level while a NuGet works at the project-level. Also, if you have a NuGet package installed, rule violations at the Error severity level will break your build.
- **Why am I only seeing rule violations in open files rather than my entire solution?**

You can get the NuGet package for these rules on [NuGet.org](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/).
This is because "Full Solution Analysis" is off by default. To turn on live code analysis for your entire solution, go to Tools>Options>Text Editor> [C# | Visual Basic] > Advanced > Enable full solution analysis.

* **Can I contribute analyzers and fixers to this repo?**
- **How do I report issues/bugs I find? How do I report a false-positive?**

YES! Create an issue with the rule/fix you want to contribute and we’ll help you get started.
Please file any issues/bugs on our GitHub repository [dotnet/roslyn-analyzers](https://github.com/dotnet/roslyn-analyzers/issues).

* **Why am I not seeing errors when I build on the command-line?**
- **Does this work with EditorConfig?**

Extensions cannot affect your build. To have these rules enforced on your command-line or CI builds, please install our equivalent NuGet package on [NuGet.org](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/).
Yes. `.editorconfig` files are supported along with `.globalconfig` files. For more information, see [Configuration files for code analysis rules](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-files).

* **I'm seeing too many errors at different severities than I had configured? What's happening?**
- **Can I contribute analyzers and fixers to this repo?**

You may have both the NuGet package and the Extension for Microsoft Code Analysis installed. Right now, this is a known issue and we have a design to fix this scenario.
YES! Create an issue with the rule/fix you want to contribute and we'll help you get started.