Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Rule request: forbid return in finally #1097

Closed
louy opened this issue Apr 8, 2016 · 3 comments
Closed

Rule request: forbid return in finally #1097

louy opened this issue Apr 8, 2016 · 3 comments

Comments

@louy
Copy link
Contributor

louy commented Apr 8, 2016

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
@adidahiya
Copy link
Contributor

sounds reasonable. is there any analogous rule for ESLint? if not, that's cool too

@louy
Copy link
Contributor Author

louy commented Apr 8, 2016

not yet. eslint/eslint#5808

jkillian pushed a commit that referenced this issue Jul 21, 2016
…1349)

* Implement rule to forbid return statements in finally blocks #1097

* explore the try statement fully to pick up violations in nested scopes

* switch to a scope aware rule walker to reduce number of passes over the AST

* Add support for other control flow statements in finally blocks (break, continue, throws)

* improve the rationale description for the no unsafe finally rule

* rename rule to no-unsafe-finally to be inline with eslint

* add new rule to latest config

* pull out helper functions from the walker class.

* fix tslint violations (which didn't occur locally)
soniro pushed a commit to soniro/tslint that referenced this issue Aug 31, 2016
…#1097 (palantir#1349)

* Implement rule to forbid return statements in finally blocks palantir#1097

* explore the try statement fully to pick up violations in nested scopes

* switch to a scope aware rule walker to reduce number of passes over the AST

* Add support for other control flow statements in finally blocks (break, continue, throws)

* improve the rationale description for the no unsafe finally rule

* rename rule to no-unsafe-finally to be inline with eslint

* add new rule to latest config

* pull out helper functions from the walker class.

* fix tslint violations (which didn't occur locally)
@andy-hanson
Copy link
Contributor

Should be fixed by #1349.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants