Skip to content
Snippets Groups Projects
Commit c6a224bf authored by Sviatoslav Smovdyr's avatar Sviatoslav Smovdyr Committed by Pierre Dureau
Browse files

Issue #3484830 by smovs, pdureau, mogtofu33: Warning if "is iterable" test found

parent 427b8366
Branches
Tags
1 merge request!265#3484830 - Added a warning if 'is iterable' test found.
Pipeline #342113 passed
......@@ -98,12 +98,11 @@ final class TwigValidatorRuleTestExpr extends TwigValidatorRulePluginBase {
switch ($name) {
case 'empty':
$message = 'The exact same as just testing the variable, empty is not needed.';
// @phpcs:disable
// @todo enable when Twig 3.11 with better iterable.
// case 'iterable':
// $message = new TranslatableMarkup('Return true for mapping and sequence.');
// return [ValidatorMessage::createForNode($id, $node, $message, RfcLogLevel::WARNING)];
// @phpcs:enable
break;
case 'iterable':
$message = '`is iterable` test is too ambiguous. Use `is sequence` or `is mapping`.';
break;
}
return RfcLogLevel::WARNING;
}
......
......@@ -30,6 +30,7 @@ final class TwigValidatorRuleTestExprTest extends TwigValidatorTestBase {
"{% set foo = 'foo' %}
{% if foo is defined %}{% endif %}
{% if foo is empty %}{% endif %}
{% if foo is iterable %}{% endif %}
{{ foo is null }}
{{ foo ?? 'bar' }}
{% if foo is same as(false) %}{% endif %}
......@@ -37,9 +38,10 @@ final class TwigValidatorRuleTestExprTest extends TwigValidatorTestBase {
[
[2, 'Not needed in Drupal because strict_variables=false.', RfcLogLevel::WARNING],
[3, 'The exact same as just testing the variable, empty is not needed.', RfcLogLevel::WARNING],
[4, 'Not needed in Drupal because strict_variables=false.', RfcLogLevel::WARNING],
[5, 'Use `|default(foo)` filter instead of null ternary `??`.', RfcLogLevel::WARNING],
[6, 'Equivalent to strict comparison in PHP, often too strict.', RfcLogLevel::ERROR],
[4, '`is iterable` test is too ambiguous. Use `is sequence` or `is mapping`.', RfcLogLevel::WARNING],
[5, 'Not needed in Drupal because strict_variables=false.', RfcLogLevel::WARNING],
[6, 'Use `|default(foo)` filter instead of null ternary `??`.', RfcLogLevel::WARNING],
[7, 'Equivalent to strict comparison in PHP, often too strict.', RfcLogLevel::ERROR],
],
],
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment