Skip to content
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

Merged
merged 13 commits into from
Apr 15, 2022

Conversation

TKharaishvili
Copy link
Contributor

@TKharaishvili TKharaishvili commented Mar 10, 2019

Fixes dotnet/runtime#43976

The first commit only includes the analyzer. Once the analyzer code gets approved, I'll also add the fixer.

@Evangelink
Copy link
Member

@TKharaishvili Do you plan to update/finish this PR?

@TKharaishvili
Copy link
Contributor Author

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

@carlossanlop

This comment has been minimized.

Copy link
Member

@sharwell sharwell left a 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:

  1. 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.
  2. 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 to ToLowerInvariant.

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.

@TKharaishvili TKharaishvili force-pushed the issue-1487-use-invariant branch from f1ec888 to 5a69115 Compare October 20, 2021 21:03
@TKharaishvili
Copy link
Contributor Author

@carlossanlop @tarekgh I managed to update the PR and address some of the original change requests. Can you gentlemen review it?
It only contains an Analyzer for now I'll start working on a Fixer soon.
Also the builds are failing with an error message that is a little hard to understand. I'd appreciate some help with that as well.

@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #2186 (31a5855) into main (5b0b341) will decrease coverage by 0.00%.
The diff coverage is 91.93%.

@@            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     

@TKharaishvili
Copy link
Contributor Author

@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.
I see that the CI build is failing, I looked at the logs but I wasn't able to figure out what the cause might be.

Copy link
Member

@tarekgh tarekgh left a 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.

@tarekgh
Copy link
Member

tarekgh commented Feb 9, 2022

@carlossanlop @buyaa-n the changes look good to me. Could you have a look and merge it if you have permission to merge?

@TKharaishvili
Copy link
Contributor Author

@tarekgh @buyaa-n I addressed the latest change requests. Had to rename Analyzer, Fixer and Test classes since the old name didn't work for new requirements.

I hope no more major changes will be necessary.

Eager to hear your reply.

Copy link
Member

@tarekgh tarekgh left a 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.

Copy link
Contributor

@buyaa-n buyaa-n left a 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

@buyaa-n
Copy link
Contributor

buyaa-n commented Apr 14, 2022

Tagging @sharwell for review as his requested change is addressed

@TKharaishvili
Copy link
Contributor Author

@tarekgh @buyaa-n all the requested changes are made.

@buyaa-n
Copy link
Contributor

buyaa-n commented Apr 15, 2022

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

@buyaa-n buyaa-n dismissed sharwell’s stale review April 15, 2022 17:45

The request is addressed

@buyaa-n buyaa-n merged commit 334bb06 into dotnet:main Apr 15, 2022
@github-actions github-actions bot added this to the vNext milestone Apr 15, 2022
<value>Specify current culture</value>
</data>
<data name="UseInvariantVersion" xml:space="preserve">
<value>User an invariant version</value>
Copy link
Member

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

Comment on lines +15 to +17
Debug.Assert(invocationNode.IsKind(SyntaxKind.InvocationExpression))

Dim invocation = CType(invocationNode, InvocationExpressionSyntax)
Copy link
Member

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Proposal] Analyzer that suggests ToUpperInvariant/ToLowerInvariant in place of ToUpper/ToLower
10 participants