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
NoTrailingCommaInSinglelineFunctionCallFixer - Introduction #6304
NoTrailingCommaInSinglelineFunctionCallFixer - Introduction #6304
Conversation
Now we have 4 places we remove trailing comma in single line stuff:
Can we go instead with one fixer like there is trailing_comma_in_multiline? |
We could if someone wants to raise the PR and do all the paperwork around deprecations and such. For me it is 50/50, it makes sense to have it done by for example |
private function clearCommaIfNeeded(Tokens $tokens, int $startIndex, int $endIndex, int $commaIndex): void | ||
{ | ||
if (!$tokens->isPartialCodeMultiline($startIndex, $endIndex)) { | ||
$tokens->clearTokenAndMergeSurroundingWhitespace($commaIndex); |
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.
Why this way, not:
$tokens->removeTrailingWhitespace($beforeEndIndex);
$tokens->clearAt($beforeEndIndex);
as it's done in NoTrailingCommaInSinglelineArrayFixer
?
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.
not sure I follow, what would be the benefit?
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.
Consistency, better fixing - now code:
$a = [1, 2, 3, ];
foo(1, 2, 3, );
would be changed to:
$a = [1, 2, 3];
foo(1, 2, 3 );
I cannot imagine anyone want to have the comma removed and keep it's trailing whitespace.
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.
check, I didn't even know removeTrailingWhitespace
existed, I think your case is covered through single-responsibility of the rule combined with priorities, but if there is more room for improvement than lets PR it.
closes #6141