Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

silverwind
Copy link
Contributor

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 in test, 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.

@silverwind silverwind added the tools Issues and PRs related to the tools directory. label Sep 12, 2015
@@ -4,7 +4,6 @@
* should trigger the error event after each attempt.
*/

var common = require('../common');
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.)

Copy link
Contributor Author

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

Copy link
Member

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:

node/test/common.js

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.
}
}

Copy link
Member

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?

Copy link
Contributor Author

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 😉

Copy link
Contributor Author

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.

Copy link
Member

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');...

Copy link
Contributor Author

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'.

@silverwind
Copy link
Contributor Author

Looks like option I need was added just in 1.3 (eslint/eslint@91fc1c5), making this PR depend on #2286.

@silverwind
Copy link
Contributor Author

This is obsolete now with #4536.

@silverwind silverwind closed this Jan 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stalled Issues and PRs that are stalled. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants