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

Analyzer: Validate literal arguments to StringSyntaxAttribute parameters/members #64009

Open
Tracked by #79053
stephentoub opened this issue Jan 19, 2022 · 2 comments
Open
Tracked by #79053
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

@stephentoub
Copy link
Member

stephentoub commented Jan 19, 2022

#62995 added the new StringSyntaxAttribute, and we annotated a bunch of APIs with it, for the three syntaxes currently identified: Regex, DateTimeFormat, and Json.

Visual Studio will look for these and use it to influence its colorization, IntelliSense, etc., but we can also use them to help warn developers at dev time / build time when they've written something that will produce run-time failures. We can add an analyzer for each syntax that will warn on the literal provided, e.g. these would warn

var r = new Regex("[abc"); //  Invalid pattern '[abc' at offset 4. Unterminated [] set.
DateTime.ParseExact(DateTime.Now.ToString(), "c", null); // Invalid format specifier
@stephentoub stephentoub added the code-analyzer Marks an issue that suggests a Roslyn analyzer label Jan 19, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jan 19, 2022
@dotnet-issue-labeler
Copy link

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
Copy link

ghost commented Jan 20, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

#62995 adds the new StringSyntaxAttribute and annotates a bunch of APIs with it, for the two syntaxes currently identified: Regex and DateTimeFormat.

Visual Studio will look for these and use it to influence its colorization, IntelliSense, etc., but we can also use them to help warn developers at dev time / build time when they've written something that will produce run-time failures. We can add an analyzer for each syntax that will warn on the literal provided, e.g. these would warn

var r = new Regex("[abc"); //  Invalid pattern '[abc' at offset 4. Unterminated [] set.
DateTime.ParseExact(DateTime.Now.ToString(), "c", null); // Invalid format specifier
Author: stephentoub
Assignees: -
Labels:

area-System.Runtime, untriaged, code-analyzer

Milestone: -

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

4 participants