diff --git a/docs/rules.md b/docs/rules.md index fcab3d9..25ba30e 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -160,6 +160,7 @@ new TwigCsFixer\Rules\Whitespace\IndentRule(3); **Twig**: - DelimiterSpacingRule - NamedArgumentNameRule +- NamedArgumentSeparatorRule - NamedArgumentSpacingRule - OperatorNameSpacingRule - OperatorSpacingRule diff --git a/src/Rules/Function/NamedArgumentSeparatorRule.php b/src/Rules/Function/NamedArgumentSeparatorRule.php index 6533dac..5b2deb9 100644 --- a/src/Rules/Function/NamedArgumentSeparatorRule.php +++ b/src/Rules/Function/NamedArgumentSeparatorRule.php @@ -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; diff --git a/src/Standard/Twig.php b/src/Standard/Twig.php index 8b02f70..7cdf5a5 100644 --- a/src/Standard/Twig.php +++ b/src/Standard/Twig.php @@ -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; @@ -24,6 +25,7 @@ public function getRules(): array return [ new DelimiterSpacingRule(), new NamedArgumentNameRule(), + new NamedArgumentSeparatorRule(), new NamedArgumentSpacingRule(), new OperatorNameSpacingRule(), new OperatorSpacingRule(), diff --git a/tests/Rules/Function/NamedArgumentSeparator/NamedArgumentSeparatorRuleTest.php b/tests/Rules/Function/NamedArgumentSeparator/NamedArgumentSeparatorRuleTest.php index 4b93d22..a65b779 100644 --- a/tests/Rules/Function/NamedArgumentSeparator/NamedArgumentSeparatorRuleTest.php +++ b/tests/Rules/Function/NamedArgumentSeparator/NamedArgumentSeparatorRuleTest.php @@ -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(), [ diff --git a/tests/Standard/SymfonyTest.php b/tests/Standard/SymfonyTest.php index 0c4631f..c51a4d7 100644 --- a/tests/Standard/SymfonyTest.php +++ b/tests/Standard/SymfonyTest.php @@ -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; @@ -26,6 +27,7 @@ public function testGetRules(): void static::assertEquals([ new DelimiterSpacingRule(), new NamedArgumentNameRule(), + new NamedArgumentSeparatorRule(), new NamedArgumentSpacingRule(), new OperatorNameSpacingRule(), new OperatorSpacingRule(), diff --git a/tests/Standard/TwigCsFixerTest.php b/tests/Standard/TwigCsFixerTest.php index 0b53cf2..859a4dc 100644 --- a/tests/Standard/TwigCsFixerTest.php +++ b/tests/Standard/TwigCsFixerTest.php @@ -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; @@ -33,6 +34,7 @@ public function testGetRules(): void static::assertEquals([ new DelimiterSpacingRule(), new NamedArgumentNameRule(), + new NamedArgumentSeparatorRule(), new NamedArgumentSpacingRule(), new OperatorNameSpacingRule(), new OperatorSpacingRule(), diff --git a/tests/Standard/TwigTest.php b/tests/Standard/TwigTest.php index 9d039d4..aafbb07 100644 --- a/tests/Standard/TwigTest.php +++ b/tests/Standard/TwigTest.php @@ -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; @@ -23,6 +24,7 @@ public function testGetRules(): void static::assertEquals([ new DelimiterSpacingRule(), new NamedArgumentNameRule(), + new NamedArgumentSeparatorRule(), new NamedArgumentSpacingRule(), new OperatorNameSpacingRule(), new OperatorSpacingRule(),