SolvedStyleCopAnalyzers [Question] Is it possible to setup StyleCop analyzers from .editorconfig file?

Hello,
Is it possible to setup StyleCop analyzers with a .editorconfig file? Replacing the stylecop.json file?
Or is there any tool to have the same rules configured the same way in both files?
Regards

12 Answers

✔️Accepted Answer

It is not currently possible to use .editorconfig instead of stylecop.json. It would make sense to add this support as an option.

Other Answers:

@JadaVonRuth You only need to click on the light bulb and in Configure or Suppress Issues option then you can select Configure SAxxx severity, but you need VS 16.4 preview 1 or, if you have at least VS 16.4 preview 2, you can also right click on the warning/error in the Error List, and choose set severity from the context menu.

If you have an .editorconfig file the rule will be added to the existing one, if there is no .editorconfig a new one will be created next to the .sln file.

The naming convention is valid for every analyzers and is pretty
easy: dotnet_diagnostic.<RULE_CODE>.severity the RULE_CODE depends by analyzers and is the code that you can see in the Error List (for StyleCopAnalyzer is in the form of "SAxxx"), anyway it is better to add the rules using the light bulb or from the Error List instead of manually edit the .editorconfig because this way you have also a useful comment which describe the rule.

The rules in the file you linked are the rules built into Visual Studio and you need to go in Option -> Text Editor -> C# -> Code Style, from here you can export the configurations that you sets in General, Formatting and Naming by clicking Generate .editorconfig file from settings

Related Issues:

4
StyleCopAnalyzers [Question] Is it possible to setup StyleCop analyzers from .editorconfig file?
It is not currently possible to use .editorconfig instead of stylecop.json It would make sense to ad...