Skip to content

Commit

Permalink
Improve twig/twig lower constraint support (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Aug 22, 2024
1 parent 10bdf19 commit fa1ca16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"symfony/filesystem": "^5.4 || ^6.4 || ^7.0",
"symfony/finder": "^5.4 || ^6.4 || ^7.0",
"symfony/string": "^5.4.42 || ^6.4.10 || ~7.0.10 || ^7.1.3",
"twig/twig": "^3.10",
"twig/twig": "^3.4",
"webmozart/assert": "^1.10"
},
"require-dev": {
Expand Down
10 changes: 9 additions & 1 deletion src/Runner/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private function parseTemplate(string $content, string $filePath, Report $report
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,
Expand All @@ -162,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
Expand Down
4 changes: 0 additions & 4 deletions tests/Environment/StubbedEnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ public function testParse(): void

public function testParseCacheTag(): void
{
if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.2.0')) {
static::markTestSkipped('twig/twig ^3.2.0 is required.');
}

$content = file_get_contents(__DIR__.'/Fixtures/cache_tag.html.twig');
static::assertNotFalse($content);

Expand Down

0 comments on commit fa1ca16

Please sign in to comment.