-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Don't report diagnostics if code-style option is disabled #62497
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
base: main
Are you sure you want to change the base?
Conversation
| /// <param name="messageArgs">Arguments to the message of the diagnostic.</param> | ||
| /// <returns>The <see cref="Diagnostic"/> instance.</returns> | ||
| public static Diagnostic Create( | ||
| public static DiagnosticWrapper Create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a new wrapper type? Can't we nullable enable all the calling code and have this method return Diagnostic??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mavasani All analyzers will have to do the null check. I wanted to minimize changes to analyzers.
And an extension method named ReportDiagnostic will not picked up unless the parameter type is different (the compiler will prefer the existing ReportDiagnostic over the extension)
And Adding an extension with a new name will lead to updates in all analyzers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, so we are basically trading off the cleanest API to avoid making tons of changes in the code base. That seems reasonable to me, but I'll let others in @dotnet/roslyn-analysis share their views.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meant to tag @dotnet/roslyn-ide
| /// </param> | ||
| /// <param name="message">Localizable message for the diagnostic.</param> | ||
| /// <returns>The <see cref="Diagnostic"/> instance.</returns> | ||
| public static Diagnostic CreateWithMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still unsure if removing this overload and LocalizableStringWithArguments is required for this PR. Can you clarify why it is being done here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocalizableStringWithArguments was originally introduced to support option = value:none. Since this PR introduces a new way to support none, the type is no longer needed.
This has also caught extra period in analyzer messages.
| var diagnostic = DiagnosticHelper.CreateWithMessage(s_unusedParameterRule, location, | ||
| option.Notification.Severity, additionalLocations: null, properties: null, message); | ||
| reportDiagnostic(diagnostic); | ||
| var diagnostic = DiagnosticHelper.Create(rule, location, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be much cleaner to rename this method to TryCreate and have it return a Diagnostic?. Also you can easily avoid the null check at each callsite by having a helper TryCreateAndReport(..., reportDiagnostic).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mavasani My intent was to avoid too many changes to analyzers.
|
Converting to a draft, I'm thinking of a larger refactoring which (if accepted) might make this change easier. Note to self (just in case I forgot what I have in mind 😄):
The new If we have now our own analysis contexts that delegate to the compiler, we could simply allow a null diagnostic. The design above has a flaw for analyzers with multiple options, but hopefully it won't be too hard to figure out a good way for these analyzers. |
|
Marking as ready for review again. The refactoring I described in previous comment isn't going well.. :( |
Replaces #62150
Previously, we report diagnostics with
IsSuppressedif the code-style option is disabled. The use ofIsSuppressedin this case is suspicious, this property is related to source (attribute/pragma) suppressions. If code-style option is disabled, no diagnostic should be reported.@mavasani for review
Core changes are in
DiagnosticHelper.cs