friendsoftwig / twigcs

The missing checkstyle for twig!
MIT License
343 stars 34 forks source link

ForbiddenFunctions rule detection problem #174

Open icedevelopment opened 3 years ago

icedevelopment commented 3 years ago

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?

Ciloe commented 3 years ago

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

icedevelopment commented 3 years ago

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

Ciloe commented 3 years ago

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

icedevelopment commented 3 years ago

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.