Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set action as error for all stylecop rules

Tags:

c#

stylecop

We are using StyleCop Analyzers in a C# project. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers) The problem is how to set all action to "Error" instead of "Warning" about both rules code analysis(CAXXXX) and style analysis(SAXXXX). Obviously I could list all rules like:

<Rule Id="CAXXXX" Action="Error" />
<Rule Id="SAXXXX" Action="Error" />

But that is inconvenient. Is there any other way to set it ?

The project used stylecop and set propertyGroup:

<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>

to set action as error. But that does not work in the new tool, stylecop analyzers.

like image 726
ihere1 Avatar asked Nov 30 '15 03:11

ihere1


People also ask

How do you change rules on StyleCop?

In your StyleCop install, there's a Settings. StyleCop file. You can edit this to turn off rules globally. Drag that file onto the Settings Editor executable in that file to edit it.

Is StyleCop still used?

StyleCop used to be a Visual Studio plugin and a NuGet package. You can still use this in Visual Studio 2019, but the current recommended way to use StyleCop is to use the Roslyn-based analyzers.


2 Answers

A quicker way to do this is:

On Analyzers, click Active Ruleset:

enter image description here

Giving something akin to:

enter image description here

Select them all:

enter image description here

Then click on any "Warning" and select "Error":

enter image description here

Then they are all set to "Error":

enter image description here

like image 125
NikolaiDante Avatar answered Nov 17 '22 01:11

NikolaiDante


To set all code analysis rules to have an Error action by default, the following can be added to a property group in the .csproj file:

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

This worked for both Microsoft.CodeAnalysis.FxCopAnalyzers and StyleCop.Analyzers packages added to a .NET Core 2.1 project.

like image 30
Tim Avatar answered Nov 16 '22 23:11

Tim