Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Analyzer and fixer that recommend case insensitive string comparison #6662
Analyzer and fixer that recommend case insensitive string comparison #6662
Changes from 38 commits
c9b4479
d85c6a8
ab3965f
9516781
1a407d4
5d202a2
27acb1c
4298b5c
d6a193c
2ca2441
c441153
8de0cd9
4da0528
0011a6a
0bfbc0b
5c16a10
492275d
1098548
1a2f5ec
1617027
75109c0
0de635c
a5e4f97
f8d5688
5961fab
fee0f45
fb4f324
673d04c
349a06c
dd47ee2
59c0115
21cfaaf
cb83e9e
d73eb5c
7ede45e
ea7d45d
f37c39e
3f7a020
801fb99
84745f0
2d3cf5b
986973c
0a2182e
4778992
e2b4b95
e570710
efabebc
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Should we consider also detecting simple patterns across statements, such as below?
We would need to check that we have exactly one reference to the intermediate temporary variable.
If yes, we already added another analyzer which implements a simple heuristic for detecting above patterns: https://github.com/dotnet/roslyn-analyzers/blob/main/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/PreferStringContainsOverIndexOfAnalyzer.cs. If not for v1, but feel it may be a worthwhile enhancement, you may also consider filing a tracking issue for this enhancement.
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.
Yes, V2. Opened: #6689
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.
Not sure if this will be a false-negative in some cases. Previously, I mentioned that the codefix produces code that is semantically different. Is it a false negative in the first place?
Or maybe report CompareTo under a separate ID to give user more control to disable it alone?
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 addressed your concern about CompareTo changing the semantics. I special-cased CompareTo so that it only triggers the analyzer but not the codefix. Check out the unit tests to see how I separate them.
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.
Yup, this comment is about whether we should actually warn or not, and if we should warn, whether it should be a separate ID or not.
Per #6662 (comment), I'm personally okay with doing this in a follow-up (unless @mavasani thinks this should be in this PR)
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.
Ah got it. Yes, let's continue the discussion separately.