eslint-plugin-standard: callback error must be non literal?

I was wondering if we could have no-callback-literal rule to correspond with the no-throw-literal rule.

Basically, if you’re using the callback pattern this should never be okay:

callback('error')

instead you should do something more like this:

callback(new Error('error'))

We already built this locally, so let me know 😃

See: https://github.com/eslint/eslint/issues/6427

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

This just hit me in a non-error case. There are definitely valid use cases where you pass a string that’s not an error. Sorry to say that, but this rule is just stupid.

Guys, this also matches

callback({foo: somevariable})

Stop it already 😄

.catch(() => callback(false)); // eslint-disable-line standard/no-callback-literal

The line comment saved me 👏

This also seems to match

callback({foo: 'bar'})

which definitely is prone to lots of false positives.

@feross I’m basically fine removing this rule, I’ve personally moved to async/await instead of callbacks wherever possible and it’s clear that a lot of people don’t want to follow the callback-pattern strictly.

We should probably make an exception for the spread operator! On Sat, Aug 19, 2017 at 7:23 PM Tim Kinnane notifications@github.com wrote:

I got this lint error in an unrelated context, I think just from using an argument named callback…

In my case, nothing to do with error handling, I’ve got an es6 class listening to and relaying events on another module with a custom on function:

on (event, callback) { otherModule.on(event, (…args) => { callback(…args) }) }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xjamundx/eslint-plugin-standard/issues/12#issuecomment-323559096, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPBf7_NqqvbTyQWRHZhnynCPiMO3mDTks5sZ5iVgaJpZM4JQSHV .

I got this lint error in an unrelated context, I think just from using an argument named callback…

In my case, nothing to do with error handling, I’ve got an es6 class listening to and relaying events on another module with a custom on function:

on (event, callback) {
  otherModule.on(event, (...args) => {
    callback(...args)
  })
}

Ran into this rule while writing some tests and passing in a couple numbers into a parameter called ‘callback.’ Got around it by renaming the parameter to aFunc. There’s no real pattern matching going on here, just looking for some parameters of certain names it seems (which doesn’t seem like a worthwhile use of a linter to me). Probably worth at least revisiting this test…