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 Generic.WhiteSpace.SpreadOperatorSpacingAfter sniff (PSR12 related) #2548

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jul 10, 2019

This introduces a new sniff which checks the whitespace between the spread operator and the variable/function call it applies to.

This new sniff has two public properties:

  • $spacing which defaults to 0, i.e. no space.
  • $ignoreNewlines which defaults to false.

Includes unit tests.
Includes fixers.
Includes documentation.

Includes adding this sniff to the PSR12 ruleset.

Note: PSR12 only specifies There MUST NOT be a space between the variadic three dot operator and the argument name for function declarations.

This sniff, however, checks the spacing for the spread operator in all circumstances in which it can be used, i.e.:

  • In function declarations (PHP 5.6).
  • In function calls (PHP 5.6).
  • In array declarations (PHP 7.4).

@gsherwood
Copy link
Member

I'm not sure I can actually include this in PSR12 because people tend to get angry when PHPCS enforces rules that the standard doesn't explicitly describe. But it's a very useful sniff regardless.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 17, 2019

Yes, I noticed you'd added a different sniff for PSR12. Shall I remove the PSR12 ruleset change from the PR so this can be merged for anyone who does want a more extensive check for the spread operator ?

@gsherwood
Copy link
Member

Shall I remove the PSR12 ruleset change from the PR so this can be merged for anyone who does want a more extensive check for the spread operator ?

Yes please, if you have time.

@jrfnl jrfnl force-pushed the feature/new-spread-operator-spacing-sniff branch from b6fb00f to 5c82a94 Compare September 17, 2019 01:24
@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 17, 2019

Easy-peasy. Done.

This introduces a new sniff which checks the whitespace between the spread operator and the variable/function call it applies to.

This new sniff has two `public` properties:
* `$spacing` which defaults to `0`, i.e. no space.
* `$ignoreNewlines` which defaults to `false`.

Includes unit tests.
Includes fixers.
Includes documentation.

Note: PSR12 only specifies _There MUST NOT be a space between the variadic three dot operator and the argument name_ for **function declarations**.

This sniff, however, checks the spacing for the spread operator in all circumstances in which it can be used, i.e.:
* In function declarations (PHP 5.6).
* In function calls (PHP 5.6).
* In array declarations (PHP 7.4).
gsherwood added a commit that referenced this pull request Sep 19, 2019
@gsherwood gsherwood merged commit 5c82a94 into squizlabs:master Sep 19, 2019
@gsherwood
Copy link
Member

Thanks a lot for making that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants