Skip to content

Conversation

@ThomasGoulet73
Copy link
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Jul 6, 2021

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.

@ThomasGoulet73 ThomasGoulet73 requested a review from a team as a code owner July 6, 2021 04:11
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jul 6, 2021
@ghost ghost requested review from SamBent, fabiant3 and ryalanms July 6, 2021 04:11
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

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 shouldn't be needed and it conflicts with other PackageReference when enabling analyzers in any other project than System.Xaml.


public virtual XamlType GetXamlType(Type type)
{
if (type == null)
Copy link
Contributor Author

@ThomasGoulet73 ThomasGoulet73 Jul 29, 2021

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)
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 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.

Copy link
Contributor

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

@singhashish-wpf singhashish-wpf merged commit ad2c221 into dotnet:main Sep 29, 2021
@ThomasGoulet73 ThomasGoulet73 deleted the analyzers-update branch October 27, 2021 20:32
@ghost ghost locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Community Test Pass PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants