fix(dedupeImports): respect negative and zero import priorities#527
fix(dedupeImports): respect negative and zero import priorities#527
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #527 +/- ##
==========================================
- Coverage 98.73% 94.60% -4.13%
==========================================
Files 14 13 -1
Lines 1817 1001 -816
Branches 374 332 -42
==========================================
- Hits 1794 947 -847
- Misses 23 50 +27
- Partials 0 4 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/dedupe.test.ts (1)
70-93: Consider asserting no warning for the negative-priority case.This test verifies winner selection, but not warning suppression. Adding an empty-warning assertion would harden the regression coverage.
Suggested test addition
it('should respect negative priority', () => { expect(dedupeImports( [ { name: 'foo', from: 'module1', }, { name: 'foo', from: 'module2', priority: -1, }, ], warnFn, )).toMatchInlineSnapshot(` [ { "from": "module1", "name": "foo", }, ] `) + expect(warnMsg).toMatchInlineSnapshot('""') })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/dedupe.test.ts` around lines 70 - 93, The test for negative priority should also assert that no warning was emitted: after calling dedupeImports in the 'should respect negative priority' test, add an assertion that warnFn was not called (e.g., expect(warnFn).not.toHaveBeenCalled() or expect(warnFn.mock.calls.length).toBe(0)) so the test verifies both winner selection and warning suppression for the negative-priority case; locate the call to dedupeImports and the warnFn mock in this test to place the assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/dedupe.test.ts`:
- Around line 70-93: The test for negative priority should also assert that no
warning was emitted: after calling dedupeImports in the 'should respect negative
priority' test, add an assertion that warnFn was not called (e.g.,
expect(warnFn).not.toHaveBeenCalled() or
expect(warnFn.mock.calls.length).toBe(0)) so the test verifies both winner
selection and warning suppression for the negative-priority case; locate the
call to dedupeImports and the warnFn mock in this test to place the assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7eb1b1b2-0ccc-43e6-b5ac-369b4f2977fd
📒 Files selected for processing (2)
src/utils.tstest/dedupe.test.ts
There was a problem hiding this comment.
we should use ?? rather than || to respect priority of 0
There was a problem hiding this comment.
Should we do that now? I kept || for compatibility, but I can change to ?? if that's not an issue.

Resolves #524.
The current implementation of
dedupeImportsignores negative priorities in some cases. This PR implements proper support for imports' negative priorities.In the linked issue, there's a warning for Nuxt's
useAppConfigimport, which uses a negative priority of-1, so I think not properly handling negative priorities is causing that issue.Summary by CodeRabbit
Bug Fixes
Tests