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.Formatting.MultipleStatementAlignment wrong error for assign in string concat #2529

Closed
sertand opened this issue Jun 14, 2019 · 5 comments

Comments

@sertand
Copy link
Member

sertand commented Jun 14, 2019

If you have:

$i = 0;
echo "TEST: ".($i += 1)."\n";

You get this error:

Equals sign not aligned with surrounding assignments; expected 17 spaces but found 1 space (Generic.Formatting.MultipleStatementAlignment.NotSame)

Expected to be no errors

@sertand sertand added this to Backlog in PHPCS v3 Development via automation Jun 14, 2019
@sertand sertand added this to the 3.5.0 milestone Jun 14, 2019
@sertand sertand self-assigned this Jun 14, 2019
@jrfnl
Copy link
Contributor

jrfnl commented Jun 14, 2019

@sertand Got another false positive for you if you're working on that sniff anyway:

$phrase = 'phrase';
if ($a === true)
    if ($b === true)
        $phrase = 'another phrase';
else
    $phrase = 'different phrase';

@gsherwood gsherwood changed the title Generic.Formatting.MultipleStatementAlignment reports wrong error for assignments in string concatenation Generic.Formatting.MultipleStatementAlignment wrong error for assign in string concat Aug 9, 2019
gsherwood added a commit that referenced this issue Aug 9, 2019
… error for assign in string concat

Decided is was easiest to ignore assignment that are in parenthesis on the same line
@gsherwood
Copy link
Member

I've fixed this specific issue, so am going to close.

Got another false positive for you if you're working on that sniff anyway:

This is not a sniff issue. The tokenizer is not assigning any of the assignment operations to the IF or ELSE statements due to the lack of braces. There is nothing the sniff can do to detect this and it would impact other sniffs as well. I have no idea how to fix it, so it would be good to open a new issue for this one.

PHPCS v3 Development automation moved this from Backlog to Ready for Release Aug 9, 2019
@jrfnl
Copy link
Contributor

jrfnl commented Aug 9, 2019

This is not a sniff issue. The tokenizer is not assigning any of the assignment operations to the IF or ELSE statements due to the lack of braces. There is nothing the sniff can do to detect this and it would impact other sniffs as well. I have no idea how to fix it, so it would be good to open a new issue for this one.

Will do.

I was actually thinking along the lines of a check that if the next assignment is not on the next line, the assignment block has ended. Could that work in your opinion ?

@gsherwood
Copy link
Member

I was actually thinking along the lines of a check that if the next assignment is not on the next line, the assignment block has ended. Could that work in your opinion ?

You've got me thinking now. I don't know why it doesn't already do that - I thought that's how it worked. The sniff is a mess and hard to read, but I don't have time to rewrite it, so I'll just keep digging and see if it is supposed to do this. Thanks.

@gsherwood
Copy link
Member

I don't know why it doesn't already do that

I know why. It only considers a blank line the end of the code block. This is so it doesnt get confused if some of the assignments are multi-line, like in the case of closures.

It might be possible to rewrite this check so it skips to the end of the statement and continues checking from there, but I'm worried it would still be tripped up by the code sample above. I think it's best to try and fix the tokenizer itself, although a lot harder.

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

No branches or pull requests

3 participants