no-useless-return has a false negative with try/catch
See original GitHub issueTell us about your environment
- ESLint Version: 3.9.0
- Node Version: 6.9.1
- npm Version: 3.10.8
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
rules:
no-useless-return: error
What did you do? Please include the actual source code causing the issue.
function foo() {
try {
return;
} catch (err) {
foo();
}
}
What did you expect to happen?
This should report an error, because the return
statement can be safely removed.
What actually happened? Please include the actual, raw output from ESLint.
No error.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
Error handling, "try...catch" - The Modern JavaScript Tutorial
The try...catch construct has two main blocks: try , and then catch : ... code below returns an error for negative or non-integer...
Read more >How to write trycatch in R - exception - Stack Overflow
As we've specified that NA should be returned in case of error, the third element in y is NA . If we'd have...
Read more >Error handling in R with tryCatchLog: Catching, logging, post ...
Use tryCatch to handle errors. With tryCatch you can handle errors as you want: an.error.occured <- FALSE ...
Read more >no-useless-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 >disable no-useless-catch
unnecessary try/catch wrapper no-useless-catch. A catch clause that only rethrows the original error is redundant, and has no effect on the runtime behavior ......
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
Thank you for this issue.
In fact, this is caused by the current code path analyzer. Since the analyzer cannot know the places which throw exceptions, it generates 2 code paths which go to the
catch
block from both the first statement and the last statement in thetry
block (edit: and fromthrow
statements). But in this case, thereturn;
statement throws no exception clearly. I will investigate to improve the code path.This has an open PR, #16693