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 3a4986a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 69 deletions.
25 changes: 13 additions & 12 deletions src/Runner/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer =
continue;
}

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

Check failure on line 129 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 129 in src/Runner/Linter.php

View workflow job for this annotation

GitHub Actions / Psalm

PossiblyNullArgument

src/Runner/Linter.php:129: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,18 +147,18 @@ 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
}
// 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
9 changes: 0 additions & 9 deletions tests/Rules/Node/ForbiddenBlock/ForbiddenBlockRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@

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
9 changes: 0 additions & 9 deletions tests/Rules/Node/ForbiddenFilter/ForbiddenFilterRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@

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
9 changes: 0 additions & 9 deletions tests/Rules/Node/NodeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,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 @@ -13,15 +13,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(), [
Expand Down
12 changes: 0 additions & 12 deletions tests/Runner/LinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,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 +320,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 +352,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 3a4986a

Please sign in to comment.