Sitelet https://github.com/import-js/eslint-plugin-import/pull/3289
Skip to content

[Fix] no-duplicates: preserve default imports with comments - #3289

Open
ZelinZhu-Richard wants to merge 2 commits into
import-js:mainfrom
ZelinZhu-Richard:fix/no-duplicates-commented-default
Open

ZelinZhu-Richard wants to merge 2 commits into
import-js:mainfrom
ZelinZhu-Richard:fix/no-duplicates-commented-default

Conversation

@ZelinZhu-Richard

@ZelinZhu-Richard ZelinZhu-Richard commented Sep 19, 2026 •

Copy link
Copy Markdown

no-duplicates can produce an invalid duplicate declaration when a comment prevents an import from being removed:

import { set } from '@ember/object';
import EmberObject, { observer, computed } from '@ember/object'; // some comment

The fixer copies EmberObject into the first import while leaving the second import intact. Only copy a default binding from an import eligible for removal, using the same filtered set as the removal logic. Existing ambiguity checks and comment handling stay unchanged; other safe imports can still merge.

Addresses the invalid-autofix part of #1838; merging across comments is intentionally left unfixed.

Tested:

  • tests/src/rules/no-duplicates.js: 114 passed. Regression coverage includes the reported example, leading/trailing/internal comments, and merging a third safe import. Five added cases failed before the fix; existing ambiguity and ordinary default-import cases pass.
  • npm test: 3,151 passed, 2 pending, including lint and documentation checks.

AI assistance: this change was developed with an AI coding tool; I reviewed and tested it.

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.60%. Comparing base (a60d715) to head (9f9ba8a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3289   +/-   ##
=======================================
  Coverage   79.59%   79.60%           
=======================================
  Files          98       98           
  Lines        4549     4550    +1     
  Branches     1543     1576   +33     
=======================================
+ Hits         3621     3622    +1     
  Misses        928      928           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant