roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

Cannot enable all disabled analyzers rules by default with `AllEnabledByDefault` setting

Open tuananh-le opened this issue 3 years ago • 4 comments

Product and Version Used: Roslynator.Analyzers Version="3.2.0" Roslynator.Formatting.Analyzers Version="1.2.0"

Steps to Reproduce:

  • Edit .csproj file and add <AnalysisMode>AllEnabledByDefault</AnalysisMode>

Actual Behavior: Disabled rules are not enabled by default. (It works for other .NET analyzers).

Expected Behavior: Enable all disabled rules by default

tuananh-le avatar Jun 15 '21 14:06 tuananh-le

@JosefPihrt : Is there a way that I can enable all the disabled rules at once using .editorConfig or sth? I don't want to have to specify one by one coz it's very time-consuming and if we update the package, we have to manually add these rules in. I want to enable all of them by default and then specifically disable some if I don't want them. Thanks.

tuananh-le avatar Jun 15 '21 15:06 tuananh-le

Hi,

my recommendation is to clone the repo and then run script tools/generate_default_ruleset.cmd. This will generate file default.editorconfig which contains all available analyzers and options in their default configuration. You can then edit the file according to your needs. If you want to enable all analyzers you can just apply some basic "find and replace" to set severities.

josefpihrt avatar Jun 15 '21 18:06 josefpihrt

@JosefPihrt : Thanks for your reply. Looks like that's the only option we have for now coz the <AnalysisMode>AllEnabledByDefault</AnalysisMode> setting does not work with Roslynator analysers for some reason. Please investigate this. Thanks.

tuananh-le avatar Jun 16 '21 00:06 tuananh-le

<AnalysisMode>AllEnabledByDefault</AnalysisMode> setting does not work with Roslynator analysers for some reason

In .NET 6+ AllEnabledByDefault should be All instead. But even with the change, this won't work because how <AnalysisMode> is implemented: <AnalysisMode> is read byMicrosoft.CodeAnalysis.NetAnalyzers.targets and it will include a pre-generated .globalconfig file to <EditorConfigFiles> that has all .NET's analyzer rules' severity set to warning.

Since Microsoft.CodeAnalysis.NetAnalyzers.targets obviously won't know about Roslynator rules, the globalconfig file added won't have roslynator rules. Thus all roslynator rules will remain in its default setting.

I think it would be possible for roslynator to maintain its own globalconfig that has all rules enabled, and update roslynator's .target file to add the globalconfig file to <EditorConfigFiles> when <AnalysisMode> is All.

You could also go one step further and support <AnalysisModeRoslynator> (the per-category variable) so that we can enable all roslynator rules without enabling all .NET CA rules.

jonathanou avatar Oct 20 '23 10:10 jonathanou