From 8343cc15998dd82853603e664bfe2c3f3196eee1 Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Tue, 25 Jul 2023 23:24:36 +0200 Subject: [PATCH] Ignore for Latte\Runtime\Html in link if strict mode is not enabled (#410) --- CHANGELOG.md | 2 ++ extension.neon | 2 +- src/Error/ErrorBuilder.php | 4 ++++ .../Fixtures/templates/Links/default.latte | 4 ++++ .../LatteTemplatesRuleForPresenterWithNoMappingTest.php | 6 ++++++ .../LatteTemplatesRule/PresenterWithoutModule/strict.neon | 3 +++ 6 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/Rule/LatteTemplatesRule/PresenterWithoutModule/strict.neon diff --git a/CHANGELOG.md b/CHANGELOG.md index fe70bb50..4076031f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Added type int as param for Runtime::item() method - Transformer for ternary condition with is_object and dynamic form fields - it removes always true / always false condition errors - Added nette/forms errors `Cannot call method endTag() on Nette\Utils\Html|string.` and `Cannot call method startTag() on Nette\Utils\Html|string.` to ignore list until they are fixed +- Support for dynamic forms with known name +- Ignore for Latte\Runtime\Html in link if strict mode is not enabled ### Removed - ignore-next-line for dynamic inputs - should be solved by removing ternary condition for dynamic inputs diff --git a/extension.neon b/extension.neon index 47423852..becb3aa4 100644 --- a/extension.neon +++ b/extension.neon @@ -205,7 +205,7 @@ services: # Error builder - Efabrica\PHPStanLatte\Error\LineMapper\LineMapper(%debugMode%) - - Efabrica\PHPStanLatte\Error\ErrorBuilder(%latte.errorPatternsToIgnore%, %latte.warningPatterns%) + - Efabrica\PHPStanLatte\Error\ErrorBuilder(%latte.errorPatternsToIgnore%, %latte.warningPatterns%, %latte.strictMode%) # Error transformers - Efabrica\PHPStanLatte\Error\Transformer\UndefinedLatteFilterErrorTransformer diff --git a/src/Error/ErrorBuilder.php b/src/Error/ErrorBuilder.php index 0e4ff4e2..ef4038ed 100644 --- a/src/Error/ErrorBuilder.php +++ b/src/Error/ErrorBuilder.php @@ -69,6 +69,7 @@ final class ErrorBuilder public function __construct( array $errorPatternsToIgnore, array $warningPatterns, + bool $strictMode, PresenterFactoryFaker $presenterFactoryFaker, array $errorTransformers, LineMapper $lineMapper @@ -77,6 +78,9 @@ public function __construct( $this->warningPatterns = $warningPatterns; $this->errorTransformers = $errorTransformers; $this->lineMapper = $lineMapper; + if ($strictMode === false) { + $this->errorPatternsToIgnore[] = '/Parameter #1 \$destination of method Nette\\\\Application\\\\UI\\\\Component::link\(\) expects string, Latte\\\\Runtime\\\\Html\|string\|false given\./'; // nette/application error https://github.com/nette/application/issues/313 found by https://github.com/efabrica-team/phpstan-latte/issues/398 + } if ($presenterFactoryFaker->getPresenterFactory() === null) { $this->errorPatternsToIgnore[] = '/Cannot load presenter .*/'; } diff --git a/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/Fixtures/templates/Links/default.latte b/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/Fixtures/templates/Links/default.latte index 7f285d85..f6d3a9a6 100644 --- a/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/Fixtures/templates/Links/default.latte +++ b/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/Fixtures/templates/Links/default.latte @@ -97,3 +97,7 @@ Missing required param in handle link Extra param in handle link Extra named param in handle link + +Create with presenter via n:href +{capture $linksCreate}Links:create{/capture} +Create with presenter via n:href diff --git a/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/LatteTemplatesRuleForPresenterWithNoMappingTest.php b/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/LatteTemplatesRuleForPresenterWithNoMappingTest.php index 272cd42c..492c4754 100644 --- a/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/LatteTemplatesRuleForPresenterWithNoMappingTest.php +++ b/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/LatteTemplatesRuleForPresenterWithNoMappingTest.php @@ -15,6 +15,7 @@ protected static function additionalConfigFiles(): array __DIR__ . '/../../../../rules.neon', __DIR__ . '/../../../config.neon', __DIR__ . '/config.neon', + __DIR__ . '/strict.neon', ]; } @@ -32,6 +33,11 @@ public function testLinks(): void 98, 'default.latte', ], + [ + 'Parameter #1 $destination of method Nette\Application\UI\Component::link() expects string, Latte\Runtime\Html|string|false given.', + 103, + 'default.latte', + ], ]); } } diff --git a/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/strict.neon b/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/strict.neon new file mode 100644 index 00000000..06b42d20 --- /dev/null +++ b/tests/Rule/LatteTemplatesRule/PresenterWithoutModule/strict.neon @@ -0,0 +1,3 @@ +parameters: + latte: + strictMode: true