Skip to content

linter: prefer-destructuring: fixer produces invalid code due to ASI #23800

Description

@ntnyq

What version of Oxlint are you using?

1.71.0

What happened?

The auto-fix for eslint/prefer-destructuring on assignment expressions produces code that triggers ASI (Automatic Semicolon Insertion) parsing errors.

Before fix:

switch (placement) {
  case 'bottom-start':
    left = triggerRect.left
    break
}

After --fix (broken):

switch (placement) {
  case 'bottom-start':
    ({ left } = triggerRect)   // TS: This expression is not callable
    break
}

TypeScript/JavaScript interprets ({ left } = triggerRect) on its own line as a function call because ( follows a newline with no preceding semicolon.

ESLint behavior: ESLint's prefer-destructuring rule does NOT auto-fix assignment expressions — only variable declarations get fixed. This avoids the ASI issue entirely.

Reproduction

// .oxlintrc.json
{ "rules": { "eslint/prefer-destructuring": "error" } }
const triggerRect = { left: 0, right: 100, top: 0, bottom: 50, width: 100, height: 50 }
let left = 0

left = triggerRect.left  // ← oxlint fixer changes this to ({ left } = triggerRect)

Expected

The fixer should either:

  1. Insert a semicolon prefix when the replacement starts with (: ;({ left } = triggerRect)
  2. Or skip auto-fix for assignment expressions (matching ESLint's behavior)

See generate_fix in crates/oxc_linter/src/rules/eslint/prefer_destructuring.rs — the is_assignment branch produces ({ prop } = obj) without checking for ASI hazards.

Metadata

Metadata

Assignees

Labels

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions