-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
dotnet/roslyn-analyzers
#6720Closed
Copy link
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Globalizationcode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixerhelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorspartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated
Milestone
Description
The right way to compare two strings in a case-insensitive manner is via a StringComparer/Comparison that specifies case-insensitivity. But there's are many cases where code is using ToLower() on each string and then comparing those for equality, e.g.
- https://grep.app/search?q=%5C.ToLower%5C%28%5C%29%20%3D%3D%20%5Cw%2B%5C.ToLower%5C%28%5C%29®exp=true&case=true&filter[lang][0]=C%23
- https://grep.app/search?q=%5C.ToUpper%5C%28%5C%29%20%3D%3D%20%5Cw%2B%5C.ToUpper%5C%28®exp=true&case=true&filter[lang][0]=C%23
- https://grep.app/search?q=%5C.ToLower%5C%28%5C%29%5C.Equals%5C%28%5Cw%2B%5C.ToLower%5C%28%5C%29®exp=true&case=true&filter[lang][0]=C%23
- https://grep.app/search?q=%5C.ToUpper%5C%28%5C%29%5C.Equals%5C%28%5Cw%2B%5C.ToUpper%5C%28%5C%29®exp=true&case=true&filter[lang][0]=C%23
We should write an analyzer that flags such uses and recommends fixing them to use Equals with the appropriate comparison.
This analyzer should cover ToUpper too even if the usage is low for that.
Such analyzers will help avoid the allocations caused by ToLower/ToUpper calls.
campersau, martincostello, NN---, datvm, ViIvanov and 3 more
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Globalizationcode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixerhelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorspartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated