Skip to content
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

Ensure that warnaserror works identically for warnings configured in … #47710

Merged
1 commit merged into from
Sep 25, 2020

Conversation

mavasani
Copy link
Contributor

…ruleset and global config

  1. Fixes TreatWarningsAsErrors ignored when severity set in EditorConfig #43051
  2. Ensures consistent behavior between ruleset and global config. Before the product change in this PR, the added unit tests pass for ruleset scenario, but fails for global config, confirming the inconsistency.

This change enables users to migrate away from rulesets when they desire to have rules configured as warnings by default and bump it to errors in CI with warnaserror. They cannot do this via editorconfig as diagnostic severity settings in editorconfig always override command line options (nowarn and warnaserror).

…ruleset and global config

1. Fixes dotnet#43051
2. Ensures consistent behavior between ruleset and global config

Enables users to migrate away from rulesets when they desire to have rules configured as warnings by default and bump it to errors in CI with warnaserror. They cannot do this via editorconfig settings as editorconfig always overrides command line options (nowarn and warnaserror).
@mavasani
Copy link
Contributor Author

Thanks @chsienki!

@dotnet/roslyn-compiler for an additional review.

@@ -196,6 +196,12 @@ internal static class CSharpDiagnosticFilter
{
// 4. Global analyzer config level
isSpecified = true;

// '/warnaserror' should promote warnings configured in global analyzer config to error.
if (report == ReportDiagnostic.Warn && generalDiagnosticOption == ReportDiagnostic.Error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only consider generalDiagnosticOption in this particular if block? Why not the others essentially?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to the fact that global configs are lazily parsed, while rulesets are parsed upfront by the command line parser.

  1. Rulesets are parsed before parsing /warnaserror command line arguments: http://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/CommandLine/CSharpCommandLineParser.cs,158
  2. When parsing /warnaserror on command line, options from rulesets are directly bumped to errors in place: http://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/CommandLine/CSharpCommandLineParser.cs,828

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, we can consider implementing a similar fix for settings in editorconfig files, i.e. if you specify dotnet_diagnostic.RuleId.severity = warning in an editorconfig and execute with /warnaserror, then the diagnostic gets promoted to error - that does seem more sensible behavior as /warnaserror should ideally imply one does not see any warnings, but only errors (unless of course users have a /warnaserror-:RuleId for specific rules). Customers are also requesting the fix to editorconfig behavior in #43051, but there is potential of that being a more visible breaking change for existing users as editorconfig support in compiler has been shipped for a while. We have 2 options:

  1. Avoid breaking change for editorconfig settings, and ask users to instead switch to global config if they desire /warnaserror to bump user configured warnings to errors. The approach taken currently in this PR.
  2. Make the more correct fix of doing this change for both editorconfig and global config settings, at the risk of breaking some customers who have configured warnings in editorconfig files and run with /warnaserror. This would be a simple change to make in this PR if we are comfortable with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we document what the precedence level is between all of the various options here? I was a bit surprised at first glance to see that the test verifies that the command line essentially overrides the config files. Likely my intuition is just off here. But wanted to find a full list of "A wins over B" so I could consider what other tests we may need here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have #47154 tracking adding this documentation.

Copy link
Contributor Author

@mavasani mavasani Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaredpar @chsienki I plan to add the precedence level documentation tracked in #47154 to docs.microsoft.com later today.

However, the open question in my above comment #47710 (comment) still needs to be answered to define this order wrt to command line options: do we believe that command line options (/nowarn and /warnaserror) should always override diagnostic settings from all of the other sources (editorconfig, global config and rulesets)? I think that should be the case, as shown by the scenarios in #43051.

This PR ensures these semantics for global configs. I can create a follow-up PR for ensuring the same semantics for editorconfigs, if we feel it is a reasonable behavior change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaredpar Do you feel scheduling a meeting for discussing this would be preferrable? Also, should this PR be retargeted to 16.8 release branch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I just lost track of this.

@mavasani mavasani changed the base branch from master to release/dev16.8 September 24, 2020 20:58
@ghost
Copy link

ghost commented Sep 24, 2020

Hello @mavasani!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approval

@ghost
Copy link

ghost commented Sep 24, 2020

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. Azure Pipelines

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

1 similar comment
@ghost
Copy link

ghost commented Sep 24, 2020

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. Azure Pipelines

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TreatWarningsAsErrors ignored when severity set in EditorConfig
4 participants