-
Notifications
You must be signed in to change notification settings - Fork 470
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
Use ToLowerInvariant Or ToUpperInvariant Analyzer #2186
Conversation
src/Microsoft.NetCore.Analyzers/Core/Runtime/UseToLowerInvariantOrToUpperInvariant.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Runtime/UseToLowerInvariantOrToUpperInvariant.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Runtime/UseToLowerInvariantOrToUpperInvariant.cs
Outdated
Show resolved
Hide resolved
@TKharaishvili Do you plan to update/finish this PR? |
@Evangelink I think there were some open questions that needed to be discussed. If you look at the 2nd of my 3 subdiscussions with mavasani above, in the last comment he tagged some people mentioning it. As far as I know those questions were never addressed. At this point I don't really remember much about this issue or even the PR itself as it all happened over a year ago. However I'm open to getting myself back up to speed on all of it given those open questions get addressed. |
This comment has been minimized.
This comment has been minimized.
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 have two problems with the current design:
- As an analyzer in the globalization category, rather than focus on usage of ToLowerInvariant and ToUpperInvariant, we should focus on explicitly indicating the desired culture for the conversion.
- Two code fixes should be offered. The first (primary) code fix should retain the call to
ToLower
but add an argument specifying current culture (semantic preservation). A second code fix can be offered to change the call toToLowerInvariant
.
If we keep the current approach of preferring to push users to change semantics by adopting invariant culture, the analyzer should probably be moved to the Performance category instead of the Globalization category, at which point the value seems to be diminished significantly.
f1ec888
to
5a69115
Compare
@carlossanlop @tarekgh I managed to update the PR and address some of the original change requests. Can you gentlemen review it? |
Codecov Report
@@ Coverage Diff @@
## main #2186 +/- ##
==========================================
- Coverage 96.05% 96.04% -0.01%
==========================================
Files 1315 1323 +8
Lines 304998 305370 +372
Branches 9667 9687 +20
==========================================
+ Hits 292952 293294 +342
- Misses 9726 9740 +14
- Partials 2320 2336 +16 |
# Conflicts: # src/NetAnalyzers/RulesMissingDocumentation.md
@carlossanlop @tarekgh gentlemen, can I request another round of code review please? Both the analyzer and fixer are implemented and ready to be looked at. |
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, thanks @TKharaishvili for getting this done.
@carlossanlop @buyaa-n the changes look good to me. Could you have a look and merge it if you have permission to merge? |
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/UseToLowerInvariantOrToUpperInvariantTests.cs
Outdated
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/UseToLowerInvariantOrToUpperInvariantTests.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/SpecifyCultureForToLowerAndToUpper.cs
Outdated
Show resolved
Hide resolved
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 @TKharaishvili for getting this ready. LGTM. I think @buyaa-n is going to take a look too.
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
...itTests/Microsoft.NetCore.Analyzers/Runtime/SpecifyCultureForToLowerAndToUpperTests.Fixer.cs
Show resolved
Hide resolved
...CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpSpecifyCultureForToLowerAndToUpper.Fixer.cs
Outdated
Show resolved
Hide resolved
...CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpSpecifyCultureForToLowerAndToUpper.Fixer.cs
Outdated
Show resolved
Hide resolved
...yzers/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpSpecifyCultureForToLowerAndToUpper.cs
Outdated
Show resolved
Hide resolved
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 @TKharaishvili I think the messaging needs some update as now it looks like an analyzer for suggesting to Specify CurrentCulture
, and left a few optional NIT, other than that it looks good to me
Tagging @sharwell for review as his requested change is addressed |
Thank you @TKharaishvili, looks great to me, normally the reviewer who requested a change should approve or remove the CR before merge, tough I see @sharwell is out. As the requested changes addressed as he wanted hope he would not mind if I dismiss his change request to unblock the PR. We he have any other comment we can address that separately |
<value>Specify current culture</value> | ||
</data> | ||
<data name="UseInvariantVersion" xml:space="preserve"> | ||
<value>User an invariant version</value> |
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.
Looks like a typo? @buyaa-n
Debug.Assert(invocationNode.IsKind(SyntaxKind.InvocationExpression)) | ||
|
||
Dim invocation = CType(invocationNode, InvocationExpressionSyntax) |
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 can fail I think. VB doesn't require parentheses for parameterless method calls
Public Class C
Public Sub M(x As String)
Dim y = x.ToLower ' This is a member access expression, not an invocation.
End Sub
End Class
|
||
namespace Microsoft.NetCore.Analyzers.Runtime.UnitTests | ||
{ | ||
public class SpecifyCultureForToLowerAndToUpperFixerTests |
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.
Tests should be consolidated into one file.
Fixes dotnet/runtime#43976
The first commit only includes the analyzer. Once the analyzer code gets approved, I'll also add the fixer.