sonar-dotnet
sonar-dotnet copied to clipboard
When comparing strings, always provide an explicit StringComparison argument
@andrei-epure-sonarsource Is it meant to be in SonarWay?
I think so...
https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings#specifying-string-comparisons-explicitly
Some overloads with default parameters (those that search for a Char in the string instance) perform an ordinal comparison, whereas others (those that search for a string in the string instance) are culture-sensitive. It is difficult to remember which method uses which default value, and easy to confuse the overloads.
In general, we recommend that you call a method that does not rely on defaults, because it makes the intent of the code unambiguous. This, in turn, makes the code more readable and easier to debug and maintain.
I'm afraid that would be too noisy. Mainly on client side apps where it is intended to use the default culture sensitive behavior.
You can use already the Roslyn analysers (CA1305) to surface that as a warning with SonarCloud @andrei-epure-sonarsource, e.g.: