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

Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional #2913

Closed
morozov opened this issue Mar 24, 2020 · 1 comment
Milestone

Comments

@morozov
Copy link
Contributor

morozov commented Mar 24, 2020

The issue is reproducible on PHP_CodeSniffer version 3.5.4. Consider the following code example and standard configuration:

<?php

if (true) {
    ?><?php echo addslashes(
        ''
    )?><?php
}
<ruleset>
    <rule ref="PSR2"/>
</ruleset>

The following violations are reported:

$ phpcs -s test.php

--------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------
 6 | ERROR | [x] Line indented incorrectly; expected at least 6 spaces, found 4
   |       |     (Generic.WhiteSpace.ScopeIndent.Incorrect)
--------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------

An attempt to auto-fix the file fails:

PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
/home/morozov/Projects/test/test.php                  FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------

The issue itself looks like a false positive since the expected number of spaces should be multiple of 4 (the tab width). The failure to fix most likely means that the sniff conflicts with some other (valid) sniff.

@gsherwood gsherwood added this to the 3.6.0 milestone Sep 21, 2020
@gsherwood gsherwood changed the title False positive and a failure to fix Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional Nov 17, 2020
gsherwood added a commit that referenced this issue Nov 17, 2020
…opening and closing tag on same line inside conditional
@gsherwood
Copy link
Member

The fix for this will be released in 3.6.0. Thanks for the bug report.

gsherwood added a commit that referenced this issue Nov 17, 2020
…opening and closing tag on same line inside conditional
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