Skip to content

[PROPOSAL] Disallow empty if and else blocks #3408

@jlherren

Description

@jlherren

I'd like to propose a sniff that detects empty if and else blocks, since they never make any sense. Adding a comment inside the empty block would suppress the error, similar to DisallowEmptyFunctionSniff.

Empty elseif blocks can sometimes make sense if followed by other elseifs or an else.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions