-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update FxCop analyzers #4800
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
Update FxCop analyzers #4800
Conversation
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.
This is the only behavior change to use Ordinal by instead of the default current culture.
It is more inline with the usage of Contains, which defaults to Ordinal comparison here:
https://github.com/dotnet/wpf/blob/78e93de6c2450b4f7b1e3adb5a8b357ab8823d41/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs#L94
and here:
https://github.com/dotnet/wpf/blob/78e93de6c2450b4f7b1e3adb5a8b357ab8823d41/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs#L99
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.
Disable CA1062 because there are false positives, when a public method is invoking another method that already does the null check.
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.
@ThomasGoulet73 There are only two such cases where this warning is raised. Shall we suppress only for those two locations, instead of globally suppressing it?
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.
@dipeshmsft You're right, I thought about it more and I think we should enable it to make sure that we do null checks in the public method, even if there is a null check in a private method. This helps make sure that the argument name in the exception is the same as the public one, in case the argument name in the private method is not the same as the one in the public method. This additional check probably won't even be noticeable performance-wise.
I'll enable it in a separate commit and I'll leave the decision to the reviewers.
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.
This shouldn't be needed and it conflicts with other PackageReference when enabling analyzers in any other project than System.Xaml.
78e93de to
c350108
Compare
|
|
||
| public virtual XamlType GetXamlType(Type type) | ||
| { | ||
| if (type == null) |
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.
This one would succeed in XamlLanguage.TypeAlias(type) but throw in GetXamlType. By adding an explicit throw here, we make sure to throw early, with the right stacktrace and the right parameter name.
| /// </summary> | ||
| protected Exception GetConvertToException(object value, Type destinationType) | ||
| { | ||
| if (destinationType == null) |
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.
This one would already throw a NullReferenceException destinationType.FullName. By adding an explicit throw here, we make sure to throw early, with the right stacktrace and the right parameter name.
This one is technically a breaking change, the type of exception returned is not the same as before. Let me know if you would prefer to revert this change.
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.
Whilst this is a breaking change indeed, these types of changes have been generally considered acceptable across the .NET ecosystem.
https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/breaking-changes.md#bucket-2-reasonable-grey-area
c9bcb9b to
2d13716
Compare
Remove Microsoft.CodeAnalysis.Common to avoid dependency conflicts.
2d13716 to
6197678
Compare
Description
Update Microsoft.CodeAnalysis.FxCopAnalyzers to 3.3.1 and activate valid rules. The last version before the deprecated warning. I plan on doing a follow-up PR on chaning FxCopAnalyzers for NetAnalyzers.
Customer Impact
None, there are no behavior changes. Except here: #4800 (comment).
Regression
None.
Testing
Local build.
Risk
None.