-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[PROPOSAL] Disallow empty if and else blocks #3408
Comments
Oops, I meant to post this to |
@jlherren Just so you know, the if ($true) {
} elseif($bar) {
} else {
// Do something.
}
|
Thanks for the hint. I always find it somewhat hard to discover what sniffs already exists. I've created #3409 to improve it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to propose a sniff that detects empty
if
andelse
blocks, since they never make any sense. Adding a comment inside the empty block would suppress the error, similar toDisallowEmptyFunctionSniff
.Empty
elseif
blocks can sometimes make sense if followed by otherelseif
s or anelse
.Perhaps the sniff could even be fixable by extracting side-effects of the condition, however, it would be more useful if we can detect whether there are any side-effects at all, which I'm not sure is possible in phpcs.
The text was updated successfully, but these errors were encountered: