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

False Positiv PSR12.Operators.OperatorSpacing.NoSpaceAfter #3180

Closed
puggan opened this issue Dec 7, 2020 · 3 comments
Closed

False Positiv PSR12.Operators.OperatorSpacing.NoSpaceAfter #3180

puggan opened this issue Dec 7, 2020 · 3 comments

Comments

@puggan
Copy link

puggan commented Dec 7, 2020

Describe the bug
Using "-" or "+" to force an string to a numeric value, sometimes triggers PSR12.Operators.OperatorSpacing.NoSpaceAfter.
In the exemple bellow it's triggered on the concatination rows, but not the other 2 rows.

Code sample

$string = '3';
echo 'Pos: ', +$string, PHP_EOL; // ok
echo 'Neg: ', -$string, PHP_EOL; // ok
echo 'Pos: ' . +$string . PHP_EOL; // PSR12.Operators.OperatorSpacing.NoSpaceAfter
echo 'Neg: ' . -$string . PHP_EOL; // PSR12.Operators.OperatorSpacing.NoSpaceAfter

Custom ruleset
--standard=PSR12

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs --standard=PSR12 test.php
  3. See error message displayed
FILE: /..../test.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 6 | ERROR | [x] Expected at least 1 space after "+"; 0 found
 7 | ERROR | [x] Expected at least 1 space after "-"; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Expected behavior
consistent.
Trigger on zero or all four of the rows,
I myself prefer if zero of the above rows trigger.

Versions (please complete the following information):

  • OS: Ubuntu 20.10
  • PHP: 7.4.9
  • PHPCS: 3.5.8
  • Standard: PSR12

Additional context
Looks related to #2696

@jrfnl
Copy link
Contributor

jrfnl commented Dec 7, 2020

Duplicate of #3170, a patch for this has already been merged and will be included in the PHPCS 3.6.0 release.
Suggest: close.

@puggan puggan closed this as completed Dec 7, 2020
@puggan
Copy link
Author

puggan commented Dec 7, 2020

The added test seams to only regard the "-" version, but I assume the fix also fixes the "+" version.
Maybe there should be test for the "+" version too.

@jrfnl
Copy link
Contributor

jrfnl commented Dec 7, 2020

The logic is no different for + or -, so no additional test is needed.

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

No branches or pull requests

2 participants