squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.68k stars 1.48k forks source link

Squiz.WhiteSpace.OperatorSpacing incorrectly adds space after bitwise operator #3922

Closed kkmuffme closed 1 year ago

kkmuffme commented 1 year ago

Describe the bug

Space added before bitwise or

Code sample

array_multisort(
    array_column( $test, 's' ),
    SORT_DESC,
    SORT_NATURAL|SORT_FLAG_CASE,
    $test
);

Custom ruleset

Using WordPress https://github.com/WordPress/WordPress-Coding-Standards

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
    Squiz.WhiteSpace.OperatorSpacing:216 replaced token 49 (T_BITWISE_OR on line ...

With phpcbf it get's autofixed to

array_multisort(
    array_column( $test, 's' ),
    SORT_DESC,
    SORT_NATURAL |SORT_FLAG_CASE,
    $test
);

Expected behavior

No error/change.

Afaik this worked correctly before.

Versions (please complete the following information)

Operating System Linux
PHP version 8.2
PHP_CodeSniffer version 3.7.2
Standard WordPress (however the error is in Squiz)
Install type composer

Please confirm:

jrfnl commented 1 year ago

Closing as invalid. This behaviour is unchanged. I've tested all the way back to PHPCS 2.6.0 and also tested with WPCS 2.3.0.

kkmuffme commented 1 year ago

But it's still wrong - there's no code standard that wants a space before a binary or, is there?

jrfnl commented 1 year ago

But it's still wrong - there's no code standard that wants a space before a binary or, is there?

No, it's not wrong. Nearly all sniffs are opinionated in one way or another. Clearly the standard you are using is of the opinion that there should be a space as they selected and enabled this sniff.