Skip to content
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

New Universal.ControlStructures.DisallowLonelyIf sniff #85

Merged
merged 1 commit into from
Feb 28, 2021

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 28, 2021

Sniff to disallow if statements as the only statement in an else block.

Inspired by the ESLint "no lonely if" rule in response to upstream PHPCS issue squizlabs/PHP_CodeSniffer#3206.

The sniff, as well as the fixer, will handle both curly brace if/else control structures as well as alternative syntax - if/else/endif - control structures correctly.
Inline control structures, i.e. without curly braces and not using alternative syntax, will be ignored by the sniff.

Note: This sniff will not fix the indentation of the "inner" code. It is strongly recommended to run this sniff together with the Generic.WhiteSpace.ScopeIndent sniff to get the correct indentation.

Includes fixer.
Includes unit tests.
Includes documentation.

Sniff to disallow `if` statements as the only statement in an `else` block.

Inspired by the [ESLint "no lonely if"](https://eslint.org/docs/rules/no-lonely-if) rule in response to upstream PHPCS issue 3206.

The sniff, as well as the fixer, will handle both curly brace if/else control structures as well as alternative syntax - if/else/endif - control structures correctly.
Inline control structures, i.e. without curly braces and not using alternative syntax, will be ignored by the sniff.

Note: This sniff will not fix the indentation of the "inner" code. It is strongly recommended to run this sniff together with the `Generic.WhiteSpace.ScopeIndent` sniff to get the correct indentation.

Includes fixer.
Includes unit tests.
Includes documentation.
@jrfnl jrfnl force-pushed the feature/phpcs-3206-no-lonely-if branch from fc6b956 to 8fc9ad1 Compare February 28, 2021 02:51
@jrfnl jrfnl merged commit a05ec49 into develop Feb 28, 2021
@jrfnl jrfnl deleted the feature/phpcs-3206-no-lonely-if branch February 28, 2021 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant