fix(linter/unicorn): fix ASI hazard in prefer-spread rule fixer#16440
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
aa56e91 to
091d331
Compare
CodSpeed Performance ReportMerging #16440 will not alter performanceComparing Summary
Footnotes
|
091d331 to
4147346
Compare
b404099 to
e68269a
Compare
4147346 to
fd61773
Compare
|
@overlookmotel assigned this to you to review as I'd appreciate another set of eyes. All good if you don't have time though - thanks |
fd61773 to
21c674f
Compare
e7f423e to
206868c
Compare
21c674f to
4867ee2
Compare
206868c to
8274f63
Compare
4867ee2 to
801fc7e
Compare
8274f63 to
8c10694
Compare
801fc7e to
ee8ab4a
Compare
ee8ab4a to
cda3bce
Compare
There was a problem hiding this comment.
My god this is tricky. It would be so much simpler and less error-prone if we had tokens to look at.
A couple more chars need adding to the check, I think, and a few notes on perf.
I've only nitpicked on perf because presumably this function is going to need to be used in lots of other rules too.
cda3bce to
bf593c7
Compare
19f94eb to
b98310b
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes an ASI (Automatic Semicolon Insertion) hazard in the prefer-spread linter rule's auto-fixer. The fixer now detects when replacing code like Array.from(set) with [...set] could cause parsing issues due to JavaScript's ASI rules, and adds a semicolon prefix when needed (e.g., foo()\nArray.from(set) becomes foo()\n;[...set]).
Key Changes:
- Added
could_be_asi_hazard()function to detect when a semicolon is needed before inserting code that starts with[ - Updated
prefer-spreadrule fixer to check for ASI hazards and add semicolons when necessary - Added comprehensive test coverage for various ASI hazard scenarios including Unicode identifiers, comments, and irregular whitespace
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
crates/oxc_linter/src/ast_util.rs |
Implements ASI hazard detection with could_be_asi_hazard() and helper function find_last_meaningful_char() to scan backwards through source text, skipping whitespace and comments |
crates/oxc_linter/src/rules/unicorn/prefer_spread.rs |
Threads node parameter through to fixer functions and adds ASI hazard checks to all auto-fixes for Array.from(), array.slice(), array.toSpliced(), and string.split() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
🤖 generated with help from Claude Opus 4.5
b98310b to
678e43b
Compare
🤖 generated with help from Claude Opus 4.5
…project#16440) 🤖 generated with help from Claude Opus 4.5

🤖 generated with help from Claude Opus 4.5