-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
dotnet/sdk
#51214Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.RegularExpressionscode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixerhelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
In looking through various code bases, I've seen the following pattern repeatedly:
if (Regex.IsMatch(pattern))
{
Match m = Regex.Match(pattern);
...
}
That just doubles the work involved when there is a match. It should instead be:
if (Regex.Match(pattern) is { Success: true } m)
{
...
}
or something similar. We should have an analyzer that flags these duplicative guards and a fixer that transforms into something like the latter.
neon-sunset, colejohnson66, MichalPetryka, omariom, martincostello and 1 moreCopilot
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.RegularExpressionscode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixerhelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged