From 79a090834371f32d5aa5a9c5f832a24bba714a0e Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 22 Aug 2024 08:50:21 +0200 Subject: [PATCH] Another strategy --- src/Runner/Linter.php | 15 +-------------- .../ForbiddenBlock/ForbiddenBlockRuleTest.php | 11 ----------- .../ForbiddenFilter/ForbiddenFilterRuleTest.php | 11 ----------- .../ForbiddenFunctionRuleTest.php | 11 ----------- tests/Rules/Node/NodeRuleTest.php | 11 ----------- .../ValidConstantFunctionRuleTest.php | 11 ----------- tests/Runner/LinterTest.php | 14 -------------- 7 files changed, 1 insertion(+), 83 deletions(-) diff --git a/src/Runner/Linter.php b/src/Runner/Linter.php index 662ad240..c09fbc31 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; @@ -126,6 +125,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = continue; } + $node->setSourceContext($node->getSourceContext()); foreach ($nodeVisitorRules as $nodeVisitor) { $nodeVisitor->setReport($report, $stream->getIgnoredViolations()); } @@ -146,19 +146,6 @@ 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); 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();