-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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-else-return doesn't trigger for else if. #9228
Comments
I believe this is working as designed. With an |
@platinumazure not in the example I gave. |
@platinumazure can you give a code example of what you mean and I'll add it to my tests? |
No, I see the hook in your example. I'm not sure how easy it will be to enhance the rule for your case without potentially breaking other cases, but that's why we have unit tests. |
The hook? |
I'm pretty sure that's not true. If you transform the code to explicit block statements no-else-return detects it correctly |
Sorry- I see what I had missed. I see why you are asking if the rule should be enhanced. I'm worried about what rabbit hole we might be opening up if we expand these cases too much. I guess in general, we could conceivably flag all if (foo) return true;
else if (bar) { return true; } // can't be flagged due to next line?
else if (baz) { doSomething(); return true; }
else if (x) return true; // could be flagged?
else if (y) { return true; } // could be flagged? I think the team might just decide that the rule is only designed to handle the specific case of |
So it does. I stand corrected. I think we can accept this as a bug. Please feel free to continue work on your PR and thanks for your patience! |
@platinumazure fyi, with explicit block statements eslint flags them all. |
Without else: () => {
if (foo) {
return true;
}
if (bar) {
return true;
}
if (baz) {
doSomething();
return true;
}
if (x) {
return true;
}
if (y) {
return true;
}
} And here it is without an extra return Which cases eslint not to flag it. |
@platinumazure is there a way to run only one test? Currently it takes too long to drop to a debugger on one rule test. |
@graingert Use Mocha's |
@platinumazure how do I get it to skip running eslint on itself? |
Just run Mocha directly: ./node-modules/mocha/bin/_mocha tests/lib/rules/no-else-return.js --grep "Name of test" |
@platinumazure thanks, that was super handy. |
@platinumazure I've taken my PR out of WIP and it's ready for review. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using? see config
Please show your full configuration: see eslint demo URLs.
What did you do? Please include the actual source code causing the issue.
What did you expect to happen?
no-else-return should trigger.
What actually happened? Please include the actual, raw output from ESLint.
no-else-return did not trigger.
Demo urls:
doesn't detect error
does detect error
The text was updated successfully, but these errors were encountered: