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.

Rule request: forbid control flow statements in finally

See original GitHub issue

Adding 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:21 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
nzakascommented, Apr 15, 2016

“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?

2reactions
BYKcommented, Apr 8, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

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