dotnet / runtime

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

Add analyzer for StringBuilder(char) #46103

Open eduherminio opened 3 years ago

eduherminio commented 3 years ago

Context:

Dotnet-GitSync-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.

GrabYourPitchforks commented 3 years ago

I wonder if this can be turned into a generalized heuristic. Some possible examples:

If the parameter is named capacity, count, or similar; and if the input to the parameter is a char which has been auto-widened to an int; trigger the analyzer.

If there are two method overloads MyMethod(..., string, ...) and MyMethod(..., int, ...) (but no MyMethod(..., char, ...)), and if the call site matched the second overload because a char was auto-widened to an int, trigger the analyzer.