Empty blocks get formatted twice
Closed this issue · 2 comments
Unformatted
<body>
{% block content %}{% endblock %}
</body>
First pass formatting with prettier --write
<body>
{% block content %}
{% endblock %}
</body>
Second pass formatting with prettier --write
again
<body>
{% block content %}
{% endblock %}
</body>
Current workarounds
- run formatting on templates twice
- add a comment inside of the empty block
<body>
{% block content %}
{# empty block #}
{% endblock %}
</body>
Neither of these workarounds are ideal, would be could if empty blocks were consistently formatted the first time. It would be useful to have this configurable as an option to allow inline empty blocks.
One possible solution could look like this
export default {
plugins: ["@zackad/prettier-plugin-twig"],
twigEmptyBlocks: "inline|break|space"
}
Since this introduce inconsistent behaviour, I consider this as a bug. I remember this has been fixed in other fork. Might be worth it to check how they handle this issue.
I'm not sure about introducing new option to handle this issue. Prettier is opiniated code formatter. I think adding new option that user has to be aware of is not a good idea, IMO.
If people want to use configurable twig formatter, I suggest to check out twig-cs-fixer.
Good point, less options the better.
I guess the best way to display it is in it's final form then, but the issue still stands, it should make it there in one formatting pass.