Skip to content

Add FixAll support of UseRecursivePattern refactoring#61915

Merged
mavasani merged 1 commit intodotnet:mainfrom
mavasani:FixAllUseRecursivePatterns
Jun 15, 2022
Merged

Add FixAll support of UseRecursivePattern refactoring#61915
mavasani merged 1 commit intodotnet:mainfrom
mavasani:FixAllUseRecursivePatterns

Conversation

@mavasani
Copy link
Copy Markdown
Contributor

This was identified as a high value refactoring for FixAll support as it promotes a new language feature (C# recursive patterns)

This was identified as a high value refactoring for FixAll support as it promotes a new language feature (C# recursive patterns)
@mavasani mavasani requested a review from CyrusNajmabadi June 15, 2022 11:25
@mavasani mavasani requested a review from a team as a code owner June 15, 2022 11:25
@ghost ghost added the Area-IDE label Jun 15, 2022
@mavasani
Copy link
Copy Markdown
Contributor Author

Tagging @mikadumont

Comment on lines +84 to +94
private static bool IsFixableNode(SyntaxNode node)
=> node switch
{
BinaryExpressionSyntax(LogicalAndExpression) => true,
CasePatternSwitchLabelSyntax { WhenClause: { } whenClause } => true,
SwitchExpressionArmSyntax { WhenClause: { } whenClause } => true,
WhenClauseSyntax { Parent: CasePatternSwitchLabelSyntax } => true,
WhenClauseSyntax { Parent: SwitchExpressionArmSyntax } => true,
_ => false
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static bool IsFixableNode(SyntaxNode node)
=> node switch
{
BinaryExpressionSyntax(LogicalAndExpression) => true,
CasePatternSwitchLabelSyntax { WhenClause: { } whenClause } => true,
SwitchExpressionArmSyntax { WhenClause: { } whenClause } => true,
WhenClauseSyntax { Parent: CasePatternSwitchLabelSyntax } => true,
WhenClauseSyntax { Parent: SwitchExpressionArmSyntax } => true,
_ => false
};
private static bool IsFixableNode(SyntaxNode node)
=> node switch
{
BinaryExpressionSyntax(LogicalAndExpression) => true,
CasePatternSwitchLabelSyntax { WhenClause: not null } => true,
SwitchExpressionArmSyntax { WhenClause: not null } => true,
WhenClauseSyntax { Parent: CasePatternSwitchLabelSyntax } => true,
WhenClauseSyntax { Parent: SwitchExpressionArmSyntax } => true,
_ => false
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fold this suggestion into the next PR and avoid re-running tests on this PR.


// Get current root, current node to refactor and semantic model.
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var currentNode = root.GetCurrentNodes(originalNode).SingleOrDefault();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're using SingleOrDefault, but not checking the result? should we check this for null? or does GetReplacementFunc already do this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, GetReplacementFunc handles null input.

@mavasani mavasani merged commit c119061 into dotnet:main Jun 15, 2022
@mavasani mavasani deleted the FixAllUseRecursivePatterns branch June 15, 2022 17:06
@ghost ghost added this to the Next milestone Jun 15, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants