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.Incorrect issue after NOWDOC #2883

Closed
JeroenBakker opened this issue Feb 28, 2020 · 3 comments
Closed

Generic.WhiteSpace.ScopeIndent.Incorrect issue after NOWDOC #2883

JeroenBakker opened this issue Feb 28, 2020 · 3 comments

Comments

@JeroenBakker
Copy link

Hi there,

I'm having an issue where phpcs is complaining about my indentation level in a nested array.
It seems to be caused by a NOWDOC or HEREDOC and then the issue crops up somewhere after a multi-line array

This is using phpcs version 3.5.4

The following array reproduces this issue:

return [
    'lor' =>
        // Without this NOWDOC everything works fine
        <<<'INTRO'
        lorem ipsum
        INTRO,
    'em' => [
        // Without this multiline array everything works fine
        [
            '',
        ],
    ],
    // Every toplevel array key from here is being flagged as being incorrectly indented
    'abc' => [
        'a' => 'wop wop',
        'b' => 'ola ola.',
    ],
];

The full error is:

 Line indented incorrectly; expected at least 8 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.Incorrect)

If I were to attempt to fix this with phpcbf it adds the indentation and throws the next error:

Array key not indented correctly; expected 4 spaces but found 8 (Generic.Arrays.ArrayIndent.KeyIncorrect)

Any further attempts to fix this just go back and forth between the two.

If you need any further details please let me know!

@BackEndTea
Copy link

Could you check what happends when the , after the nowdoc is on another line (or completely missing)?

@JeroenBakker
Copy link
Author

Good find, if the trailing comma after the NOWDOC closing tag is moved to the next line the issue goes away.

That's ugly though 😛

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Mar 8, 2020
@gsherwood gsherwood added this to the 3.5.6 milestone Mar 8, 2020
@gsherwood gsherwood moved this from Idea Bank to Selected for Development in PHPCS v3 Development May 21, 2020
@gsherwood gsherwood modified the milestones: 3.5.6, 3.5.7 Jun 22, 2020
gsherwood added a commit that referenced this issue Aug 20, 2020
…r NOWDOC

Stopping at the end of a here/nowdoc when finding the start of a statement isn't correct.
These token have openers/closers to help sniff developers, but they are still strings
and should be skipped over in the same way.
gsherwood added a commit that referenced this issue Aug 20, 2020
…r NOWDOC

Stopping at the end of a here/nowdoc when finding the start of a statement isn't correct.
These token have openers/closers to help sniff developers, but they are still strings
and should be skipped over in the same way.
gsherwood added a commit that referenced this issue Aug 20, 2020
@gsherwood
Copy link
Member

I've committed a fix for this problem. The core issue is the the end of the nowdoc was seen as the end of that statement, whereas the comma should really be the end. The whitespace sniff specifically tries to ignore commas to cover cases like this, but the nowdoc issue was stopping that from working.

Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

No branches or pull requests

3 participants