Skip to content

Commit 10a23da

Browse files
🐛 Fix delimiter spacing for comment with new line
1 parent 6437a6d commit 10a23da

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

TwigCS/src/Sniff/AbstractSpacingSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private function checkSpaceAfter(int $tokenPosition, array $tokens, int $expecte
6565

6666
// Ignore new line
6767
$next = $this->findNext(Token::WHITESPACE_TOKENS, $tokens, $tokenPosition + 1, true);
68-
if (false !== $next && $this->isTokenMatching($tokens[$next], Token::EOL_TYPE)) {
68+
if (false !== $next && $this->isTokenMatching($tokens[$next], [Token::EOL_TYPE, Token::COMMENT_EOL_TYPE])) {
6969
return;
7070
}
7171

@@ -106,7 +106,7 @@ private function checkSpaceBefore(int $tokenPosition, array $tokens, int $expect
106106

107107
// Ignore new line
108108
$previous = $this->findPrevious(Token::WHITESPACE_TOKENS, $tokens, $tokenPosition - 1, true);
109-
if ($this->isTokenMatching($tokens[$previous], Token::EOL_TYPE)) {
109+
if ($this->isTokenMatching($tokens[$previous], [Token::EOL_TYPE, Token::COMMENT_EOL_TYPE])) {
110110
return;
111111
}
112112

TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.fixed.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
{{
1010
shouldNotCareAboutNewLine
1111
}}
12+
{#
13+
shouldNotCareAboutNewLine
14+
#}
1215
{%- if foo -%}{%- endif -%}
1316

1417
{{ foo({'bar': {'baz': 'shouldNotCareAboutDoubleHashes'}}) }}

TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class DelimiterSpacingTest extends AbstractSniffTest
1818
public function testSniff(): void
1919
{
2020
$this->checkSniff(new DelimiterSpacingSniff(), [
21-
[12 => 1],
22-
[12 => 12],
23-
[12 => 15],
24-
[12 => 25],
21+
[15 => 1],
22+
[15 => 12],
23+
[15 => 15],
24+
[15 => 25],
2525
]);
2626
}
2727
}

TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
{{
1010
shouldNotCareAboutNewLine
1111
}}
12+
{#
13+
shouldNotCareAboutNewLine
14+
#}
1215
{%-if foo -%}{%- endif-%}
1316

1417
{{ foo({'bar': {'baz': 'shouldNotCareAboutDoubleHashes'}}) }}

0 commit comments

Comments
 (0)