New Rule: no-callback-literal
See original GitHub issueWhat 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:
- Created 7 years ago
- Reactions:24
- Comments:17 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The lack of
callback(...args)
support is a bit lame.What about
why it’is error?