Skip to content
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

Add analyzer for StringBuilder(char) #46103

Open
eduherminio opened this issue Dec 15, 2020 · 2 comments
Open

Add analyzer for StringBuilder(char) #46103

eduherminio opened this issue Dec 15, 2020 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime code-analyzer Marks an issue that suggests a Roslyn analyzer
Milestone

Comments

@eduherminio
Copy link
Member

Context:

  • Adding a StringBuilder(char) constructor was originally proposed in Add StringBuilder(Char) #20848 due to the existing StringBuilder(int capacity) constructor accepting a char as an argument (i.e.: StringBuilder('a')), but the proposal was finally rejected.

  • Since this scenario will generally denote a bug, the possibility of creating an analyzer for it was brought up during the review of the proposal, but apparently was discarded or never formalized.

  • After opening a GH discussion about it, I was suggested in to formally propose the creation of such analyzer (StringBuilder: char constructor #46052 (comment)).

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Dec 15, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

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.

@danmoseley danmoseley added area-System.Runtime code-fixer Marks an issue that suggests a Roslyn code fixer code-analyzer Marks an issue that suggests a Roslyn analyzer and removed code-fixer Marks an issue that suggests a Roslyn code fixer labels Dec 15, 2020
@GrabYourPitchforks
Copy link
Member

GrabYourPitchforks commented Dec 16, 2020

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.

@tannergooding tannergooding removed the untriaged New issue has not been triaged by the area owner label Jul 12, 2021
@tannergooding tannergooding added this to the Future milestone Jul 12, 2021
@buyaa-n buyaa-n added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime code-analyzer Marks an issue that suggests a Roslyn analyzer
Projects
None yet
Development

No branches or pull requests

6 participants