zackad / prettier-plugin-twig

Code formatting plugin for Prettier to handle Twig templates
Apache License 2.0
45 stars 5 forks source link

Parser doesn't allow <body {% block body_attributes %}{% endblock %}> #61

Open jraller opened 2 weeks ago

jraller commented 2 weeks ago

A twig template with

    <body {% block body_attributes %}{% endblock %}>
        {% block body %}
        {% endblock %}
    </body>

in it passes the linter symfony console lint:twig templates, but prettier-plugin-twig's parser reports:

[error] templates/base.html.twig: Error: ERROR: Invalid token [error] 18 | {% endblock %} [error] 19 | [error] > 20 | <body {% block body_attributes %}{% endblock %}> [error] | ^ [error] 21 | {% block body %} [error] 22 | {% endblock %} [error] 23 | [error] [error] A tag must consist of attributes or expressions. Twig Tags are not allowed. [error] at TokenStream.error (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/melody/melody-parser/TokenStream.js:129:24) [error] at Parser.error (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/melody/melody-parser/Parser.js:452:21) [error] at Parser.matchAttributes (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/melody/melody-parser/Parser.js:442:22) [error] at Parser.matchElement (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/melody/melody-parser/Parser.js:333:14) [error] at Parser.parse (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/melody/melody-parser/Parser.js:207:32) [error] at Parser.matchElement (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/melody/melody-parser/Parser.js:343:41) [error] at Parser.parse (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/melody/melody-parser/Parser.js:207:32) [error] at Object.parse (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/@zackad/prettier-plugin-twig/src/parser.js:82:24)
[error] at parse4 (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/prettier/index.mjs:20685:24) [error] at async coreFormat (file:///C:/Users/Jason/AppData/Roaming/npm/node_modules/prettier/index.mjs:21146:7)

usage for this when calling the body_attributes block allows for passing in class and data-controller as follows:

{% block body_attributes %}
    class="bg-gray-100 font-sans leading-normal tracking-normal mt-12" data-controller="style"'%}
{% endblock %}
jraller commented 2 weeks ago

It looks like this dates back to https://github.com/trivago/prettier-plugin-twig-melody/issues/60