Skip to content

Respect code style option severity in ConvertSwitchStatementToExpress…#36087

Merged
mavasani merged 1 commit intodotnet:masterfrom
mavasani:Issue36086
May 31, 2019
Merged

Respect code style option severity in ConvertSwitchStatementToExpress…#36087
mavasani merged 1 commit intodotnet:masterfrom
mavasani:Issue36086

Conversation

@mavasani
Copy link
Copy Markdown
Contributor

…ionDiagnosticAnalyzer

Fixes #36086

@mavasani mavasani requested a review from a team May 31, 2019 14:45
@mavasani
Copy link
Copy Markdown
Contributor Author

Tag @alrz @CyrusNajmabadi

}

context.ReportDiagnostic(Diagnostic.Create(Descriptor,
context.ReportDiagnostic(DiagnosticHelper.Create(Descriptor,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if this is an optional arg, we should consider making mandatory, so that this can't happen.

Copy link
Copy Markdown
Contributor Author

@mavasani mavasani May 31, 2019

Choose a reason for hiding this comment

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

This is already a mandatory argument for DiagnosticHelper.Create API. The issue was the analyzer directly invoked the Diagnostic.Create public API, which is meant for all non-code style analyzers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah, got it. yeah... hrmm, i wonder if we should have an analyzer to catch usages of Diagnostic.Create!

}
}";
var warningOption = new CodeStyleOption<bool>(true, NotificationOption.Warning);
var options = Option(CSharpCodeStyleOptions.PreferSwitchExpression, warningOption);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can just say CodeStyleOptions.TrueWithSuggestionEnforcement then just validate you got a suggestion back.

using var workspace = CreateWorkspaceFromOptions(source, testParameters);
var diags = await GetDiagnosticsAsync(workspace, testParameters);
Assert.Single(diags);
Assert.Equal(DiagnosticSeverity.Warning, diags.First().Severity);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could just remove the line above and have this be diags.Single().Severity. But i don't care that much :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also, can we check if the diag ID is actually the one we expect here?

Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

Tiny nits/suggestions. Up to you on taking them. I would recommend future work to make this parameter non-optional.

Approve
Submit feedback approving these changes.

@mavasani
Copy link
Copy Markdown
Contributor Author

Tiny nits/suggestions. Up to you on taking them.

Thanks. I am going to do these as a follow-up change as we have a targeted snap for today and I want to ensure this change makes it in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE0066 (ConvertSwitchStatementToExpression) does not respect severity from CSharpCodeStyleOptions.PreferSwitchExpression

3 participants