Skip to content

Commit

Permalink
Ignore for Latte\Runtime\Html in link if strict mode is not enabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lulco authored Jul 25, 2023
1 parent d11c7f0 commit 8343cc1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Error/ErrorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ final class ErrorBuilder
public function __construct(
array $errorPatternsToIgnore,
array $warningPatterns,
bool $strictMode,
PresenterFactoryFaker $presenterFactoryFaker,
array $errorTransformers,
LineMapper $lineMapper
Expand All @@ -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 .*/';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@
<a href="{link delete!}">Missing required param in handle link</a>
<a href="{link delete!, 'my-id', 'extra param'}">Extra param in handle link</a>
<a href="{link delete!, id: 'my-id', extra: 'extra param'}">Extra named param in handle link</a>

<a n:href="Links:create" n:attr="aa, bb">Create with presenter via n:href</a>
{capture $linksCreate}Links:create{/capture}
<a n:href="$linksCreate" n:attr="aa, bb">Create with presenter via n:href</a>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected static function additionalConfigFiles(): array
__DIR__ . '/../../../../rules.neon',
__DIR__ . '/../../../config.neon',
__DIR__ . '/config.neon',
__DIR__ . '/strict.neon',
];
}

Expand All @@ -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',
],
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
latte:
strictMode: true

0 comments on commit 8343cc1

Please sign in to comment.