diff --git a/src/Runner/Linter.php b/src/Runner/Linter.php index 662ad240..d80da7b4 100644 --- a/src/Runner/Linter.php +++ b/src/Runner/Linter.php @@ -11,7 +11,6 @@ use Twig\Source; use TwigCsFixer\Cache\Manager\CacheManagerInterface; use TwigCsFixer\Cache\Manager\NullCacheManager; -use TwigCsFixer\Environment\StubbedEnvironment; use TwigCsFixer\Exception\CannotFixFileException; use TwigCsFixer\Exception\CannotTokenizeException; use TwigCsFixer\Report\Report; @@ -146,23 +145,10 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = private function parseTemplate(string $content, string $filePath, Report $report): ?ModuleNode { - if (!StubbedEnvironment::satisfiesTwigVersion(3, 10)) { - // @codeCoverageIgnoreStart - $violation = new Violation( - Violation::LEVEL_FATAL, - 'Node visitor rules require twig/twig >= 3.10.0', - $filePath, - ); - $report->addViolation($violation); - - return null; - // @codeCoverageIgnoreEnd - } - try { $twigSource = new Source($content, $filePath); - return $this->env->parse($this->env->tokenize($twigSource)); + $node = $this->env->parse($this->env->tokenize($twigSource)); } catch (Error $error) { $violation = new Violation( Violation::LEVEL_FATAL, @@ -176,6 +162,14 @@ private function parseTemplate(string $content, string $filePath, Report $report return null; } + + // BC fix for twig/twig < 3.10. + $sourceContext = $node->getSourceContext(); + if (null !== $sourceContext) { + $node->setSourceContext($sourceContext); + } + + return $node; } private function setErrorHandler(Report $report, string $file): void diff --git a/tests/Rules/Node/ForbiddenBlock/ForbiddenBlockRuleTest.php b/tests/Rules/Node/ForbiddenBlock/ForbiddenBlockRuleTest.php index 69a63ac5..09a8bc2b 100644 --- a/tests/Rules/Node/ForbiddenBlock/ForbiddenBlockRuleTest.php +++ b/tests/Rules/Node/ForbiddenBlock/ForbiddenBlockRuleTest.php @@ -4,22 +4,11 @@ namespace TwigCsFixer\Tests\Rules\Node\ForbiddenBlock; -use Composer\InstalledVersions; -use Composer\Semver\VersionParser; use TwigCsFixer\Rules\Node\ForbiddenBlockRule; use TwigCsFixer\Tests\Rules\AbstractRuleTestCase; final class ForbiddenBlockRuleTest extends AbstractRuleTestCase { - protected function setUp(): void - { - parent::setUp(); - - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - } - public function testConfiguration(): void { static::assertSame( diff --git a/tests/Rules/Node/ForbiddenFilter/ForbiddenFilterRuleTest.php b/tests/Rules/Node/ForbiddenFilter/ForbiddenFilterRuleTest.php index 4c796a87..e8f5fbdb 100644 --- a/tests/Rules/Node/ForbiddenFilter/ForbiddenFilterRuleTest.php +++ b/tests/Rules/Node/ForbiddenFilter/ForbiddenFilterRuleTest.php @@ -4,22 +4,11 @@ namespace TwigCsFixer\Tests\Rules\Node\ForbiddenFilter; -use Composer\InstalledVersions; -use Composer\Semver\VersionParser; use TwigCsFixer\Rules\Node\ForbiddenFilterRule; use TwigCsFixer\Tests\Rules\AbstractRuleTestCase; final class ForbiddenFilterRuleTest extends AbstractRuleTestCase { - protected function setUp(): void - { - parent::setUp(); - - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - } - public function testConfiguration(): void { static::assertSame( diff --git a/tests/Rules/Node/ForbiddenFunction/ForbiddenFunctionRuleTest.php b/tests/Rules/Node/ForbiddenFunction/ForbiddenFunctionRuleTest.php index 640297f7..0fd7d1ff 100644 --- a/tests/Rules/Node/ForbiddenFunction/ForbiddenFunctionRuleTest.php +++ b/tests/Rules/Node/ForbiddenFunction/ForbiddenFunctionRuleTest.php @@ -4,22 +4,11 @@ namespace TwigCsFixer\Tests\Rules\Node\ForbiddenFunction; -use Composer\InstalledVersions; -use Composer\Semver\VersionParser; use TwigCsFixer\Rules\Node\ForbiddenFunctionRule; use TwigCsFixer\Tests\Rules\AbstractRuleTestCase; final class ForbiddenFunctionRuleTest extends AbstractRuleTestCase { - protected function setUp(): void - { - parent::setUp(); - - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - } - public function testConfiguration(): void { static::assertSame( diff --git a/tests/Rules/Node/NodeRuleTest.php b/tests/Rules/Node/NodeRuleTest.php index 6683a0fa..decbc56d 100644 --- a/tests/Rules/Node/NodeRuleTest.php +++ b/tests/Rules/Node/NodeRuleTest.php @@ -4,8 +4,6 @@ namespace TwigCsFixer\Tests\Rules\Node; -use Composer\InstalledVersions; -use Composer\Semver\VersionParser; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Node\Node; @@ -22,15 +20,6 @@ final class NodeRuleTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); - - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - } - public function testEnterNodeRule(): void { $report = new Report([new \SplFileInfo('fakeFile.html.twig')]); diff --git a/tests/Rules/Node/ValidConstantFunction/ValidConstantFunctionRuleTest.php b/tests/Rules/Node/ValidConstantFunction/ValidConstantFunctionRuleTest.php index a320cf13..ac46f5a5 100644 --- a/tests/Rules/Node/ValidConstantFunction/ValidConstantFunctionRuleTest.php +++ b/tests/Rules/Node/ValidConstantFunction/ValidConstantFunctionRuleTest.php @@ -4,8 +4,6 @@ namespace TwigCsFixer\Tests\Rules\Node\ValidConstantFunction; -use Composer\InstalledVersions; -use Composer\Semver\VersionParser; use TwigCsFixer\Rules\Node\ValidConstantFunctionRule; use TwigCsFixer\Tests\Rules\AbstractRuleTestCase; @@ -13,15 +11,6 @@ final class ValidConstantFunctionRuleTest extends AbstractRuleTestCase { public const SOME_CONSTANT = 'Foo'; - protected function setUp(): void - { - parent::setUp(); - - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - } - public function testRule(): void { $this->checkRule(new ValidConstantFunctionRule(), [ diff --git a/tests/Runner/LinterTest.php b/tests/Runner/LinterTest.php index ccf86276..be751b08 100644 --- a/tests/Runner/LinterTest.php +++ b/tests/Runner/LinterTest.php @@ -4,8 +4,6 @@ namespace TwigCsFixer\Tests\Runner; -use Composer\InstalledVersions; -use Composer\Semver\VersionParser; use Twig\Environment; use Twig\Error\SyntaxError; use TwigCsFixer\Cache\Manager\CacheManagerInterface; @@ -276,10 +274,6 @@ public function testFileIsNotCachedWhenReportHasErrors(): void public function testViolationsFromNodeVisitorRule(): void { - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - $filePath = $this->getTmpPath(__DIR__.'/Fixtures/Linter/node_visitor.twig'); $ruleset = new Ruleset(); @@ -324,10 +318,6 @@ public function testViolationsFromNodeVisitorRule(): void public function testNodeVisitorWithInvalidFiles(): void { - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - $filePath = $this->getTmpPath(__DIR__.'/Fixtures/Linter/file.twig'); $filePath2 = $this->getTmpPath(__DIR__.'/Fixtures/Linter/file2.twig'); @@ -360,10 +350,6 @@ public function testNodeVisitorWithInvalidFiles(): void public function testNodeVisitorWithBuggyFixer(): void { - if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.10.0')) { - static::markTestSkipped('twig/twig ^3.10.0 is required.'); - } - $filePath = $this->getTmpPath(__DIR__.'/Fixtures/Linter/file.twig'); $ruleset = new Ruleset();