-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Squiz.WhiteSpace.LanguageConstructSpacing does not properly check for tabs and newlines #1573
Squiz.WhiteSpace.LanguageConstructSpacing does not properly check for tabs and newlines #1573
Conversation
It could be another whitespace character, like "\t", "\n", ... Now it will be always converted to space.
@gmponos please have a look |
@@ -30,3 +30,10 @@ return; | |||
return $blah; | |||
return $blah; | |||
return($blah); | |||
|
|||
return $tab; | |||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this change here will raise a lot of issues. According to my understanding (maybe I am wrong) the goal of this sniff is to ensure that there are no two spaces between language constructs and $variables/functions etc.
So as I understand it the goal is to avoid this:
return ['test' => 'value'];
and not this:
return
[
'test' => 'value'
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have right, but sniff description says:
Ensures all language constructs contain a single space between themselves and their content.
And I think that it is exactly what the sniff should do, we didn't have covered that case previously in tests, so I think @gsherwood is gonna decide what to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be avoided by checking for ' ' or $phpcsFile->eolChar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To work around this problem, you can use:
return (
[
'test' => 'value'
]
);
Edit: Or just:
return [
'test' => 'value'
];
But in my case I have stuff like:
return
$qb->from(Entities\Player::class, 'p')
->leftJoin('p.user', 'u')
->select('p', 'u')
->where('CASE WHEN p.name IS NULL THEN u.username ELSE p.name END = ?1')
->setParameter(1, $name)
->getQuery()
->getOneOrNullResult();
... so the parentheses work better.
$content = $tokens[($stackPtr + 1)]['content']; | ||
if ($content !== ' ') { | ||
$error = 'Language constructs must be followed by a single space; expected 1 space but found "%s"'; | ||
$data = array($tokenContent = Util\Common::prepareForOutput($content)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I avoid assignments that can be tricky to the eye. I would've added the assignment on a different line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I see it more carefully the $tokenContent
is not used anywhere. So why is it assinged to a variable first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my mistake, the variable shouldn't be there, thanks. Now removed.
return $tab; | ||
return | ||
$newLine; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is gonna be merged I believe it should cover one more test case. What happens if there is a single space after return and then a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gsherwood can you check on this PR I need for another one? |
The intention of this sniff is for a newline to be banned. That's why a return followed by |
Thanks for this fix. |
As we discussed in #1337 (comment) I've created this PR to issues noted in PR #1337