Eslint-plugin-import: [no-unused-modules] Imports overriding reexports

Created on 7 Apr 2020  路  4Comments  路  Source: benmosher/eslint-plugin-import

I noticed that no-unused-modules with unusedExports trips up on this syntax:

a.js:

export function a() {}

// The following line will wrongly error as unused:
export function aa() {}

b.js:

import { a } from './a';

export { aa } from './a';

I've tracked this down to this line in the src, which overwrites any previously detected reexports. The proposed fix is to do something like what is already being done in these lines to keep both reexported entries and imports.

I can give a shot at throwing together a PR if this looks reasonable?

bug help wanted

Most helpful comment

Yeah, having a import and a reexport from the same file isn't a super common pattern. 馃槃

I have some code that works, just need to write a test and I'll send a PR within the next few days.

All 4 comments

The example is working as intended. Do you mean

- export { aa } from './b';
+ export { aa } from './a';

?

Ah, yes, sorry for the typo. I updated the first post to be correct. 馃槃 Thanks for noticing!

Yes, that seems like a good fix - the code was probably assuming that duplicate imports were always merged.

Yeah, having a import and a reexport from the same file isn't a super common pattern. 馃槃

I have some code that works, just need to write a test and I'll send a PR within the next few days.

Was this page helpful?
0 / 5 - 0 ratings