trivago / prettier-plugin-twig-melody

Code formatting plugin for Prettier which can handle Twig/Melody templates
Apache License 2.0
158 stars 34 forks source link

Formatting error with Symfony style Twig functions #41

Open 0x7061 opened 4 years ago

0x7061 commented 4 years ago

Hey guys, thanks for the great plugin. I just started using it in a Symfony project and stumbled over a few limitations (?). Basically I get a ["ERROR" - 7:50:43 PM] Error formatting document. when I have Symfony Twig functions inside my code like:

{{ form_start(form, {'method': 'POST', 'multipart': true, 'attr': { 'id': 'expense_form' }}) }}
...
{{ form_end(form) }}

Without these, my Twig file gets formatted perfectly. Any idea if this is/should be/will be supported?

Thanks

hansgrinwis commented 4 years ago

Hello @codepushr, if you include a space between the two mustaches }} after 'expense_form' it formats fine. The plugin thinks }} is a Twig print delimiter where they are two separate object delimiters.

{{ form_start(form, {'method': 'POST', 'multipart': true, 'attr': { 'id': 'expense_form' } }) }}
...
{{ form_end(form) }}

It might still be worthwhile for the plugin to catch this...