-
-
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
rule
#1142
Conversation
Signed-off-by: René Fermann <rene.fermann@gmx.de>
Signed-off-by: René Fermann <rene.fermann@gmx.de>
Signed-off-by: René Fermann <rene.fermann@gmx.de>
…ilename Signed-off-by: René Fermann <rene.fermann@gmx.de>
Signed-off-by: René Fermann <rene.fermann@gmx.de>
Signed-off-by: René Fermann <rene.fermann@gmx.de>
This comment has been minimized.
This comment has been minimized.
While looking into how import *I'm unsure what should happen when import * as localVar from './file-1';
localVar.something(); Can we detect that we're actually using the named export export fromGiven
dynamic importI suspect dynamic import cannot be detected, this should be mentioned in the docs. |
Yes, an import * should mark all exports as used, i think. |
… sanity checks Signed-off-by: René Fermann <rene.fermann@gmx.de>
Signed-off-by: René Fermann <rene.fermann@gmx.de>
…rom ', revised docs
Support for How can I analyze, why the AppVeyor build is failing all the time? It btw also fails for tests I haven't touched at all 😕 |
@ljharb: do you have any ideas how to tackle the failing AppVeyor build? |
@rfermann i believe it's on master, and unrelated to this PR. |
Okay, good to know. What else needs to be done from my site to let this PR be merged? Should I adjust the change log? Or is that one of these tasks you will perform @ljharb? |
@rfermann you don't have to worry about the changelog; the appveyor issue should be fixed on master if you rebase. |
…orts', revised docs Signed-off-by: René Fermann <rene.fermann@gmx.de>
Signed-off-by: René Fermann <rene.fermann@gmx.de>
@ljharb , @benmosher: what else am I expected to do to get this PR merged? Is it the outstanding rebase which is blocking the merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing a fresh review - looks good overall. Just a few comments.
…riable, fixed documentation Signed-off-by: Fermann <rene.fermann@capgemini.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure all files have trailing newlines.
Thanks for your latest feedback. I implemented your suggestions.
I don't get that. Did I forgot the trailing newline anywhere? I checked the files I pushed today and all already had a trailing newline 😕 |
src/rules/no-unused-modules.js
Outdated
specifiers.some(({ type }) => type === IMPORT_DEFAULT_SPECIFIER) | ||
|
||
module.exports = { | ||
isNodeModule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically for testing, just as you supposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't need direct testing; let's please not export it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rfermann hey! i know it's been awhile; are you still interested in addressing the outstanding comments, rebasing, and ensuring the tests pass?
src/rules/no-unused-modules.js
Outdated
specifiers.some(({ type }) => type === IMPORT_DEFAULT_SPECIFIER) | ||
|
||
module.exports = { | ||
isNodeModule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't need direct testing; let's please not export it.
|
||
module.exports = { | ||
meta: { | ||
docs: { url: docsUrl('no-unused-modules') }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the name no-unused-modules
misleading? This rule reports individual export declarations, but the name suggests it reports whole files as unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my understanding is that it reports on both - both unused files, and unused exports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as @ljharb says, it reports on both:
- modules without any exports are reported here
- and modules with unused exports are reported here and here
However this rule currently does not report, if a module only consists of unused exports. Each of these exports is reported separately.
I am not sure whether it makes sense to have one single report being triggered if none of the existing exports is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make sense to me in that case to only provide one report; just as I’d expect when a module has no exports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, let's give this a shot :-)
As discussed in #186, this rule adds the possibility to find modules without any exports and/or exports within a module, which aren't used in other modules
ToDos:
This is the first rule I created. Writing tests for it may therefor take some additional time.