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

no-unused-vars very forgiving #419

Closed
szkrd opened this issue Feb 15, 2016 · 16 comments

Comments

@szkrd
Copy link

commented Feb 15, 2016

Is it intentional that no-unused-vars are set only for variables, but not for arguments? I can live with it of course, just curious.

"no-unused-vars": 2 vs. "no-unused-vars": [2, { "args": "all" }]

@LinusU

This comment has been minimized.

Copy link
Member

commented Feb 15, 2016

It usually clashes with the ugly way that express defines handles error handlers...

I brought it up here #216 (comment) and here xojs/xo#6

Although I would actually be in favour of making it more strict 👍

@szkrd

This comment has been minimized.

Copy link
Author

commented Feb 15, 2016

Ah, now I see, thank you!

@szkrd szkrd closed this Feb 15, 2016

@LinusU

This comment has been minimized.

Copy link
Member

commented Feb 15, 2016

It might be a good idea to open up discussion about this again, and to run thru the tests and see how many repos would be affected by changing this...

@dcousens

This comment has been minimized.

Copy link
Member

commented Feb 15, 2016

@LinusU I use express. I feel this pain.

@dcousens dcousens added the question label Feb 15, 2016

@LinusU

This comment has been minimized.

Copy link
Member

commented Feb 15, 2016

Yeah, me too. But it's literally the only place I have this problem though, which makes it a bit annoying since it could catch other bugs...

@szkrd

This comment has been minimized.

Copy link
Author

commented Feb 15, 2016

We are mostly a koa shop :) Though adding it manually to eslintrc feels kinda dirty.

@dcousens

This comment has been minimized.

Copy link
Member

commented Feb 15, 2016

@LinusU the other major places I had this issue (superagent) were eventually lobbied enough to remove it, but I still feel its pain from time to time.

@feross

This comment has been minimized.

Copy link
Member

commented Feb 19, 2016

I just opened an issue on express about deprecating their four-argument middleware in favor of an explicit app.error method: expressjs/express#2896

@feross

This comment has been minimized.

Copy link
Member

commented Feb 19, 2016

Ran { "args": "after-used" } through the test suite:

1..427
# tests 427
# pass  322
# fail  105
@akivajgordon

This comment has been minimized.

Copy link

commented Jan 5, 2017

For me, a consequence of not being informed about unused params can cause tests to fail. As an example, I started with an asynchronous test:

it('should foo', (done) => {
  somethingAsync().then(() => {
    expect(...)
    done()
  })
})

But then, I refactored my test and it no longer needed to be async:

it('should foo', (done) => {
  doSomething()
  expect(...)
})

Oops! Now my test fails because I never called done(). Had the linter warned me about done being unused, I would have removed it and not been running an asynchronous test. In other words, the mere presence of the done argument (or lack thereof) actually changes the way the test behaves, so it would be nice if I was warned about it.

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Jan 5, 2017

@dcousens

This comment has been minimized.

Copy link
Member

commented Jan 6, 2017

Indeed, I am bitten by this often.
The few times it still occurs in express, I use _ to indicate an unused variable.

@dcousens

This comment has been minimized.

Copy link
Member

commented Jan 6, 2017

What about

"no-unused-vars": [2, { "vars": "all", "args": "all", "argsIgnorePattern": "^_$" }],
@feross

This comment has been minimized.

Copy link
Member

commented Jan 7, 2017

@akivajgordon Mocha should not count the number of arguments to the function to determine whether it's async or sync. Fortunately, this kind of fanciness is going out of fashion: it's planned to be removed from express and was already removed from other libraries that do it, like superagent. It should have explicit methods for sync and async tests, IMO.

@dcousens Any idea what the ecosystem impact of that rule change would be?

@yoshuawuyts This was removed well over a year ago, I believe.

@LinusU

This comment has been minimized.

Copy link
Member

commented Jan 7, 2017

It won't be a problem in the case of mocha though, since you always call the done callback somehow, if your test is asynchronous...

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

@feross feross reopened this Jul 11, 2019

@standard standard unlocked this conversation Jul 11, 2019

@feross feross added enhancement and removed question labels Jul 11, 2019

@feross

This comment has been minimized.

Copy link
Member

commented Jul 11, 2019

Moving discussion to here: standard/eslint-config-standard#136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants
You can’t perform that action at this time.