twigcs
twigcs copied to clipboard
Spacing of default values in macros
Hey folks!
Looking at the Twig Coding Standards, there doesn't seem to be a set standard for defining default values in macros.
However, the official documentation for macros uses spaces around the =
in its examples.
twigcs currently detects default values in macro definitions as named arguments, and request you use no space around the =
. I'm not sure if this is a decision based on the lack of clear standard, or simply a bug.
If this is a bug or an oversight, I'd be happy to look into it and try to work on a quick PR to fix this. I'd just like to validate the desired standard here before getting started.
Steps required to reproduce the problem
- Create a macro with a default value
{%- macro render_a_thing(my_var = null) -%} {# some macro content #} {%- endmacro -%}
- Run twigcs (
vendor/friendsoftwig/twigcs/bin/twigcs templates
)
Expected Result
No violation found.
Actual Result
l.1 c.31 : ERROR There should be 0 space before the "=" in the named arguments list.
l.1 c.33 : ERROR There should be 0 space after the "=" in the named arguments list.
Hi,
I think it's a bug ^^
Hello and thank you for reporting this. I think it's a duplicate of https://github.com/friendsoftwig/twigcs/issues/170
I tried to look at the fix a few weeks ago and it's not that easy. We would need some improvement on the code that split parenthesis to make the difference between a macro declaration and other parenthesis (macro call, arithmetic expression, etc...).