question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Rule: no-callback-literal

See original GitHub issue

What does everyone think of a rule that more strictly enforce the callback pattern? This will help people avoid the common mistake of calling back with an error message instead of an error object, which can lead to all sorts of weird bugs.

There is already this similar rule in ESLint: http://eslint.org/docs/rules/no-throw-literal

Here is how it will work:

Allowed

callback(null)
callback()
callback(undefined)
callback(null, data)
callback(err)
callback(someRandomVariable)
callback(new Error("error!~"))

Not allowed

callback(true)
callback("there was an error")
callback(1)

Of course we can figure out if we should include cb and next as well as callback in the list of allowed function names.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:24
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
dcousenscommented, Dec 1, 2017

The lack of callback(...args) support is a bit lame.

3reactions
dutchenkoOlegcommented, Jul 20, 2017

What about

return cb(...someArray);

why it’is error?

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-node/no-callback-literal.md at master - GitHub
When a function is named cb or callback , then it must be invoked with a first argument that is undefined , null...
Read more >
Unexpected literal in error position of callback in Vue.JS
It seems like it's caused by some code linting tool you use. It thinks that you need to pass error as the first...
Read more >
eslint-plugin-n - npm
Additional ESLint's rules for Node.js. ... n/no-callback-literal, ensure Node.js-style error-first callback ... A new rule is created.
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
Rules. Rules in ESLint are grouped by category to help you understand their purpose. No rules are enabled by default. The "extends": "eslint:recommended" ......
Read more >
14 Linting Rules To Help You Write Asynchronous Code in ...
This rule disallows passing an async function to the new Promise ... In other words, this rule prevents callback hell! ... 9. node/no-callback-literal....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found