import-js/eslint-plugin-import

[no-unused-modules] Improve for "import * as __ from __"

Offen

#1.775 geöffnet am 21.05.2020

 (6 Kommentare) (1 Reaktion) (0 zugewiesene Personen)JavaScript (1.548 Forks)batch import
enhancementhelp wantedrule proposal

Repository-Metriken

Stars
 (5.940 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 138T 22h) (3 gemergte PRs in 30 T)

Beschreibung

If a file with named exports is imported as import * as xxx from './xxx' the rule assumes that all exports of this file have been used.

Would it be possible to report exports that never have been accessed?

Example:

given file-f:

import * as fileG from './file-g'

const x = fileG.a
fileG.b()

and file-g

export const a = 7 // will not be reported
export const b = () => {} // will not be reported
export const c = 5 // will be reported

Of course this can only work as long as a module is not access like this:

import * as fileG from './fileG'
fileG['b']()

In this case the current behaviour would apply and nothing would be reported.

We heavily rely on the import * as __ from __ syntax, so we would rely profit from this change. In any case, thanks a lot for all the effort that went into that plugin already!

Contributor Guide