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

PSR12.Operators.OperatorSpacing false positive #3098

Closed
morozov opened this issue Sep 4, 2020 · 0 comments · Fixed by #3099
Closed

PSR12.Operators.OperatorSpacing false positive #3098

morozov opened this issue Sep 4, 2020 · 0 comments · Fixed by #3099
Milestone

Comments

@morozov
Copy link
Contributor

morozov commented Sep 4, 2020

Describe the bug
The sniff doesn't recognize unary minus applied to a number used with theexit language construct.

Code sample

<?php

function test()
{
    exit -1;
}

Custom ruleset
None.

To reproduce
Steps to reproduce the behavior:

  1. Run phpcs -s --standard=PSR12 --sniffs=PSR12.Operators.OperatorSpacing test.php
FILE: /home/morozov/Projects/phpcs-playground/test.php
------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Expected at least 1 space after "-"; 0 found
   |       |     (PSR12.Operators.OperatorSpacing.NoSpaceAfter)
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------

Time: 33ms; Memory: 6MB
  1. Run phpcbf --standard=PSR12 --sniffs=PSR12.Operators.OperatorSpacing test.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
/home/morozov/Projects/phpcs-playground/test.php      1      0
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------

Time: 37ms; Memory: 6MB

The resulting file contents are:

<?php

function test()
{
    exit - 1;
}

Expected behavior
No error is reported.

Versions (please complete the following information):

  • OS: Linux
  • PHP: 7.4.9
  • PHPCS: 3.5.6
  • Standard: PSR-12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants