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.

no-else-return doesn't trigger for else if.

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.6.1
  • Node Version: 8.4.0
  • npm Version: 5.3.0

What parser (default, Babel-ESLint, etc.) are you using? see config Please show your full configuration: see eslint demo URLs. What did you do? Please include the actual source code causing the issue.

const res = (() => {
  if (error) {
    return 'It failed';
  } else if (loading) {
    return "It's still loading";
  }

  return result;
})();

What did you expect to happen?

no-else-return should trigger.

What actually happened? Please include the actual, raw output from ESLint.

no-else-return did not trigger.

Demo urls:

doesn’t detect error does detect error

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
graingertcommented, Sep 4, 2017

@platinumazure fyi, with explicit block statements eslint flags them all.

0reactions
graingertcommented, Sep 5, 2017

@platinumazure I’ve taken my PR out of WIP and it’s ready for review.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Unnecessary 'else' after 'return'. (No-else-return)
It's just saying that there's no need for 'else' since the execution of the function already stopped and if the 'if' condition doesn't...
Read more >
No Else Return | SamanthaMing.com
No Else Return. You can skip the else block if your if block always executes a return statement. I find this way makes...
Read more >
5 ways to refactor if/else statements in JS functions
Last solution to clunky if/else statements, especially those nested ones, are no-else-return statements and guard clauses .
Read more >
[resolved] Does every IF has to follow a ELSE and Does return ...
So I hope not tl;dr the first questions answer is no, a else can follow after an if but it does not need...
Read more >
Pylint features - Pylint 2.16.0-dev documentation
Used when an async context manager is used with an object that does not ... should only have an else clause if they...
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