-
Notifications
You must be signed in to change notification settings - Fork 480
Add support for CA1305 suppression. #5374
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
Conversation
Codecov Report
@@ 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 |
|
@Youssef1313 Would you mind having a look? |
Youssef1313
left a comment
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.
LGTM
Youssef1313
left a comment
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.
Please open an issue for dotnet/docs to update the documentation when this PR is merged and a new version is released.
|
Thank you! |
|
@sharwell Gentle ping. Can a buddy be assigned here? :-) |
|
@buyaa-n @jeffhandley Would you be the correct one to review this? |
jeffhandley
left a comment
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.
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:
methodsWithSameNameAsTargetMethod.HasMoreThan(1)being true and false- With overloads that do and don't match the desired parameters
- And overloads where the last parameter is and is not
IFormatProvider, ensuring we hit each of thecorrectPOverloads.FirstOrDefault()possibilities - Where
targetMethod.ReturnTypeis and is not astring - Where the symbol does and does not match one of the
...UICulturePropertyproperties
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)) | ||
| { |
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 looks like this set of braces can be removed
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.
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) | ||
| { |
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 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)) |
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.
[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)) |
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.
[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)) |
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.
[cosmetic] Could you revert the condition to reduce nesting?
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.
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.
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.
@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?
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.
However, I actually think that all
IsConfiguredToSkipAnalysiscalls 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 && |
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.
[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( |
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.
[cosmetic] This line and the next are missing some indent.
|
@jeffhandley I did try to address your feedback. I'm not entirely sure that I did it correctly but I did try :-) |
jmarolf
left a comment
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.
![]()
jeffhandley
left a comment
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 for addressing the feedback and for the additional tests.
|
@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? |
|
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? |
|
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. |
Fixes #5372