Skip to content

Remove parentheses from single unnamed lambda parameters#1054

Merged
timtebeek merged 1 commit intomainfrom
tim/unnamed-var-lambda-parens
Apr 9, 2026
Merged

Remove parentheses from single unnamed lambda parameters#1054
timtebeek merged 1 commit intomainfrom
tim/unnamed-var-lambda-parens

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • When ReplaceUnusedVariablesWithUnderscore renames a single parenthesized lambda parameter to _, it now also strips the parentheses so (_) -> ... becomes _ -> ...
  • renameVariableIfUnusedInContext now returns a boolean to signal whether a rename will occur
  • Added replaceUnusedParenthesizedLambdaParameter test covering this case

Test plan

  • Existing tests pass
  • New test verifies (item) -> "NODATA" becomes _ -> "NODATA"
  • Multi-param lambdas like (_, _) -> ... retain parentheses

When `ReplaceUnusedVariablesWithUnderscore` renames a single
parenthesized lambda parameter to `_`, also strip the parentheses
so `(_) -> ...` becomes `_ -> ...`.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Apr 9, 2026
@timtebeek timtebeek merged commit 8ad8d92 into main Apr 9, 2026
1 check passed
@timtebeek timtebeek deleted the tim/unnamed-var-lambda-parens branch April 9, 2026 11:07
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant