-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New] no-unused-modules
: support dynamic imports
#1660
[New] no-unused-modules
: support dynamic imports
#1660
Conversation
3 similar comments
Because |
hey, thanks for feedback!
good point, you're right - I should be treating this as namespace :)
Not sure I entirely follow here. I was not going to check if any specific name imported from the module has ever been referenced (there are other eslint rules for this matter) but when import is assigned to destructured object I want to mark specific names that were imported, isn't this good for this rule? |
Right, that's what I'm saying - it's not going to be safe in enough cases to mark specific names, so any path that's dynamically imported should be treated as potentially using every export. |
Even though handling all kinds of expressions would be very complex I believe it is possible to handle some finite amount of patterns and it would increase accuracy of the lib, e.g.
all other calls to is that something you would consider to review? updated version of table yeah I figured out all calls to import not assigned to object pattern should be treated as namespace imports, so it results in less specific cases:
all other calls to |
In your first row, the
|
alright, this is too much :) I'll treat |
@ljharb I almost cleaned it up although I am stuck at typescript files - I put a dedicated test with typescript parser and it is always green - how do I configure it to work properly - it looks like it is simply skipping ts file. |
2ae6d70
to
db319e3
Compare
ok I believe I figured this out, although one last bit that puzzles me - dynamic imports are supported by espree since 6.1.0 (eslint/js@f5e58cc) but tests fail even if |
It wasn't stage 4 until ES2020, so eslint wouldn't support it until that ecmaVersion. If it's still not working with the right ecmaVersion, it might not work in eslint until v7; for now, it's fine just to support those two parsers. |
should I modify readme with this? |
533df7f
to
4e2e78c
Compare
it fails tests on eslint 2 and 3, what's the best way to deal with these? |
bump? |
689264a
to
cff6dbb
Compare
@maxkomarychev looks like you also have to update https://github.com/benmosher/eslint-plugin-import/blob/master/src/rules/no-unused-modules.js#L610 to include dynamic imports into |
@Hypnosphi can you elaborate please? this pr puts dynamic imports with as they are namespace imports, given that all other code is using Thanks. |
friendly ping @ljharb |
I'll take a look at this in the next 24 hours or so. |
eee0cc8
to
4f338bf
Compare
no-unused-modules
: support dynamic imports
@Hypnosphi perhaps i messed up the rebase, but a bunch of tests are still failing. could you make sure to fetch the latest branch, and then get the tests passing? |
Sorry, it's hard to track what's changed here comparing to my branch. I think I'll open a separate PR |
@Hypnosphi i really, really wish you had not done that (see #1660 (comment) where i explicitly asked you not to); PRs once opened are eternally present in a repo's refs. Now I just have to keep both of these PRs in sync until they're landed. |
63c3c5a
to
b724db8
Compare
Extracted from import-js#2122 / import-js#1660.
Extracted from import-js#2212 / import-js#1660.
See import-js#1660, import-js#2212. Co-authored-by: Max Komarychev <[email protected]> Co-authored-by: Filipp Riabchun <[email protected]> Co-authored-by: 薛定谔的猫 <[email protected]>
All occurences of `import('...')` are treated as namespace imports (`import * as X from '...'`) See import-js#1660, import-js#2212. Co-authored-by: Max Komarychev <[email protected]> Co-authored-by: Filipp Riabchun <[email protected]> Co-authored-by: 薛定谔的猫 <[email protected]>
b724db8
to
b7bf750
Compare
b7bf750
to
7c382f0
Compare
yes, please file a new issue if you still encounter it. |
All occurences of
import('...')
are treated as namespace imports(
import * as X from '...'
)Fixes #1951.