-
Notifications
You must be signed in to change notification settings - Fork 186
New unreachable_code_linter #1003
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one might benefit from running on some packages in the wild. WDYT?
//FUNCTION | ||
/following-sibling::expr | ||
/*[ | ||
self::expr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is equivalent to using /expr
instead of /*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not quite, because position()
needs to include all nodes, not just expr
. I'll add a comment.
/*[ | ||
self::expr | ||
and expr[SYMBOL_FUNCTION_CALL[text() = 'return' or text() = 'stop']] | ||
and (position() != last() - 1 or not(following-sibling::OP-RIGHT-BRACE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: Does this cope properly with return in switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it doesn't -- just added an example test (commented out) to make sure I captured what you had in mind.
I think tryCatch()
is equally affected.
I recommend covering all the new linters together. FWIW, the linters have all been vetted on our internal code base (O(10k) files) so I'm reasonably confident about false positives. False negatives are something we can always improve iteratively. |
Part of #962
The current version of this works best alongside our
ExplicitReturnLinter()
, where terminal statements will already bereturn()
. The logic of nailing down the last expression in xpath is a bit of a mess so we avoided replicating it inside this linter. Now I'm wondering how useful this linter is without that added logic 🤔