Skip to content

/warnaserror-:DiagnosticId should not nullify editorconfig diagnostic…#49449

Merged
mavasani merged 3 commits intodotnet:masterfrom
mavasani:FixWarnAsErrorMinus
Nov 24, 2020
Merged

/warnaserror-:DiagnosticId should not nullify editorconfig diagnostic…#49449
mavasani merged 3 commits intodotnet:masterfrom
mavasani:FixWarnAsErrorMinus

Conversation

@mavasani
Copy link
Contributor

… settings for DiagnosticId

Fixes #49446

@mavasani mavasani added this to the 16.9 milestone Nov 17, 2020
@mavasani mavasani requested review from a team and chsienki November 17, 2020 21:38
@mavasani
Copy link
Contributor Author

@dotnet/roslyn-compiler for second review.

1 similar comment
@mavasani
Copy link
Contributor Author

@dotnet/roslyn-compiler for second review.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 23, 2020

            if (tree != null && syntaxTreeOptions.TryGetDiagnosticValue(tree, id, cancellationToken, out report) ||

It looks like we are overriding the report value unconditionally. It feels like that can lead to a loss of the value we got from specificDiagnosticOptions. Are we testing scenarios like that? I think it would be better to extract config setting into a separate variable and then have an explicit logic to merge both values. #Closed


Refers to: src/Compilers/CSharp/Portable/Compilation/CSharpDiagnosticFilter.cs:201 in 23dbaaa. [](commit_id = 23dbaaa, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

            if (tree != null && syntaxTreeOptions.TryGetDiagnosticValue(tree, id, cancellationToken, out report) ||

For example, it is not obvious if we can switch to ReportDiagnostic.Error and whether that would be the right thing to do.


In reply to: 732285025 [](ancestors = 732285025)


Refers to: src/Compilers/CSharp/Portable/Compilation/CSharpDiagnosticFilter.cs:201 in 23dbaaa. [](commit_id = 23dbaaa, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 23, 2020

Done with review pass (iteration 1) #Closed

@mavasani
Copy link
Contributor Author

            if (tree != null && syntaxTreeOptions.TryGetDiagnosticValue(tree, id, cancellationToken, out report) ||

It looks like we are overriding the report value unconditionally. It feels like that can lead to a loss of the value we got from specificDiagnosticOptions. Are we testing scenarios like that? I think it would be better to extract config setting into a separate variable and then have an explicit logic to merge both values.

Refers to: src/Compilers/CSharp/Portable/Compilation/CSharpDiagnosticFilter.cs:201 in 23dbaaa. [](commit_id = 23dbaaa, deletion_comment = False)

Thanks, I can refactor so we don't explicitly rely on the behavior of TryGetDiagnosticValue to set value to ReportDiagnostic.Default on false return case below:

public override bool TryGetDiagnosticValue(SyntaxTree tree, string diagnosticId, CancellationToken _, out ReportDiagnostic severity)
{
if (_options.TryGetValue(tree, out var value))
{
return value.DiagnosticOptions.TryGetValue(diagnosticId, out severity);
}
severity = ReportDiagnostic.Default;
return false;
}

Note that this is already tested via an existing test which passes /warnaserror- without any syntax tree options, so there is no need to add a new test, but your suggested refactoring will make this more explicit.

@AlekseyTs
Copy link
Contributor

, I can refactor so we don't explicitly rely on the behavior of TryGetDiagnosticValue to set value to ReportDiagnostic.Default on false return case

Note, this isn't the only case I am concerned about. It is not clear to me why it would be fine to read ReportDiagnostic.Error from config in our case.


In reply to: 732298342 [](ancestors = 732298342)

@AlekseyTs
Copy link
Contributor

Note that this is already tested via an existing test which passes /warnaserror- without any syntax tree options, so there is no need to add a new test, but your suggested refactoring will make this more explicit.

I am referring to other values that might come from config, not just lack of a value.


In reply to: 732304230 [](ancestors = 732304230,732298342)

@mavasani
Copy link
Contributor Author

, I can refactor so we don't explicitly rely on the behavior of TryGetDiagnosticValue to set value to ReportDiagnostic.Default on false return case

Note, this isn't the only case I am concerned about. It is not clear to me why it would be fine to read ReportDiagnostic.Error from config in our case.

In reply to: 732298342 [](ancestors = 732298342)

Maybe I am not clear about the exact scenarios that you are concerned about. The logic works as follows:

  1. If SpecificDiagnosticOptions has a value other than ReportDiagnostic.Default, it overrides syntax tree options from config files and determines diagnostic's effective severity. Syntax tree options from config files are ignored.
  2. Otherwise, if config file options contains a value for an ID, that overrides and determines diagnostic's reported severity. This is true even if SpecificDiagnosticOptions has a ReportDiagnostic.Default from /warnaserror-:ID. /warnaserror- cannot nullify an explicit entry from config file (even ReportDiagnostic.Error), it can only nullify a previous /warnaserror+ specification indicating a warning being bumped to an error.
  3. If after all the above handling, diagnostic's effective severity is a warning and /warnaserror+ is applicable for the ID, it will be bumped to an error.

I can add more tests to assert this behavior.

@AlekseyTs
Copy link
Contributor

It is not obvious to me why it is desired to override /warnaserror-:ID from command line with /warnaserror:ID from config. Since you didn't test this scenario, I couldn't tell what the expectations should be


In reply to: 732320103 [](ancestors = 732320103)

@mavasani
Copy link
Contributor Author

It is not obvious to me why it is desired to override /warnaserror-:ID from command line with /warnaserror:ID from config. Since you didn't test this scenario, I couldn't tell what the expectations should be

Sounds good - I don't have a push back to change the semantics so /warnaserror-:ID from command line will override ReportDiagnostic.Error from config for warning diagnostics. IMO, these are conflicting configurations, so pretty unlikely, but your stance seems reasonable. I'll make this adjustment and add tests.

… from bumping a warning to an error.

Verified that the new test fails for the case `[InlineData(warnAsErrorMinus: true, defaultSeverity: DiagnosticSeverity.Warning, severityInConfigFile: DiagnosticSeverity.Error, expectedEffectiveSeverity: DiagnosticSeverity.Warning)]` prior to the product fix in this commit, as actual effective severity was an error. This is fixed with commit.
// Verify '/warnaserror-:ID' has no effect when default severity is 'Info' and config file bumps severity to 'Error'
[InlineData(false, DiagnosticSeverity.Info, DiagnosticSeverity.Error, DiagnosticSeverity.Error)]
[InlineData(true, DiagnosticSeverity.Info, DiagnosticSeverity.Error, DiagnosticSeverity.Error)]
public void TestWarnAsErrorMinusDoesNotNullifyEditorConfig(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AlekseyTs Please let me know if you feel there are more combinations that would be worth testing.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 3)

@mavasani
Copy link
Contributor Author

Thanks!

@mavasani mavasani merged commit c536d5b into dotnet:master Nov 24, 2020
@ghost ghost modified the milestones: 16.9, Next Nov 24, 2020
@mavasani mavasani deleted the FixWarnAsErrorMinus branch November 24, 2020 17:52
@dibarbet dibarbet removed this from the Next milestone Dec 19, 2020
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.

'/warnaserror-:DiagnosticId' should not nullify diagnostic severity settings for 'DiagnosticId' in editorconfig

4 participants