-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule request: forbid control flow statements in finally #5808
Comments
Thank you for this issue. Indeed, ReturnStatements in a
I like this idea, but we need to wait for opinions of other members. |
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 |
Seems like a good idea. Does anyone want to champion this? @eslint/eslint-team @BYK we only change |
If |
👍 to @michaelficarra. Perhaps the rule could be called something like |
@nzakas - I know. I wanted to raise the flag to include this in 3.0.0 planning :) I can champion the rule. @onurtemizkan interested in implementing? |
Sure! 😄 |
Okay @BYK is championing this rule. Please work with @onurtemizkan to implement the rule using the new format. |
Did we decide on a rule name?
@onurtemizkan has started working on this. |
I could probably get behind any of those. I'll throw one more name into the
|
"Control flow" refers to anything that changes where execution flows, Including How about |
|
Okay, we'll leave this to @BYK and @onurtemizkan to implement. |
@michaelficarra I couldn't find a case for |
(function() {
label: try {
return 0;
} finally {
break label;
}
return 1;
})() |
Ah, okay. Thanks! |
Currently this rule isn't actually checking that breaks and continues are crossing the boundary of the let foo = function(a) {
try {
return 1;
} catch(err) {
return 2;
} finally {
switch(a) {
case 1: {
console.log("hola!")
break;
}
}
}
}; This also trips this rule, I think incorrectly: try {} finally {
while(true) {
break;
}
} I would not think the mere presence of control flow statements would be an issue: it's only control flow which crosses the boundary of the I can open an issue for this if people agree. |
@bakkot I agree with your logic. Please open a new issue and I will triage it as a bug right away. 😄 |
@bakkot Sorry, my bad. I can post a fix for this if you open an issue. |
Opened #5972. |
Does anyone have an in-the-wild example where flow control in a finally block caused an actual problem? (To me, the use of this rule seems intuitive, but I'd like to convince a skeptic.) |
Adding a
return
statement in afinally
block is a very confusing thing. Thrown errors get ignored,return
statements intry
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:
The text was updated successfully, but these errors were encountered: