Meta / ktfmt
Merged via Meta CodeSyncFeatureMerged Jun 18, 2026

Support name-based destructuring declarations

Meta CodeSync imported and merged the ktfmt fix for Kotlin name-based destructuring, preserving bracket delimiters and rename formatting for the newer destructuring syntax.

facebook/ktfmt · #630

Problem

ktfmt could hang or fail to normalize Kotlin name-based destructuring examples such as bracket destructuring and renamed entries. The formatter also risked rewriting bracket delimiters as parentheses, which would change the source form users wrote.

Approach

Preserved destructuring delimiters through the Kotlin PSI lPar/rPar accessors, formatted renamed entries through the existing declaration path, added regression coverage, and guarded the new syntax test for Kotlin 2.3+ so Meta's Kotlin 2.2 internal build stayed compatible.

Impact and scope

  • Keeps ktfmt aligned with newer Kotlin destructuring syntax instead of losing bracket delimiter intent during formatting.
  • Improves formatter correctness for developers using name-based destructuring with renamed bindings such as x = b.
  • Demonstrates upstream review collaboration by resolving Meta's Kotlin 2.2 compatibility feedback before CodeSync merged the change.

Validation

  • Added FormatterTest coverage for bracket destructuring and renamed name-based destructuring entries.
  • Verified focused FormatterTest coverage, the broader formatter test class, and the ktfmt module build from the PR workflow.
  • Meta CodeSync imported the PR, closed linked issue #629, applied the Merged label, and recorded the merge into facebook/ktfmt.