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 😃
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 21 (10 by maintainers)
Links to this issue
Commits related to this issue
- New Rule: no-callback-literal (fixes #12) — committed to standard/eslint-plugin-standard by deleted user 8 years ago
- New Rule: no-callback-literal (fixes #12) — committed to standard/eslint-plugin-standard by deleted user 8 years ago
- New Rule: no-callback-literal (fixes #12) — committed to standard/eslint-plugin-standard by deleted user 8 years ago
- New Rule: no-callback-literal (fixes #12) — committed to standard/eslint-plugin-standard by deleted user 8 years ago
- New Rule: no-callback-literal (fixes #12) — committed to standard/eslint-plugin-standard by deleted user 8 years ago
- Merge pull request #15 from xjamundx/no-callback-literal New Rule: no-callback-literal (fixes #12) — committed to standard/eslint-plugin-standard by feross 7 years ago
- eslint: disable node/no-callback-literal - only false positives All of our patterns are like this: https://github.com/standard/eslint-plugin-standard/issues/12#issuecomment-298228089 — committed to kiwitcms/Kiwi by atodorov 3 years ago
- eslint: disable node/no-callback-literal - only false positives All of our patterns are like this: https://github.com/standard/eslint-plugin-standard/issues/12#issuecomment-298228089 — committed to kiwitcms/Kiwi by atodorov 3 years ago
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
Stop it already 😄
The line comment saved me 👏
This also seems to match
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
onfunction: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…