Skip to content

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

Closed
@morozov

Description

@morozov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions