-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b5ff55
commit 0d79179
Showing
11 changed files
with
91 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TwigCsFixer\Sniff; | ||
|
||
use TwigCsFixer\Token\Token; | ||
|
||
/** | ||
* Ensure there is one space before and after block names. | ||
*/ | ||
final class BlockNameSpacingSniff extends AbstractSpacingSniff | ||
{ | ||
/** | ||
* @param array<int, Token> $tokens | ||
*/ | ||
protected function getSpaceBefore(int $tokenPosition, array $tokens): ?int | ||
{ | ||
$token = $tokens[$tokenPosition]; | ||
|
||
if ($this->isTokenMatching($token, Token::BLOCK_NAME_TYPE)) { | ||
return 1; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param array<int, Token> $tokens | ||
*/ | ||
protected function getSpaceAfter(int $tokenPosition, array $tokens): ?int | ||
{ | ||
$token = $tokens[$tokenPosition]; | ||
|
||
if ($this->isTokenMatching($token, Token::BLOCK_NAME_TYPE)) { | ||
return 1; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/Sniff/BlockNameSpacingSniff/BlockNameSpacingTest.fixed.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% extends '@Admin/...' %} | ||
{% set test = 'test' %} | ||
{% if test is not null %}{% endif %} |
21 changes: 21 additions & 0 deletions
21
tests/Sniff/BlockNameSpacingSniff/BlockNameSpacingTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TwigCsFixer\Tests\Sniff\BlockNameSpacingSniff; | ||
|
||
use TwigCsFixer\Sniff\BlockNameSpacingSniff; | ||
use TwigCsFixer\Tests\Sniff\AbstractSniffTestCase; | ||
|
||
final class BlockNameSpacingTest extends AbstractSniffTestCase | ||
{ | ||
public function testSniff(): void | ||
{ | ||
$this->checkSniff(new BlockNameSpacingSniff(), [ | ||
[1 => 5], | ||
[1 => 5], | ||
[3 => 3], | ||
[3 => 3], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% extends'@Admin/...' %} | ||
{% set test = 'test' %} | ||
{%if test is not null %}{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters