Skip to content

Commit

Permalink
Merge branch '3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
OwlyCode committed Oct 26, 2019
2 parents 5d4f041 + 7c4bc76 commit 80d4f9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
23 changes: 17 additions & 6 deletions src/Rule/TrailingSpace.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@ public function check(\Twig\TokenStream $tokens)
\Twig\Token::TEXT_TYPE === $token->getType()
) {
if (preg_match("/[[:blank:]]+\n/", $token->getValue())) {
$violations[] = $this->createViolation(
$tokens->getSourceContext()->getPath(),
$token->getLine(),
$token->columnno,
'A line should not end with blank space(s).'
);
$line = $token->getLine();
$column = $token->columnno;
$values = explode("\n", $token->getValue());
$counter = 0;

foreach ($values as $value) {
if (preg_match('/[[:blank:]]+$/', $value)) {
$violations[] = $this->createViolation(
$tokens->getSourceContext()->getPath(),
$line + $counter,
0 === $counter ? $column + strlen($value) : strlen($value),
'A line should not end with blank space(s).'
);
}

++$counter;
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ public function getData()
["\t<meta property=\"og:url\" content=\"{{ url(\n\t\tapp.request.attributes.get('_route'),\n\t\tapp.request.attributes.get('_route_params')\n\t) }}\">", null],

// Spaces
["{{ foo }} \n", 'A line should not end with blank space(s).'],
["{{ foo }}\t\n", 'A line should not end with blank space(s).'],
["{{ foo }}\r\n\r\n", null],
["{{ foo }} \n", 'A line should not end with blank space(s).', [13, 1]],
["{{ foo }}\t\n", 'A line should not end with blank space(s).', [10, 1]],
["str\nstr \nstr", 'A line should not end with blank space(s).', [7, 2]],
["{{ 1 }}str\nstr \nstr", 'A line should not end with blank space(s).', [7, 2]],
['{{ foo }}', null],

// Check regression of https://github.com/friendsoftwig/twigcs/issues/23
['{% from _self import folder_breadcrumb %}', 'Unused macro import "folder_breadcrumb".'],
Expand Down

0 comments on commit 80d4f9a

Please sign in to comment.