no-else-return rule should work in try-catch block
See original GitHub issueTell 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:
- Created 4 years ago
- Comments:16 (14 by maintainers)
Top 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 >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
I would like to work on this, could you please assign this issue to me?
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.