twigcs icon indicating copy to clipboard operation
twigcs copied to clipboard

ForbiddenFunctions rule detection problem

Open icedevelopment opened this issue 3 years ago • 4 comments

The ForbiddenFunctions rule added in #67 doesn't detect function calls with spaces before the first parenthesis.

Example:

{% dump (foo) %}
{{ dump (foo) }}

won't be detected but

{% dump(foo) %}
{{ dump(foo) }}

will be.

@Ciloe any chance you could slightly modify the parser to handle these cases?

icedevelopment avatar Apr 26 '21 09:04 icedevelopment

Yes, I will see that. Thanks for your feedback !

Ciloe avatar Apr 26 '21 10:04 Ciloe

As a side note {% dump %} isn't detected either.

icedevelopment avatar Apr 26 '21 15:04 icedevelopment

Yes, but this is not a real function which is forbidden.

Ciloe avatar Apr 27 '21 06:04 Ciloe

True, technically its a tag in this case but I think it would be a very useful thing if this rule would detect it as well. According to the comments in Symfony\Bridge\Twig\TokenParser\DumpTokenParser the syntax should be:

{% dump %}
{% dump foo %}
{% dump foo, bar %}

but it looks like {% dump (foo) %} is syntactically valid. On the other hand {% dump (foo, bar) %} will throw an exception.

icedevelopment avatar Apr 28 '21 07:04 icedevelopment