`consistent-return` Treat `return void ...` the same as `return;`
See original GitHub issueWhat version of ESLint are you using?
2.8.0
What parser (default, Babel-ESLint, etc.) are you using?
Default
Please show your full configuration:
root: true
env:
es6: true
node: true
extends:
"eslint:recommended"
rules:
consistent-return: "error"
What did you do? Please include the actual source code causing the issue.
Wrote a function with a callback that returns early when an error is found:
log(level, message, meta, callback) {
let recipientId = _.get(meta, 'recipientId');
if (!recipientId) {
return void callback(new Error('No recipient ID'));
}
// Other code that doesn't return anything ...
}
Returning the callback is nice because it saves a line, but I want to guarantee the function returns nothing (thus the use of void
).
What did you expect to happen?
No error.
What actually happened? Please include the actual, raw output from ESLint.
error Expected to return a value at the end of this method consistent-return
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:26 (26 by maintainers)
Top Results From Across the Web
consistent-return - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Return void type in C and C++ - Stack Overflow
In a function returning void, the return statement with expression can be used, if the expression type is void.
Read more >JavaScript void Keyword - Cmichel.io
Let's look at the consistent return ESLint rule again. It states that functions should either always return values, or never (which means always ......
Read more >"warning: no return statement in function returning non-void ...
Either flowing off the end of a function is "equivalent to a return with no value" (i.e. invalid according to the beginning of...
Read more >consistent-return - DEV Community
function myFunc(item) { if (booleanCheck) { // do something return false; } // do something but not returning anything or returning void or ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
Sounds reasonable to me, but I think it should go behind an option. 👍
I will be champion to work through the rest of the process with @scriptdaemon