roslyn: Cannot configure severity with editorconfig for analyzer diagnostics with Location.None
Version Used: Latest 16.3 dogfood preview build
Steps to Reproduce:
- Open attached ClassLibrary28.zip, which is a simple C# netstandard class library project with a ruleset with following contents to configure couple of CA diagnostics to errors:
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="MyRules" Description="MyRules" ToolsVersion="10.0">
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
<Rule Id="CA1014" Action="Error" /> <!-- Mark assemblies with CLSCompliant -->
<Rule Id="CA1040" Action="Error" /> <!-- Avoid empty interfaces -->
</Rules>
</RuleSet>
- Build project and verify 2 errors as expected:
- Now delete the ruleset from the project and replace it with the below equivalent editorconfig file (note can also use
[*.cs]
for the section header):
[*.*]
# CA1014: Mark assemblies with CLSCompliant
dotnet_diagnostic.CA1014.severity = error
# CA1040: Avoid empty interfaces
dotnet_diagnostic.CA1040.severity = error
- Rebuild project
Expected Behavior: 2 errors similar to behavior when ruleset was used
Actual Behavior:
Only one error for CA1040
CA1014 being a project level diagnostic with Location.None
doesn’t seem to be configurable from editorconfig file. This issue applies to all project level analyzer diagnostics, CA1014 is not special.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 30 (19 by maintainers)
What is the state of this problem? I justed startet migrating rulesets to editorconfig as “highly recommended” here: https://docs.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2019 I just used the conversion by VS. This changes CodeAnalysisRuleSet to MinimumRecommendedRules.ruleset.
Now CA1014 is no longer a warning and i’m unable to change this bei editorconfig. Maintaining ruleset and editorconfig is very confusing as you never know, which file is used for which rule.
This can’t be the right way…
I can’t understand how you could highly recommend something, which is working so bad.
@beho @ChrisTorng This is a known issue that will be addressed when @chsienki implements #48634 to allow user specified global config to override SDK/NuGet provided global config. Until that feature is implemented, you can workaround by disabling this rule in MSBuild props/project file:
I am going to re-open this issue so at least the consequences of Won’t fixing this can be understood and discussed at IDE design meeting. Also changing it to Area-IDE.
We cannot write a reliable migration tool to convert any given ruleset file into an equivalent editorconfig file, which has been requested and discussed few times with @jinujoseph @vatsalyaagrawal @mikadumont. Note that a ruleset file is independent of project context and is generally shared across multiple projects in a solution, so one cannot go from a pointed ruleset file to each applicable project and update it to add a /nowarn.
The existing Analyzers node’s “Set Rule Set Severity” functionality is being moved over to “Set severity” to instead update the editorconfig file with https://github.com/dotnet/roslyn/pull/37795. As the rule metadata does not indicate if it will produce no-location diagnostics, we cannot differentiate rules on when to add a configuration entry to editorconfig vs doing a /nowarn. Unfortunately, this would mean we cannot take that PR and would need to continue offering generating/editing ruleset files from Analyzers node for reliable configuration.
While attempting to manually update some existing project using ruleset to editorconfig, it took me considerable amount of debugging why some of the severity settings in editorconfig work and some don’t - was my syntax wrong? was some other editorconfig in my directory structure overriding it? was some other MSBuild property causing it not to be respected for some analyzer diagnostics? Explaining all this to customers would be much harder.
thx @sharwell ! It’s working 😃
@p-bojkowski The configuration needs to be placed in .globalconfig, which is the true functional replacement for a rule set file. This is like .editorconfig, except it has
is_global=true
(instead ofroot=true
) at the top, and it doesn’t have file grouping section headers like[*.cs]
.Hi,
when using
AllEnabledByDefault
(opt-out) analysis mode and trying to disableCA1014: Mark assemblies as CLSCompliant
(which is no-location diagnostic) I get following warning:So it seems that SDK-level globalconfig clashes with project-level one.
Am I missing something or there is no way to disable no-location warning without getting another one in opt-out mode?
Faced the same problem, workaround with global .editorconfig doesn’t work 😦 A workaround is to use
<NoWarn>
😦Above entry in your .editorconfig should suppress all IDE0062 for files and folders under that directory.
and analyzers do work, I mean, the roslyn analyzers.