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
no-useless-return has a false negative with try/catch #7481
Comments
Thank you for this issue. In fact, this is caused by the current code path analyzer. |
When linting this code: try { a; b; c; } catch (e) {} I got this code path: DOTdigraph {
node[shape=box,style="rounded,filled",fillcolor=white];
initial[label="",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];
final[label="",shape=doublecircle,style=filled,fillcolor=black,width=0.25,height=0.25];
s1_1[label="Program\nTryStatement\nBlockStatement\nExpressionStatement\nIdentifier (a)\nIdentifier:exit (a)"];
s1_2[label="ExpressionStatement\nIdentifier (b)\nExpressionStatement\nIdentifier (c)\nExpressionStatement:exit\nIdentifier:exit (b)\nExpressionStatement:exit\nIdentifier:exit (c)\nExpressionStatement:exit\nBlockStatement:exit"];
s1_4[label="TryStatement:exit\nProgram:exit"];
s1_3[label="CatchClause\nIdentifier (e)\nBlockStatement\nIdentifier:exit (e)\nBlockStatement:exit\nCatchClause:exit"];
initial->s1_1->s1_2->s1_4;
s1_1->s1_3->s1_4->final;
} But I expected to get something like this: DOTdigraph {
node[shape=box,style="rounded,filled",fillcolor=white];
initial[label="",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];
final[label="",shape=doublecircle,style=filled,fillcolor=black,width=0.25,height=0.25];
s1_1[label="Program\nTryStatement\nBlockStatement\nExpressionStatement\nIdentifier (a)"];
s1_2[label="Identifier:exit (a)\nExpressionStatement:exit\nExpressionStatement\nIdentifier (b)"];
s1_3[label="Identifier:exit (b)\nExpressionStatement:exit\nExpressionStatement\nIdentifier (c)"];
s1_4[label="Identifier:exit (c)\nExpressionStatement:exit\nBlockStatement:exit"];
s1_5[label="CatchClause\nIdentifier (e)\nBlockStatement\nIdentifier:exit (e)\nBlockStatement:exit\nCatchClause:exit"];
s1_6[label="TryStatement:exit\nProgram:exit"];
initial->s1_1->s1_2->s1_3->s1_4->s1_6;
s1_1->s1_5->s1_6->final;
s1_2->s1_5;
s1_3->s1_5;
} Is it intentional that each |
Yes, it's intentional because I thought that making every throwable path is too many. #3559 (comment) I'm sorry for I have not done this. |
I see, that makes sense.
|
It makes sense if we avoid making throwable path at references which never throw. |
Actually, I suppose the second solution wouldn't resolve this issue because something like this would still report an error: try {
foo();
return;
} catch (err) {
foo();
} |
@mysticatea @not-an-aardvark are either of you interested in addressing this? |
Friendly ping |
I have free time until 1st december, can I go for it @mysticatea ? Any tip will be very appreciate 😄
|
@guilhermejcgois they have long since left the project. You are welcome to pick this up. |
Promote up the useless returns in BlockStatement inside TryStatement when ESLint is going up in the tree during traversing the AST. Fixes eslint#7481
Promote up the useless returns in BlockStatement inside TryStatement when ESLint is going up in the tree during traversing the AST. Fixes eslint#7481
Promote up the useless returns in BlockStatement inside TryStatement when ESLint is going up in the tree during traversing the AST. Fixes eslint#7481
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
This has an open PR, #16693 |
Update:
|
Looks like we will need help finishing up the PR for this. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
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.
The text was updated successfully, but these errors were encountered: