Skip to content

fix(linter/import/no-duplicates): handle comments after a trailing comma when merging - #29595

Merged
camc314 merged 6 commits into
oxc-project:mainfrom
shuxiachai:fix/no-duplicates-comma-comment
Nov 15, 2026
Merged

camc314 merged 6 commits into
oxc-project:mainfrom
shuxiachai:fix/no-duplicates-comma-comment

Conversation

@shuxiachai

@shuxiachai shuxiachai commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

import/no-duplicates checks for a trailing comma in the first import with trim_end().ends_with(','), so a comment after the comma hides it. This is common in multi-line imports:

import {
  a, // comment
} from "./x.js";
import { b } from "./x.js";
console.log(a, b);

oxlint -A all -D import/no-duplicates --import-plugin --fix writes

import {
  a, // comment,b
} from "./x.js";
console.log(a, b);

b ends up in the comment and its import is removed. The result parses, so the fixer's syntax check doesn't catch it, and running the file throws ReferenceError: b is not defined.

With /* comment */ after the comma, the fix writes a, /* comment */,b, which doesn't parse. Debug builds stop at the fixer's "produced invalid syntax" assertion; release builds write it to disk.

A comment after the trailing comma of a later import has the same problem. It is taken as a specifier, so a comma goes before the next one: { a,b,// note\n,c }.

This PR:

  • skips comments when looking for the first import's trailing comma, as eslint-plugin-import does with getTokenBefore(closeBrace) (no-duplicates.js)
  • starts the merged specifiers on a new line when the first import's braces end with a line comment
  • doesn't put a comma before a part that is only comments, e.g. /* note */ in { b, /* note */ }

The four cases are added as fix cases. #24467 handled trailing commas without comments.

cargo test --all-features -p oxc_linter and just lint -p oxc_linter pass.


I used AI assistance (Claude Code) to find these bugs and write this change. I reviewed the code and ran the tests.

🤖 Generated with Claude Code

Follow-up review and fixes were prepared with OpenAI Codex AI assistance: preserve imports after line comments ending in spaces, recognize all JavaScript line terminators, avoid repeated forward comment scans, and remove redundant explanatory comments.

…mma when merging

The fix looked for a trailing comma in the first import with
`trim_end().ends_with(',')`, so a comment after the comma hid it:

- `import {\n  a, // comment\n} from 'x'` merged with `import { b } from 'x'`
  became `a, // comment,b`. `b` ends up in the comment and its import is
  removed, and the result still parses.
- With `/* comment */` instead, it became `a, /* comment */,b`, which
  doesn't parse.

A comment after the trailing comma of a later import was taken as a
specifier, so another comma was added before the next one:
`{ a,b,// note\n,c }`.

Skip comments when looking for the trailing comma, as eslint-plugin-import
does with `getTokenBefore`, start the merged specifiers on a new line after
a line comment, and don't put a comma before a part that is only comments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shuxiachai
shuxiachai requested a review from camc314 as a code owner November 15, 2026 10:35
@github-actions github-actions Bot added the A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details label Nov 15, 2026
@codspeed

codspeed Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 105 skipped benchmarks1


Comparing shuxiachai:fix/no-duplicates-comma-comment (7280ec8) with main (00704a6)

Open in CodSpeed

Footnotes

  1. 105 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@camc314
camc314 merged commit 42395f2 into oxc-project:main Nov 15, 2026
32 checks passed
graphite-app Bot pushed a commit that referenced this pull request Nov 16, 2026
# Oxlint
### 🚀 Features

- db5bc6b linter: Output recommended flag in `--rules` JSON output (#29338) (Cam McHenry)
- acd8814 linter/typescript/no-misused-promises: Add `flagUnions` option (#29380) (camc314)
- fa492d6 minifier: Merge adjacent switch cases with identical bodies (#29316) (camc314)
- ca3b2cb linter/vue/no-shared-component-data: Implement fixer (#29291) (Mikhail Baev)
- bfe3498 linter: Mark oxc rules as recommended (#28091) (Cam McHenry)
- 5da83ae linter/eslint/no-unused-vars: Suggest removing unused type parameters (#28762) (YanYunCY)
- 6816662 linter/jsdoc/require-param-description: Implement suggestion (#29118) (Mikhail Baev)

### 🐛 Bug Fixes

- 97ed4b7 linter: Mark undefined argument removal as dangerous (#29266) (周星星同学)
- 58ef81d linter/typescript/prefer-function-type: Strip a trailing comma from the fixed signature (#28145) (NavpreetSSidhu)
- dcb465f linter/jsx-a11y/prefer-tag-over-role: Allow role="img" on svg (#29440) (Nadir Ali)
- 994ddc3 linter/eslint/no-div-regex: Offer regex rewrites as suggestions (#29493) (oxc-captain[bot])
- dc5add7 linter/jsx-a11y/lang: Don't report a missing lang attribute (#29441) (Nadir Ali)
- f010115 linter/jest/prefer-to-be,linter/vitest/prefer-to-be: Emit rewrites as suggestions (#29503) (oxc-captain[bot])
- b31fb57 linter/eslint/no-new-wrappers: Offer wrapper rewrites as suggestions (#29494) (oxc-captain[bot])
- 9abb941 linter/jsx-a11y/scope: Preserve effectful attribute values in safe fixes (#29507) (oxc-captain[bot])
- a1664a9 linter/jsx-a11y/no-redundant-roles: Use the first valid ARIA role token (#29497) (oxc-captain[bot])
- 64df21d linter/eslint/yoda: Skip safe fixes for relational regex comparisons (#29495) (oxc-captain[bot])
- df8887a linter/typescript/no-import-type-side-effects: Make the import rewrite a suggestion (#29502) (oxc-captain[bot])
- 2ce7f06 linter/jest/no-unneeded-async-expect-function,linter/vitest/no-unneeded-async-expect-function: Suggest unwrapping async callbacks (#29501) (oxc-captain[bot])
- 45c2159 linter/eslint/no-regex-spaces: Offer regex rewrites as suggestions (#29499) (oxc-captain[bot])
- 5167945 linter/vitest/prefer-import-in-mock: Preserve quotes and escapes in fixes (#29509) (oxc-captain[bot])
- 7127aa6 linter/jest/prefer-called-with,linter/vitest/prefer-called-with: Offer matcher rewrites as suggestions (#29498) (oxc-captain[bot])
- 5472a21 linter/typescript: Offer @ts-ignore rewrites as suggestions (#29511) (oxc-captain[bot])
- 523d59b linter/eslint/no-useless-escape: Demote useless escape fixes to suggestions (#29508) (oxc-captain[bot])
- 7ce5692 linter/jest/prefer-todo,linter/vitest/prefer-todo: Restrict safe fixes (#29512) (oxc-captain[bot])
- 0d3f45a linter/vitest/prefer-importing-vitest-globals: Avoid duplicate imports for type-only bindings (#29564) (Ahmed Alhaidary)
- d22f2c2 linter/vitest/prefer-strict-boolean-matchers: Offer rewrites as suggestions (#29500) (oxc-captain[bot])
- 2170319 linter/react/only-export-components: Classify export specifiers like declarations (#29520) (Rahul Kashyap)
- 79c0b73 linter/eslint/prefer-object-spread: Skip __proto__ sources and suggest unsafe rewrites (#29510) (oxc-captain[bot])
- 69be73e linter/jsx-a11y: Match event handler props case-insensitively (#29570) (Nadir Ali)
- 1ae09b9 linter/jsx-a11y/aria-unsupported-elements: Preserve effectful attribute values (#29506) (oxc-captain[bot])
- 4092e2f linter/jsx-a11y/no-aria-hidden-on-focusable: Suggest removing aria-hidden (#29505) (oxc-captain[bot])
- 4059ff7 linter/react/rules-of-hooks: Match namespaced additional effect hooks (#29517) (Boshen)
- 65659e6 linter/react/no-unstable-nested-components: Ignore prop callbacks that return an object holding JSX (#29605) (Nadir Ali)
- bff48d0 linter/unicorn/prefer-set-size: Keep a space after a keyword before `[` (#29597) (Jingbo Chai)
- 2bb4c72 linter/vitest/prefer-importing-vitest-globals: Skip value imports from non-Vitest sources (#29563) (Abdul karim mia)
- a087125 linter/oxc/no-accumulating-spread: Check reduce callbacks that take the index or array (#29573) (Nadir Ali)
- 1a6fa05 linter/eslint/no-useless-rename: Don't fix a parenthesized target with a default (#29602) (Jingbo Chai)
- 121b55c linter/typescript/prefer-function-type: Don't fix or double-report `export default interface` (#29593) (Jingbo Chai)
- 9a3d7a1 linter/unicorn/prefer-export-from: Don't offer a fix that drops other names from the export list (#29574) (Nadir Ali)
- b188db6 linter/unicorn/prefer-response-static-json: Fix the suggestion when a comment follows `new` (#29591) (Jingbo Chai)
- 915a851 linter/eslint/no-var: Don't fix when `let` or `const` changes behavior (#29590) (Jingbo Chai)
- 9674aec linter: Don't skip code between comments when checking for an ASI hazard (#29601) (Jingbo Chai)
- 5e74d21 linter/unicorn/prefer-at: Preserve grouping in slice pop and shift fixes (#29598) (Jingbo Chai)
- c39f4fc linter/oxc/only-used-in-recursion: Keep the line break after a line comment (#29606) (Jingbo Chai)
- 66d30ee linter/jest/no-untyped-mock-factory: Copy the module name as written (#29604) (Jingbo Chai)
- 1a0460a linter/unicorn/prefer-single-call: Skip comments when checking for a trailing comma (#29596) (Jingbo Chai)
- 42395f2 linter/import/no-duplicates: Handle comments after a trailing comma when merging (#29595) (Jingbo Chai)
- 22cfb3f linter/eslint/curly: Don't remove braces when the statement needs a semicolon (#29592) (Jingbo Chai)
- 40b81d2 linter/unicorn/no-useless-spread: Replace holes with `undefined` in spread arguments (#29600) (Jingbo Chai)
- 00704a6 linter: Print config: remove redundant extends in output (#29585) (Cam McHenry)
- fe779e8 linter/vitest/require-awaited-expect-poll: Allow implicit arrow-function returns (#29576) (oxc-captain[bot])
- 6da36f8 linter: Print config: validate CLI options before printing config (#29538) (Cam McHenry)
- dda4d11 linter: Print config: reflect CLI options like `--type-aware` in the printed config (#29537) (Cam McHenry)
- dadb64f linter: Print config: include JS plugin settings in output JSON (#29534) (Cam McHenry)
- 0b643b3 linter: Print config: use resolved config instead of config builder (#29533) (Cam McHenry)
- 0a557ae linter: Print config: flatten single-element options arrays (#29531) (Cam McHenry)
- 09ef22f linter: Print config: preserve original rule configuration when generating rule sets (#29530) (Cam McHenry)
- 9314042 linter/react: Exhaustive-deps misses ref.current method calls on custom refs (#29571) (Boshen)
- 1dc0ee9 semantic: Preserve catch and var binding identities (#28739) (Dunqing)
- bebe76c linter/unicorn/prefer-spread: Avoid stack overflow on cyclic initializers (#29433) (camc314)
- eefd253 linter/react/exhaustive-deps: Stop autofixing missing dependency arrays (#29430) (camc314)
- 2b4f13e linter/unicorn/prefer-date-now: Preserve negation and comments (#29352) (Guru 🦄)
- 2dc1839 linter/eslint/func-style: Report functions sharing type names (#29378) (Abdul karim mia)
- db80510 linter/jsx-a11y/no-redundant-roles: Preserve link roles without href (#29384) (oxc-captain[bot])
- 9c20c2a linter: Infer omitted RegExp flags from known patterns (#29428) (oxc-captain[bot])
- 95f1081 linter/unicorn/no-accessor-recursion: Distinguish private and public keys (#29429) (oxc-captain[bot])
- 9f465fd react-compiler: Preserve ref mutation hints (#28553) (Nash Aschenbath)
- e5fb59e linter/vitest/require-test-timeout: Avoid overflow when sorting configurations (#29299) (camc314)
- 9f72ce2 linter/unicorn/consistent-template-literal-escape: Avoid panics after CRLF (#29298) (camc314)
- a2bd61d linter/react/jsx-key: Only check direct JSX array elements (#29294) (camc314)
- ed4fb73 linter/oxc/no-accumulating-spread: Avoid panic on parenthesized optional chains (#29293) (camc314)
- 4a9d681 linter/jest/prefer-to-be,linter/vitest/prefer-to-be: Avoid Unicode whitespace panics (#29292) (camc314)
- d8c1333 linter/vitest/prefer-called-once: Avoid panics on escaped matcher names (#29289) (camc314)
- 4959267 linter/unicorn/prefer-includes: Avoid panic on parenthesized optional chains (#29286) (camc314)
- a5f7617 linter/unicorn/prefer-object-from-entries: Avoid panic on wrapped callees (#29285) (camc314)
- 925633b linter/unicorn/prefer-dom-node-remove: Avoid panic on parenthesized optional chains (#29279) (camc314)
- f991b20 linter/unicorn/no-length-as-slice-end: Avoid panic on wrapped callees (#29277) (camc314)
- d5385ca linter/unicorn/no-useless-spread: Avoid panics on Unicode whitespace (#29278) (camc314)
- 06d5e6d linter/typescript/consistent-type-imports: Avoid panic on quoted import names (#29274) (camc314)
- db58bd1 linter/unicorn/prefer-set-has: Avoid panics on Unicode whitespace (#29276) (camc314)
- a87cecd linter/unicorn/no-document-cookie: Stop resolving cyclic aliases (#29275) (camc314)
- 9c9ffb6 linter/unicorn/prefer-array-flat: Avoid panic on rest parameters (#29273) (camc314)
- d068722 linter/no-large-snapshots: Avoid panics on Unicode whitespace (#29272) (camc314)
- 411624a linter/eslint/no-empty: Use byte offsets for finally suggestions (#29271) (camc314)
- 84fd230 linter/import/no-duplicates: Ignore braces in module strings (#29270) (camc314)
- 5d669bb linter/vitest/no-standalone-expect: Support Vitest `.extend` test functions (#29243) (camchenry)
- d1bd197 linter/vitest/prefer-snapshot-hint: Recognize conditional test scopes (#29221) (camc314)
- 3b16ccf linter/vitest/require-awaited-expect-poll: Avoid duplicated reports (#29174) (sapphi-red)
- f0e3270 linter/prefer-mock-return-shorthand: Avoid mock return shorthand for mutations (#29136) (camc314)
- 8fe22b1 linter/eslint/no-useless-assignment: Handle instance field captures (#29135) (camc314)
- 3e1303e linter/eslint/no-use-before-defne: Fix numerous failing cases (#28861) (Cam McHenry)
- 50278cc linter/eslint/no-restricted-imports: Report invalid regex configuration (#29119) (camc314)
- dde6024 linter/eslint/arrow-body-style: Converge fixes for wrapped object returns (#29101) (camc314)
- 5a32ad0 linter/unicorn/prefer-negative-index: Avoid panic on non-ASCII whitespace (#28877) (YT)

### ⚡ Performance

- aed0190 parser: Skip unused identifier hashes (#29168) (Boshen)
- 0dfb188 oxlint: Build diagnostic output while linting runs (#28747) (YT)

### 📚 Documentation

- cdb5ac4 oxlint: Remove experimental label from `typeCheck` (#29175) (Yuji Sugiura)
- ae514b3 linter: Move rule creation guidance into crate AGENTS.md (#29122) (camc314)
# Oxfmt
### 🚀 Features

- 21e1fc1 formatter_graphql: Support empty selection sets and braced unicode escapes (#29345) (leaysgur)
- 292f216 oxfmt: Bump prettier to 3.10.1 (#29333) (leaysgur)

### 🐛 Bug Fixes

- 552732b formatter: Fix parenthesized `TSInstantiationExpression` issue (#29389) (leaysgur)
- 7e41638 parser: Keep whole parenthesized `TSInstantiationExpression` with `preserve_parens: false` (#29359) (leaysgur)
- d41ed14 formatter: Keep the `;` of a lone statement in a Vue event handler (#29354) (leaysgur)
- 58d7356 formatter: Break a conditional type alias with a generic constructor type after `=` (#29411) (leaysgur)
- 59b8eaa formatter: Print binaryish or `yield` args like `return` (#29407) (leaysgur)
- d6632f3 formatter: Keep a comment after `TSPropertySignature`'s `:` (#29393) (leaysgur)
- cf50f9b formatter: Keep a blank line between dangling comments (#29392) (leaysgur)
- e648de6 formatter: Print sequence in `yield` and unary like in `return` (#29353) (leaysgur)
- 547684d formatter: Keep parens around `<` on the left of `>` (#29351) (leaysgur)
- 16b84d3 formatter/htmlish: Print CDATA sections as nodes of their own (#29348) (leaysgur)
- f9f2385 formatter_css: Print `@supports selector()` like rule selector (#29343) (leaysgur)
- f31a8d1 formatter: Align union hug and conditional branch (#29261) (leaysgur)
- 79064df formatter_htmlish/angular: Keep block params, ignore whole block (#29258) (leaysgur)
- 4d50307 formatter_htmlish: Keep attrs holding character reference (#29257) (leaysgur)
- 3205e84 formatter: Break after `=` for hugged type alias (#29256) (leaysgur)
- bed54ab formatter_htmlish: Keep whitespace as written only between two CJ characters (#29171) (leaysgur)
- 1905d2b formatter_markdown: Keep whitespace as written only between two CJ characters (#29170) (leaysgur)
- a3660bb formatter_htmlish: Keep empty comment only element as-is (#29159) (leaysgur)
- 49b832a formatter_htmlish/vue: Preserve `v-for` alias holding `in|of` (#29156) (leaysgur)

### 📚 Documentation

- 63b9b38 formatter: Re-check divergences whose pins changed in Prettier 3.10 (#29412) (leaysgur)
- 0467739 formatter: Classify js/ts conformance failures for prettier 3.10 (#29336) (leaysgur)
- 9660ce4 oxfmt: Update htmlish and oxfmt divergences (#29334) (leaysgur)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants