-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for respecting custom configured severity settings in editorconfig #52991
Comments
Tagging @jaredpar @chsienki from the compiler/editorconfig side. Jared/Chris - for context, we discussed this issue in last week's IDE design meeting and came up the conclusion of writing a proposal for the compiler feature request and then scheduling a quick sync-up meeting between all of us to get compiler team's opinion. I'll start an email thread and setup an appropriate meeting. |
Ah, forgot to tag @jasonmalinowski who did most of the IDE work for editorconfig support. |
I'd say to consider choosing a design that makes it easier in the future to allow third-party analyzers to use this syntax as well. |
@Youssef1313 Absolutely - my proposal above does not restrict this feature to any specific analyzer package. |
really like this proposal @mavasani |
We discussed this amongst the compiler and IDE teams and identified that the original proposal in this issue does not meet all requirements. Specifically, for naming style analyzers that use dynamically generated editorconfig key names for setting severity, analyzers cannot statically report all its supported editorconfig keys in its descriptor. We decided to go with @sharwell's proposal instead:
|
Implements the compiler/analyzer driver change from dotnet#52991 (comment) This flag indicates the minimum reported diagnostic severity for analyzer execution context. For command line builds, this will be warning, while for the IDE case this will be hidden. Analyzer diagnostics with severity lesser than this severity are not reported by the driver. This flag will allow the IDE code style analyzers to turn on/off in command line builds based on `option_name = option_value:severity` entries in editorconfig.
Adding a note to record that I ran into this issue: the compiler layer is currently not sufficiently enforcing naming convention on local functions. (here's most recent relevant change) |
API Review
Conclusion : Approved |
Won't supporting this syntax in the compiler represent a potential breaking change? Essentially customers today have If that analysis is correct then we need to think about an opt-in mechanism, probably tied to TFM, to enable this. Risky to be on by default. |
This is correct analysis. It seems fine to make this opt-in and tie it to say an MSBuild property that can be explicitly enabled by the user OR implicitly enabled with a minimum value of AnalysisLevel (TFM essentially). When enabled, we emit a special entry in our tooling generated globalconfig that passes MSBuild properties to analyzers, and have the CodeStyle analyzer package respect this option to turn on the new functionality. Does that sound like a reasonable approach? |
@jaredpar Please see draft PR #70727 for the recommended opt-in proposal for this feature via a new MSBuild property, |
The core idea is to define and thread in a new numeric `AnalysisLevel` value specific to IDE Code style, that gets passed to the analyzers to conditionally enable any new breaking change features, such as the one proposed in dotnet#52991. Currently, we support `AnalysisLevel` and per-category `AnalysisLevel{Category}` properties to determine the set of first party CA and IDE rules to enable by default: https://learn.microsoft.com/dotnet/core/project-sdk/msbuild-props#analysislevelcategory. This also includes `AnalysisLevelStyle` property for IDE CodeStyle analyzers, which already defaults to `AnalysisLevel`. However, this property can hold non-numeric well-known values such as `none`, `preview`, `latest` or compound values in the form `<version>-<mode>` (documented [here](https://learn.microsoft.com/dotnet/core/project-sdk/msbuild-props#analysislevel). This PR adds the below additional logic: 1. Add a new MSBuild 'EffectiveAnalysisLevelStyle' property, that contains a numeric value derived from `AnalysisLevelStyle` property, similar to the way we have `EffectiveAnalysisLevel` derived from `AnalysisLevel` property (see https://github.com/dotnet/sdk/blob/fcc367b2164e4b41b8fb6622110aeb9f3247dd92/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets#L35-L56). Note that the category specific logic added here (for 'Style' category) is identical to the existing logic in Microsoft.CodeAnalysis.NetAnalyzers.targets file for different CA analyzer categories that is generated by tooling and inserted into the .NET SDK: https://github.com/dotnet/roslyn-analyzers/blob/b924542a1b526322929725a1aaa9586c21b1b231/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs#L1528C62-L1553. 2. Mark this new 'EffectiveAnalysisLevelStyle' property as a `CompilerVisibileProperty` to pass it to the analyzers via analyzer config options. Note that this Target gets added to C# and VB CodeStyle targets file that is imported here: https://github.com/dotnet/sdk/blob/f52240f11ad291e6ee3cff86e83c0f7a21b60370/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets#L117-L120. I verified locally that `<%ProjectName%>.GeneratedMSBuildEditorConfig.editorconfig` generated by our tooling contains an entry with key `build_property.EffectiveAnalysisLevelStyle`.
Filed dotnet/docs#38540 to update docs for this support.
|
@mavasani What happens if there is a "conflict" in severity values? e.g, My understanding from the PR description is that Or am I misunderstanding something? |
@Youssef1313, yes we expect everyone to eventually use the code style option based syntax for value and severity configuration as that avoids the use of these opaque IDs for code styles. I assume we can write a simple analyzer to flag cases when we see conflicting entries like you mentioned above, but that needs support for reporting diagnostics in analyzer config files #64214 |
Yes, having such analyzer is going to be perfect. |
You marked this as duplicated and pointed us here. https://developercommunity.visualstudio.com/t/VS-2022-code-analysis-ignores-editorconf/10584696 I certainly can be missing something but I think what we are asking for (and worked prior) was the following With options that affect more than one rule (like dotnet_style_coalesce_expression), we wanted to turn on the option and turn off one of the rules. So we do what you said to do with But like IDE0029 and IDE0030 We want to turn off IDE0270 In the text in the linked issue it seemed to me to indicate we just need to move to but we are doing that. I don't see how to cherry pick turning off a given rule by only referencing option_name when a given option can cover more than one rule. If you do not intend to support this anymore, can you make that clear? Also, our point in the ticket was also we are seeing inconsistent behavior between inside the Visual Studio and command line building for this. Again. I can be missing something. Thank you for your help and guidance. |
@tfadler Thank you for the clarification of your query, and let me try to be more precise here.
|
Fixes dotnet#72094 Recently, as part of implementing support for dotnet#52991, we started respecting `option_name = option_value:severity` in build. As part of this change, if user has conflicting severity configurations from `option_name = option_value:severity` and `dotnet_diagnostic.IDExxxx.severity`, the former was given preference. We knew that this would likely break some customers, hence added functionality to guard this feature by enabling it only when AnalysisLevel was >= 9.0. However, that guard was only implemented for command line build path. This meant the feature was still being enabled by default in the IDE live analysis, which was unintentional. We now ensure that we respect the AnalysisLevel value even for this path and filter out CustomSeverityConfigurable custom tag for AnalysisLevel less than 9. As part of this change, I also identified a bug in the SDK targets: https://github.com/dotnet/sdk/blob/3075c3bc8d8aa4e0ffcf2945459ef2ee383e3ae0/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets#L117-L120 We shouldn't be conditioning the inclusion of CodeStyle targets file on `EnforceCodeStyleInBuild` as we want the target to execute even for live analysis for IDE analyzers shipping inside VS, not only when enabled on build. Fix to remove that condition is required to ensure we thread in AnalysisLevel property value to the analyzers. I will create a PR for the same.
Overview of the issue
Current IDE code style options support the following editorconfig syntax:
For example:
Command line compiler supports configuring severity of a specific diagnostic ID with the following editorconfig syntax:
This former syntax (
option_name = option_value:severity
) allows configuring both code style option value and severity. However, the severity setting from this syntax is only respected when executing the corresponding analyzer in the IDE live analysis. This syntax is not recognized by the command line compiler and/or the analyzer driver, so the severity setting above is redundant when executing from an explicit command line build. Additionally, with the command line compiler optimization implemented in #43546, we no longer execute hidden/suggestion analyzers in command line builds, unless the user has explicitly specified the analyzer diagnostic ID as a warning or error with thedotnet_diagnostic.RuleID.severity = severity
syntax. All IDE code style rules are hidden or suggestions by default. This essentially means that the only way to enforce an IDE code style rule on command line build from our CodeStyle NuGet package is by using the latter compiler recognized syntax.#44201 suggested tackling this issue by deprecating the
:severity
suffix inoption_name = option_value:severity
syntax. However, there has been customer pushback on this as almost all existing editorconfigs out there which have IDE code style option entries use:severity
. Note that:severity
suffix was mandatory in this syntax up until the end of the last year, when we made it optional. This presents another case that uses will face a hard time figuring out why IDE code style option entries that specify:warning
or:error
doesn't cause them to be executed on command line builds.Original implementation proposal
The feature request here is for the compiler/analyzer driver to support decoding the
:severity
suffix in editorconfig entries with formatoption_name = option_value:severity
. Additionally, the compiler will need to add some new API/mechanism for diagnostic analyzers to specify a mapping from its supportedoption_names
to diagnostic ID. There are two possible ways that come to my mind for this:DiagnosticDescriptor
constructor that take astring[] optionNames
orImmutableArray<string> optionNames
parameter, and the analyzer driver can create aoption_name <-> diagnosticId
mappingcustomTags
parameter on theDiagnosticDescriptor
ctors to have a special format to specify supported option names, sayoption_names = name1;name2;name3
Latest implementation proposal
See comment below: #52991 (comment)
Public API proposal corresponding to the latest implementation proposal
See comment below: #52991 (comment)
The text was updated successfully, but these errors were encountered: