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.

`consistent-return` Treat `return void ...` the same as `return;`

See original GitHub issue

What 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

2reactions
ilyavolodincommented, May 2, 2016

Sounds reasonable to me, but I think it should go behind an option. 👍

1reaction
pedrottimarkcommented, May 15, 2016

I will be champion to work through the rest of the process with @scriptdaemon

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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