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-unreachable
reports EmptyStatements
#9081
Comments
What happens if you remove the unnecessary semicolon after the |
holy shit. |
ya i think it shouldn't also that's legitimately it and i think i just caught on fire pardon me, calling the burn team |
note: had removed the semicolon @ljharb is talking about as a cleanliness detail before he spoke up, without retesting it if he hadn't responded so ridiculously quickly i would have actually accidentally blown the test case |
Seems like the bug is that |
test case restored |
@ljharb Yeah, it would be nice for |
I'll work on this. |
no-unreachable will only report if there is at least one non-EmptyStatement node in the range
no-unreachable
difference correct?no-unreachable
reports EmptyStatements
Just link to a previous discussion: #6295 |
Hmm. Apparently I was in favor of changing the lint message rather than not reporting at that time. Thanks @mysticatea for finding that discussion. I'd be okay with modifying my PR to just change the lint message if there are only EmptyStatements in the range (and continuing to report entire ranges including EmptyStatements when there is at least one statement that is not an EmptyStatement). Just not sure what's the best approach here. |
I think it makes no sense at all for no-unreachable to consider EmptyStatements at all. It's not about whether a semi after a switch makes sense (it doesn't), but that's something only no-semi should warn on. Empty statements contain no code, therefore there's nothing unreachable in them, from an intuition standpoint. I should be able to use |
I would be okay with either outcome, but I agree with ljharb: if there isn't any unreachable code (empty statements are not code in my mind,) then this rule should not fire IMO |
@ljharb @StoneCypher You may wish to check out my pull request (see #9084). Basically, what happens is, EmptyStatements are included in a reported range as unreachable code, but if the entire block of "unreachable code" consists solely of EmptyStatements, then it's not reported at all. So basically, my approach is a good balance of practicality (don't report code that won't do anything) and accuracy (but do report all of the unreachable code when some or all of that code is non-empty). If you think that behavior is unreasonable, feel free to leave a comment here or there. But I'm fairly sure this approach gets you what you want, in terms of the clear priority. |
That sounds perfectly reasonable to me! |
As someone who has never contributed to this codebase, that sounds approximately ideal to me. Thanks for the inclusion and thanks for the rapid response. |
@ljharb @StoneCypher 👍, I'll request reviews on my pull request with the current behavior. |
@platinumazure Where does this issue stand right now? |
I ended up closing my PR as not the desired direction. I am not currently working on this. Contributions would be most welcome. Thanks! |
I'll work on this. |
thanks |
Thank you for a wonderful tool. Most times I think I find a bug, instead I learn a JS horror detail.
Can't figure this one out yet. Don't think it's env related.
Please show your full configuration:
Configuration
eslint-config-stonecypher
in turn configures every current eslint rule, pluseslint-plugin-
...flowtype
,fp
,jsdoc
,ava
,unicorn
,new-with-error
, andpromise
What did you do? Please include the actual source code causing the issue.
The following code triggers "no-unreachable" at the end of the switch, even though it's the last action in a default, ostensibly because of the
throw
.What did you expect to happen?
Nothing. No code follows the
throw
.This similar code does not trigger the warning, I expect because the throw is now outside the switch.
What actually happened? Please include the actual, raw output from ESLint.
It's not like it's a big deal, or anything. I moved the throws outside of the switch afterwards anyway, because in retrospect it's sorta gross.
It's just surprising, and I wonder whether it's legitimately a subtle bug.
Please have a nice day.
The text was updated successfully, but these errors were encountered: