Skip to content

Conversation

@rickhohler
Copy link

Description

This PR implements the RemoveRedundantParens refactoring action, which safely unwraps single-element tuples that do not need parentheses.

Transformation:

let x = (10)
// becomes:
let x = 10

Detailed Design

  • Adds RemoveRedundantParens provider to SwiftRefactor.
  • Criteria:
    • Input is a TupleExprSyntax.
    • Exactly one element.
    • No element labels.
  • Safety Logic (Precedence):
    • To prevent breaking operator precedence, the refactoring aborts if it detects that it is unwrapping a SequenceExpr (binary operation) inside another SequenceExpr (or standard ExprList structure).
    • Example: x * (a + b) -> Parentheses are PRESERVED (Refactoring unavailable).
    • Example: let x = (a + b) -> Parentheses removed (Safe assignment).

Fixes

Addresses core logic for swiftlang/sourcekit-lsp#2451.

Pre-PR Checklist

  • Code builds and passes tests.
  • Ran swift-format.
  • Added unit tests in RemoveRedundantParensTest.swift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant