From 10a23da985d0eca59194489f3c87823169187095 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 26 Apr 2020 20:15:46 +0200 Subject: [PATCH] :bug: Fix delimiter spacing for comment with new line --- TwigCS/src/Sniff/AbstractSpacingSniff.php | 4 ++-- .../DelimiterSpacing/DelimiterSpacingTest.fixed.twig | 3 +++ .../Generic/DelimiterSpacing/DelimiterSpacingTest.php | 8 ++++---- .../Generic/DelimiterSpacing/DelimiterSpacingTest.twig | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/TwigCS/src/Sniff/AbstractSpacingSniff.php b/TwigCS/src/Sniff/AbstractSpacingSniff.php index 3620cb4..1d4f2bf 100644 --- a/TwigCS/src/Sniff/AbstractSpacingSniff.php +++ b/TwigCS/src/Sniff/AbstractSpacingSniff.php @@ -65,7 +65,7 @@ private function checkSpaceAfter(int $tokenPosition, array $tokens, int $expecte // Ignore new line $next = $this->findNext(Token::WHITESPACE_TOKENS, $tokens, $tokenPosition + 1, true); - if (false !== $next && $this->isTokenMatching($tokens[$next], Token::EOL_TYPE)) { + if (false !== $next && $this->isTokenMatching($tokens[$next], [Token::EOL_TYPE, Token::COMMENT_EOL_TYPE])) { return; } @@ -106,7 +106,7 @@ private function checkSpaceBefore(int $tokenPosition, array $tokens, int $expect // Ignore new line $previous = $this->findPrevious(Token::WHITESPACE_TOKENS, $tokens, $tokenPosition - 1, true); - if ($this->isTokenMatching($tokens[$previous], Token::EOL_TYPE)) { + if ($this->isTokenMatching($tokens[$previous], [Token::EOL_TYPE, Token::COMMENT_EOL_TYPE])) { return; } diff --git a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.fixed.twig b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.fixed.twig index 692a539..5da5b66 100644 --- a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.fixed.twig +++ b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.fixed.twig @@ -9,6 +9,9 @@ {{ shouldNotCareAboutNewLine }} +{# + shouldNotCareAboutNewLine +#} {%- if foo -%}{%- endif -%} {{ foo({'bar': {'baz': 'shouldNotCareAboutDoubleHashes'}}) }} diff --git a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php index 820ff14..c037966 100644 --- a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php +++ b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php @@ -18,10 +18,10 @@ class DelimiterSpacingTest extends AbstractSniffTest public function testSniff(): void { $this->checkSniff(new DelimiterSpacingSniff(), [ - [12 => 1], - [12 => 12], - [12 => 15], - [12 => 25], + [15 => 1], + [15 => 12], + [15 => 15], + [15 => 25], ]); } } diff --git a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.twig b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.twig index 0175972..c6161a3 100644 --- a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.twig +++ b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.twig @@ -9,6 +9,9 @@ {{ shouldNotCareAboutNewLine }} +{# + shouldNotCareAboutNewLine +#} {%-if foo -%}{%- endif-%} {{ foo({'bar': {'baz': 'shouldNotCareAboutDoubleHashes'}}) }}