Skip to content

Commit

Permalink
Merge pull request #126 from VincentLanglet/fixComment
Browse files Browse the repository at this point in the history
🐛 Fix delimiter spacing for comment with new line
  • Loading branch information
VincentLanglet authored Apr 26, 2020
2 parents 6437a6d + 10a23da commit 9b00eab
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions TwigCS/src/Sniff/AbstractSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{{
shouldNotCareAboutNewLine
}}
{#
shouldNotCareAboutNewLine
#}
{%- if foo -%}{%- endif -%}

{{ foo({'bar': {'baz': 'shouldNotCareAboutDoubleHashes'}}) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{{
shouldNotCareAboutNewLine
}}
{#
shouldNotCareAboutNewLine
#}
{%-if foo -%}{%- endif-%}

{{ foo({'bar': {'baz': 'shouldNotCareAboutDoubleHashes'}}) }}
Expand Down

0 comments on commit 9b00eab

Please sign in to comment.