Rule request: forbid control flow statements in finally
See original GitHub issueAdding a return
statement in a finally
block is a very confusing thing. Thrown errors get ignored, return
statements in try
blocks get ignored, and your mind explodes.
I’d love to have a rule to forbid this. Especially now that we’re having async
/await
.
examples:
try {
return 1;
} catch(err) {
return 2;
} finally {
return 3;
}
// > 3
try {
throw new Error;
return 1;
} catch(err) {
return 2;
} finally {
return 3;
}
// > 3
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:21 (20 by maintainers)
Top Results From Across the Web
no-unsafe-finally - Pluggable JavaScript Linter - ESLint
This rule disallows return , throw , break , and continue statements inside finally blocks. It allows indirect usages, such as in function...
Read more >Control flow is not passing over to finally block if exception ...
When an exception occur the program crashes without passing control to the finally block as it is understood that finally block must be...
Read more >PEP 601: Forbid return/break/continue breaking out of finally
Aim of the PEP 601 is forbid return, break and continue statements within a finally suite where they would break out of the...
Read more >Return statements in finally blocks are forbidden
JavaScript suspends the control flow statements of try and catch blocks until the execution of finally block finishes. So, when return, throw, break,...
Read more >Control Flow — The Swift Programming Language (Swift 5.7)
These include while loops to perform a task multiple times; if , guard , and switch statements to execute different branches of code...
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
“Control flow” refers to anything that changes where execution flows, Including
if
,while
, etc., so it’s a bit broad for this use case.How about
no-unsafe-finally
?I’m 👍 since this is a core language issue and a pitfall quite easy to fall into without realizing consequences. We should add this to
eslint:recommended
too IMO.