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.ControlStructures.ControlStructureSpacing not ignoring indentation inside multi-line string arguments #2623

Closed
dereuromark opened this issue Sep 30, 2019 · 3 comments

Comments

@dereuromark
Copy link
Contributor

if (preg_match(
            '(
                \*\s+[{}A-Z0-9\-]+.*\s+
                \*?\s*
                \*\s+@api
            )xi',
            $comment
        )) {
            return;
        }

reports

 86 | ERROR | [x] Each line in a multi-line control structure must be indented at least once; expected at least 12 spaces, but found 0
    |       |     (PSR12.ControlStructures.ControlStructureSpacing.LineIndent)
 88 | ERROR | [x] Each line in a multi-line control structure must be indented at least once; expected at least 12 spaces, but found 8
    |       |     (PSR12.ControlStructures.ControlStructureSpacing.LineIndent)
 88 | ERROR | [x] The closing parenthesis of a multi-line control structure must be on the line after the last expression
    |       |     (PSR12.ControlStructures.ControlStructureSpacing.CloseParenthesisLine)

but when running it

FAILED TO FIX

Using -vvv it seems that this is what it fixes it too, breaking other rules:

if (preg_match(
 82|            '(
 83|                \*\s+[{}A-Z0-9\-]+.*\s+
 84|                \*?\s*
 85|                \*\s+@api
 86|                                                                                                                                                                                                )xi',
 87|            $comment
 88|            )
 89|        ) {
 90|            return;
 91|        }
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Oct 1, 2019
@gsherwood gsherwood added this to the 3.5.1 milestone Oct 1, 2019
@gsherwood gsherwood moved this from Idea Bank to Backlog in PHPCS v3 Development Oct 1, 2019
@spaceemotion
Copy link

spaceemotion commented Oct 2, 2019

Not sure if this is related (if not, i can open up a new issue), but the following code gets completely broken in terms of layout:

Edit: Opened up #2635 instead

@gsherwood
Copy link
Member

Not sure if this is related (if not, i can open up a new issue), but the following code gets completely broken in terms of layout:

Different issue.

@gsherwood gsherwood changed the title Bug in multi line fixing PSR12.ControlStructures.ControlStructureSpacing not ignoring indentation inside multi-line string arguments Oct 3, 2019
gsherwood added a commit that referenced this issue Oct 3, 2019
… ignoring indentation inside multi-line string arguments
@gsherwood
Copy link
Member

Thanks for the report. The sniff was not ignoring multi-line string arguments and so was complaining about indentation and conflicting with other rules.

The sample code is now fixed like this:

<?php
if (
    preg_match(
        '(
                \*\s+[{}A-Z0-9\-]+.*\s+
                \*?\s*
                \*\s+@api
            )xi',
        $comment
    )
) {
            return;
}

PHPCS v3 Development automation moved this from Backlog to Ready for Release Oct 3, 2019
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