Skip to content

Commit

Permalink
Fix TrailingCommaMultiLine when there is no elements (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Nov 6, 2024
1 parent 4f482ed commit 595fe48
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Rules/Punctuation/TrailingCommaMultiLineRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ protected function process(int $tokenIndex, Tokens $tokens): void
return;
}

$isMatchingComma = $tokens->get($previous)->isMatching(Token::PUNCTUATION_TYPE, ',');
$previousToken = $tokens->get($previous);
if ($previousToken === $token->getRelatedToken()) {
// There is no element, so adding a trailing comma will break the code.
return;
}

$isMatchingComma = $previousToken->isMatching(Token::PUNCTUATION_TYPE, ',');
if ($this->useTrailingComma === $isMatchingComma) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@
1
+ 2
) }}

{% set emptyArray = [
] %}
{% set emptyObject = {
} %}
{{ emptyCall(
) }}
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@
1
+ 2
) }}

{% set emptyArray = [
] %}
{% set emptyObject = {
} %}
{{ emptyCall(
) }}
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@
1
+ 2
) }}

{% set emptyArray = [
] %}
{% set emptyObject = {
} %}
{{ emptyCall(
) }}

0 comments on commit 595fe48

Please sign in to comment.