Skip to content

Conversation

@MartyIX
Copy link

@MartyIX MartyIX commented Aug 15, 2021

Fixes #5372

@codecov
Copy link

codecov bot commented Aug 15, 2021

Codecov Report

Merging #5374 (1f825aa) into main (664f3d5) will decrease coverage by 0.10%.
The diff coverage is 99.75%.

@@            Coverage Diff             @@
##             main    #5374      +/-   ##
==========================================
- Coverage   95.60%   95.49%   -0.11%     
==========================================
  Files        1200     1213      +13     
  Lines      276353   276401      +48     
  Branches    16633    16709      +76     
==========================================
- Hits       264196   263946     -250     
- Misses       9980    10263     +283     
- Partials     2177     2192      +15     

@MartyIX
Copy link
Author

MartyIX commented Aug 17, 2021

@Youssef1313 Would you mind having a look?

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

Please open an issue for dotnet/docs to update the documentation when this PR is merged and a new version is released.

@MartyIX MartyIX marked this pull request as ready for review August 17, 2021 12:03
@MartyIX MartyIX requested a review from a team as a code owner August 17, 2021 12:03
@MartyIX
Copy link
Author

MartyIX commented Aug 17, 2021

Thank you!

@MartyIX
Copy link
Author

MartyIX commented Aug 23, 2021

@sharwell Gentle ping. Can a buddy be assigned here? :-)

@Youssef1313
Copy link
Member

@buyaa-n @jeffhandley Would you be the correct one to review this?

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

The logic looks good to me. I added a couple of syntax nit comments. Beyond that, I'd like to see more test cases added to cover conditions of:

  1. methodsWithSameNameAsTargetMethod.HasMoreThan(1) being true and false
  2. With overloads that do and don't match the desired parameters
  3. And overloads where the last parameter is and is not IFormatProvider, ensuring we hit each of the correctPOverloads.FirstOrDefault() possibilities
  4. Where targetMethod.ReturnType is and is not a string
  5. Where the symbol does and does not match one of the ...UICultureProperty properties

After that, I recommend getting a review from @sharwell or @jmarolf before we accept it.


IEnumerable<IMethodSymbol> methodsWithSameNameAsTargetMethod = targetMethod.ContainingType.GetMembers(targetMethod.Name).OfType<IMethodSymbol>().WhereMethodDoesNotContainAttribute(obsoleteAttributeType).ToList();
if (methodsWithSameNameAsTargetMethod.HasMoreThan(1))
{
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this set of braces can be removed

Copy link
Author

Choose a reason for hiding this comment

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

Interestingly, it looks like Github moved your comments to different line numbers.

#region "UICultureStringRule & UICultureRule"
IEnumerable<int> IformatProviderParameterIndices = GetIndexesOfParameterType(targetMethod, iformatProviderType);
foreach (var index in IformatProviderParameterIndices)
{
Copy link
Member

Choose a reason for hiding this comment

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

It looks like these braces can be removed.

// Sample message for IFormatProviderAlternateRule: Because the behavior of Convert.ToInt64(string) could vary based on the current user's locale settings,
// replace this call in IFormatProviderStringTest.TestMethod() with a call to Convert.ToInt64(string, IFormatProvider).
if (correctOverload != null)
if (!oaContext.Options.IsConfiguredToSkipAnalysis(rule, targetMethod, oaContext.ContainingSymbol, oaContext.Compilation))
Copy link
Member

Choose a reason for hiding this comment

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

[cosmetic] Could you revert the condition to reduce nesting?

oaContext.ContainingSymbol.ToDisplayString(SymbolDisplayFormats.ShortSymbolDisplayFormat),
correctOverload.ToDisplayString(SymbolDisplayFormats.ShortSymbolDisplayFormat)));
IEnumerable<IMethodSymbol> methodsWithSameNameAsTargetMethod = targetMethod.ContainingType.GetMembers(targetMethod.Name).OfType<IMethodSymbol>().WhereMethodDoesNotContainAttribute(obsoleteAttributeType).ToList();
if (methodsWithSameNameAsTargetMethod.HasMoreThan(1))
Copy link
Member

Choose a reason for hiding this comment

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

[cosmetic] Could you revert the condition to reduce nesting?


if (argument != null && currentUICultureProperty != null &&
installedUICultureProperty != null && currentThreadCurrentUICultureProperty != null)
if (!oaContext.Options.IsConfiguredToSkipAnalysis(rule, targetMethod, oaContext.ContainingSymbol, oaContext.Compilation))
Copy link
Member

Choose a reason for hiding this comment

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

[cosmetic] Could you revert the condition to reduce nesting?

Copy link
Author

Choose a reason for hiding this comment

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

Would you please elaborate on what you mean? It's not obvious to me. I understand what you want but not how to do it actually.

Copy link
Member

Choose a reason for hiding this comment

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

@Evangelink This probably can't be done without goto? We don't bail out if it's configured to skip analysis since there are more rules to check.

However, I actually think that all IsConfiguredToSkipAnalysis calls will return the same result since all the 4 rules use the same ID?

In this case, I'll consider updating IsConfiguredToSkipAnalysis to take a rule id instead. But that probably should be in a different PR. Is there anything I'm missing?

Copy link
Author

Choose a reason for hiding this comment

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

However, I actually think that all IsConfiguredToSkipAnalysis calls will return the same result since all the 4 rules use the same ID?

This is something I'm interested in too.

targetMethod.ToDisplayString(SymbolDisplayFormats.ShortSymbolDisplayFormat)));
var argument = invocationExpression.Arguments[index];

if (argument != null && currentUICultureProperty != null &&
Copy link
Member

Choose a reason for hiding this comment

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

[cosmetic] Could you revert the condition to reduce nesting?

// This property returns a culture that is inappropriate for formatting methods.

oaContext.ReportDiagnostic(
invocationExpression.Syntax.CreateDiagnostic(
Copy link
Member

Choose a reason for hiding this comment

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

[cosmetic] This line and the next are missing some indent.

@MartyIX
Copy link
Author

MartyIX commented Sep 6, 2021

@jeffhandley I did try to address your feedback. I'm not entirely sure that I did it correctly but I did try :-)

@MartyIX
Copy link
Author

MartyIX commented Sep 7, 2021

@sharwell @jmarolf Would you mind having a look, please?

Copy link

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

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

:shipit:

@jmarolf jmarolf merged commit 7f55d85 into dotnet:main Sep 7, 2021
Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the feedback and for the additional tests.

@MartyIX MartyIX deleted the feature/ca1305-suppress branch September 7, 2021 18:56
@MartyIX
Copy link
Author

MartyIX commented Sep 13, 2021

@jeffhandley Would it be conceivable to port this PR even to .NET 6.0 branch? It seems to me that currently the PR is merged to .NET 7.0 branch.

Can I possibly help?

@jeffhandley
Copy link
Member

I'm on the fence for this. We've closed down RC2 so the fix would be ported into the final 6.0 release if we did. Our bar for fixes in the GA milestone is very high (generally only what we would service 6.0 for), and I'm uncertain if this meets that bar.

@jmarolf What do you think?

@MartyIX
Copy link
Author

MartyIX commented Sep 17, 2021

I see. One thing to consider is that the change is rather small (most of the added code is tests).

The alternative for me is to wait a year and not use CA1305 at all, if I get it correctly. I mean the rule discovers useful things for us but without suppressing the rule is not that useful as we use NLog where we are not interested in the warnings - probably the case for many people.

jmarolf pushed a commit to jmarolf/roslyn-analyzers that referenced this pull request Sep 23, 2021
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.

How to suppress CA1305 warnings for a specific type?

5 participants