-
Notifications
You must be signed in to change notification settings - Fork 29.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
tools: enable no-unused-vars linter rule and fix issues #2828
Conversation
@@ -4,7 +4,6 @@ | |||
* should trigger the error event after each attempt. | |||
*/ | |||
|
|||
var common = require('../common'); |
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.
Requiring common actually just does things.
I suppose we don't need to assign it to a variable though.
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.
Are these 'things' relevant to tests that don't use the variable?
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.
Yes. See https://github.com/nodejs/node/blob/master/test/common.js#L304-L313 among other things. Actually, all tests should require common. (Perhaps it should just be pre-loaded, not sure.)
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.
If it's just this leaked global check, I see two options:
- We remove that leaked global check. These can be warned through the linter unless we do something like global.x, but that ought to be intentional.
- We preload common.js
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.
There's this too but I think that's it:
Lines 142 to 151 in 68dc69a
if (process.env.NODE_COMMON_PIPE) { | |
exports.PIPE = process.env.NODE_COMMON_PIPE; | |
// Remove manually, the test runner won't do it | |
// for us like it does for files in test/tmp. | |
try { | |
fs.unlinkSync(exports.PIPE); | |
} catch (e) { | |
// Ignore. | |
} | |
} |
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.
what's the big deal with requiring common? are you trying to shave off ms?
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.
Requiring common without actually using it violates the rule I'm trying to add 😉
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 saw that the rule allows exceptions per varsIgnorePattern
, so that could be another option.
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.
Could also change var common = require('../common.js')
to just require('../common.js');
...
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.
That looks a bit strange imho and would confuse someone who doesn't know about this 'dependency'.
Looks like option I need was added just in 1.3 (eslint/eslint@91fc1c5), making this PR depend on #2286. |
This is obsolete now with #4536. |
This enables the
no-unused-vars
rule. Issues that came up were mostly the variables on top of tests and there were a few cases where there was leftover dead code.I intentionally didn't enable the feature for unused function arguments yet. I think the best to go about these is to comment out the arguments in
lib
while removing them intest
, does that sound good?Note that this is somewhat WIP, as there were a few cases where the intention seemed to be to use some of these variables, but I'm submitting this now as-is for some feedback.