Skip to content

Commit

Permalink
Another strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 22, 2024
1 parent 703deeb commit 79a0908
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 83 deletions.
15 changes: 1 addition & 14 deletions src/Runner/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,6 +125,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer =
continue;
}

$node->setSourceContext($node->getSourceContext());

Check failure on line 128 in src/Runner/Linter.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $source of method Twig\Node\Node::setSourceContext() expects Twig\Source, Twig\Source|null given.

Check failure on line 128 in src/Runner/Linter.php

View workflow job for this annotation

GitHub Actions / Psalm

PossiblyNullArgument

src/Runner/Linter.php:128:41: PossiblyNullArgument: Argument 1 of Twig\Node\ModuleNode::setSourceContext cannot be null, possibly null value provided (see https://psalm.dev/078)
foreach ($nodeVisitorRules as $nodeVisitor) {
$nodeVisitor->setReport($report, $stream->getIgnoredViolations());
}
Expand All @@ -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);

Expand Down
11 changes: 0 additions & 11 deletions tests/Rules/Node/ForbiddenBlock/ForbiddenBlockRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions tests/Rules/Node/ForbiddenFilter/ForbiddenFilterRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions tests/Rules/Node/ForbiddenFunction/ForbiddenFunctionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions tests/Rules/Node/NodeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@

namespace TwigCsFixer\Tests\Rules\Node\ValidConstantFunction;

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use TwigCsFixer\Rules\Node\ValidConstantFunctionRule;
use TwigCsFixer\Tests\Rules\AbstractRuleTestCase;

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(), [
Expand Down
14 changes: 0 additions & 14 deletions tests/Runner/LinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 79a0908

Please sign in to comment.