Roslyn: Ruleset is still needed with .editorconfig to enable disabled rules

Created on 10 Feb 2020  路  6Comments  路  Source: dotnet/roslyn

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

v2.9.8 (Latest)

Issue

There are several analyzers (e.g. CA1725) which are disabled by default. This means i need a ruleset file to enable them to some random severity, after which i can set the severity in the .editorconfig file (if i want to, the same as with all the others). Would it be possible to switch all the analyzers to "enabled by default = true" but set the default severity of the ones you don't want by default to "none"? That way i could simply enable (or disable) them by setting the severity in .editorconfig, as with all the others

Area-IDE Bug

Most helpful comment

Ah, this was actually fixed by #40488. I verified this does not repro with the latest VS2019 preview: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview

All 6 comments

I never paid attention that setting the severity in the .editorconfig wasn't changing the activation state. I do think this is an interesting feature.

It's probably more an issue for the roslyn repo though.

This was fixed by https://github.com/dotnet/roslyn/pull/38792 (Visual Studio 2019 version 16.4)

Hum I have created a console app with the following code:

public interface IBase
{
    void TestMethod(string baseArg1, string baseArg2);
}

public class TestClass : IBase
{
    public void TestMethod(string arg1, string arg2) { }
}

I have added the .editorconfig and I have added dotnet_diagnostic.CA1725.severity = error but I don't have any error raised.

I confirmed that CA1725 is enabled with the .editorconfig entry in command line build, but not in the IDE analyzer execution. So, doing an explicit build will generate the diagnostics, but not from live analysis. I believe this has regressed in the IDE layer as I had verified this scenario when validation https://github.com/dotnet/roslyn/pull/38792.

@sharwell Can you please port this issue to Roslyn repo and assign it to me?

We should also file a separate feature request in Roslyn repo for the following:

Would it be possible to switch all the analyzers to "enabled by default = true" but set the default severity of the ones you don't want by default to "none"? That way i could simply enable (or disable) them by setting the severity in .editorconfig, as with all the others

Users can use the feature enabled in https://github.com/dotnet/roslyn/pull/38886#issue-321838740 to disable all analyzer diagnostics by default, and then enable each analyzer by rule ID specific entry. However, there is no support for enabling every rule in the package that was disabled by default. I think it seems reasonable to allow user to state dotnet_analyzer_diagnostic.enabled_by_default = true | false OR dotnet_analyzer_diagnostic.category-{category}.enabled_by_default = true | false

Thanks to all of you for the investigations and explanations. I created the issue in roslyn-analyzers because i thought this behavior in Roslyn was by design (sorry for that).

I agree with @mavasani 's last point, it would be nice to be able to simply enable the analyzers and keep their default severity

Ah, this was actually fixed by #40488. I verified this does not repro with the latest VS2019 preview: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview

Was this page helpful?
0 / 5 - 0 ratings