dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.91k stars 4.63k forks source link

Add a rule to specify StringComparer #52399

Open xPaw opened 4 years ago

xPaw commented 4 years ago

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

v2.9.5 (Latest)

assembly.GetTypes().OrderBy(t => t.Namespace)

There are CA1304, CA1305, CA1307 rules which warn about specifying CultureInfo, IFormatProvider, StringComparison.

There is no rule to warn about StringComparer, which also has different behaviours depending on current locale, for example in OrderBy and ThenBy LINQ methods.

StingyJack commented 4 years ago

Would this cover Dictionary<string, T>(StringComparer) also?

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 3 years ago

Tagging subscribers to this area: @tannergooding See info in area-owners.md if you want to be subscribed.

Issue Details
#### Analyzer package [Microsoft.CodeAnalysis.FxCopAnalyzers](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers) #### Package Version v2.9.5 (Latest) #### ```dotnet assembly.GetTypes().OrderBy(t => t.Namespace) ``` There are CA1304, CA1305, CA1307 rules which warn about specifying CultureInfo, IFormatProvider, StringComparison. There is no rule to warn about `StringComparer`, which also has different behaviours depending on current locale, for example in `OrderBy` and `ThenBy` LINQ methods.
Author: xPaw
Assignees: -
Labels: `area-System.Runtime`, `code-analyzer`, `untriaged`
Milestone: -
stan-sz commented 2 years ago

As per @StingyJack question: it would save so many case-sensitivity bugs in code to have this rule cover Dictionary's constructor...

symbiogenesis commented 1 year ago

Great idea!