Skip to content

Commit

Permalink
Use NamedArgumentSeparatorRule in Twig standard
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 30, 2024
1 parent 0c50bdb commit e2130a3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ new TwigCsFixer\Rules\Whitespace\IndentRule(3);
**Twig**:
- DelimiterSpacingRule
- NamedArgumentNameRule
- NamedArgumentSeparatorRule
- NamedArgumentSpacingRule
- OperatorNameSpacingRule
- OperatorSpacingRule
Expand Down
7 changes: 2 additions & 5 deletions src/Rules/Function/NamedArgumentSeparatorRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
*/
final class NamedArgumentSeparatorRule extends AbstractFixableRule
{
public function __construct()
protected function process(int $tokenIndex, Tokens $tokens): void
{
if (!StubbedEnvironment::satisfiesTwigVersion(3, 12)) {
throw new \InvalidArgumentException('Named argument with semi colons requires twig/twig >= 3.12.0');
return;
}
}

protected function process(int $tokenIndex, Tokens $tokens): void
{
$token = $tokens->get($tokenIndex);
if (!$token->isMatching(Token::NAMED_ARGUMENT_SEPARATOR_TYPE)) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/Standard/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use TwigCsFixer\Rules\Delimiter\DelimiterSpacingRule;
use TwigCsFixer\Rules\Function\NamedArgumentNameRule;
use TwigCsFixer\Rules\Function\NamedArgumentSeparatorRule;
use TwigCsFixer\Rules\Function\NamedArgumentSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorNameSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorSpacingRule;
Expand All @@ -24,6 +25,7 @@ public function getRules(): array
return [
new DelimiterSpacingRule(),
new NamedArgumentNameRule(),
new NamedArgumentSeparatorRule(),
new NamedArgumentSpacingRule(),
new OperatorNameSpacingRule(),
new OperatorSpacingRule(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class NamedArgumentSeparatorRuleTest extends AbstractRuleTestCase
public function testRule(): void
{
if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.12.0')) {
$this->expectException(\InvalidArgumentException::class);
static::markTestSkipped('twig/twig ^3.12.0 is required.');
}

$this->checkRule(new NamedArgumentSeparatorRule(), [
Expand Down
2 changes: 2 additions & 0 deletions tests/Standard/SymfonyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use TwigCsFixer\Rules\File\FileExtensionRule;
use TwigCsFixer\Rules\File\FileNameRule;
use TwigCsFixer\Rules\Function\NamedArgumentNameRule;
use TwigCsFixer\Rules\Function\NamedArgumentSeparatorRule;
use TwigCsFixer\Rules\Function\NamedArgumentSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorNameSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorSpacingRule;
Expand All @@ -26,6 +27,7 @@ public function testGetRules(): void
static::assertEquals([
new DelimiterSpacingRule(),
new NamedArgumentNameRule(),
new NamedArgumentSeparatorRule(),
new NamedArgumentSpacingRule(),
new OperatorNameSpacingRule(),
new OperatorSpacingRule(),
Expand Down
2 changes: 2 additions & 0 deletions tests/Standard/TwigCsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use TwigCsFixer\Rules\Delimiter\DelimiterSpacingRule;
use TwigCsFixer\Rules\Function\IncludeFunctionRule;
use TwigCsFixer\Rules\Function\NamedArgumentNameRule;
use TwigCsFixer\Rules\Function\NamedArgumentSeparatorRule;
use TwigCsFixer\Rules\Function\NamedArgumentSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorNameSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorSpacingRule;
Expand All @@ -33,6 +34,7 @@ public function testGetRules(): void
static::assertEquals([
new DelimiterSpacingRule(),
new NamedArgumentNameRule(),
new NamedArgumentSeparatorRule(),
new NamedArgumentSpacingRule(),
new OperatorNameSpacingRule(),
new OperatorSpacingRule(),
Expand Down
2 changes: 2 additions & 0 deletions tests/Standard/TwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\TestCase;
use TwigCsFixer\Rules\Delimiter\DelimiterSpacingRule;
use TwigCsFixer\Rules\Function\NamedArgumentNameRule;
use TwigCsFixer\Rules\Function\NamedArgumentSeparatorRule;
use TwigCsFixer\Rules\Function\NamedArgumentSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorNameSpacingRule;
use TwigCsFixer\Rules\Operator\OperatorSpacingRule;
Expand All @@ -23,6 +24,7 @@ public function testGetRules(): void
static::assertEquals([
new DelimiterSpacingRule(),
new NamedArgumentNameRule(),
new NamedArgumentSeparatorRule(),
new NamedArgumentSpacingRule(),
new OperatorNameSpacingRule(),
new OperatorSpacingRule(),
Expand Down

0 comments on commit e2130a3

Please sign in to comment.