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 rule should work in try-catch block

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.16.0
  • Node Version: 12.0.0
  • npm Version: 6.9.0

What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration:

Configuration
{
    "env": {
        "es6": true,
        "node": true
    },
    "extends": "eslint:recommended",
    "rules":  {
        "no-else-return": "error"
    }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

class C {
    get(id) {
        if (this._options.get) {
            try {
                return this._options.get(id);
            } catch (error) {
                return Promise.reject(error);
            }
        } else { // Should warn about unnecessary else block
            return Promise.reject(new Error('Method not implemented'));
        }
    }
}
npx eslint test.js

What did you expect to happen? It was expected to show an error that else block is unnecessary.

What actually happened? Please include the actual, raw output from ESLint. No error displayed in the output, because there is a nested try-catch block inside the if block.

Are you willing to submit a pull request to fix this bug? Not yet.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
thewalla07commented, Nov 8, 2019

I would like to work on this, could you please assign this issue to me?

1reaction
kaicataldocommented, Mar 8, 2020

I’m still in favor of the proposal outlined in https://github.com/eslint/eslint/issues/8028. If someone is interested in championing that proposal, please feel free to create a new issue outlining where we landed in that issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-else-return - ESLint - Pluggable JavaScript Linter
This rule is aimed at highlighting an unnecessary block of code following an if containing a return statement. As such, it will warn...
Read more >
Behaviour of return statement in catch and finally
General rules of try/catch block: 1) Never return a value in the finally block. 2) Avoid throwing an exception in a finally or...
Read more >
Error handling, "try...catch" - The Modern JavaScript Tutorial
So, an error inside the try {...} block does not kill the script – we have a chance to handle it in catch...
Read more >
Chapter 14. Blocks, Statements, and Patterns
This simple rule prevents the "dangling else " problem. The execution behavior of a statement with the "no short if " restriction is...
Read more >
Python Exceptions: An Introduction - Real Python
except is used to catch and handle the exception(s) that are encountered in the try clause. else lets you code sections that should...
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