trivago / prettier-plugin-twig-melody

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

Adopt the Sen­sio Labs Twig Cod­ing Stan­dards #7

Closed urbantrout closed 4 years ago

urbantrout commented 4 years ago

See: https://twig.symfony.com/doc/2.x/coding_standards.html

Specifically:

twbartel commented 4 years ago

Hey Harald, thanks for the suggestion. The problem I see is that part of the coding standards might be at odds with what Prettier is all about. Let's look at a real-world example where a filter expression won't fit on one line:

<p class="alert__message">
    {{
        'results_for'
            | translate({ searchedTerm: '<mark class="highlight-search-term">' ~ semKeyword ~ '</mark>' })
            | raw
    }}
</p>

Having no whitespace whatsoever around the | operator would force Prettier to put it all on one line, which goes against the purpose of even using Prettier. What I can try to do is to go without any spaces as long as the filter expression fits on one line, and insert breaks if it doesn't. Would you prefer having line breaks, but no spaces after the | operators, like this?

<p class="alert__message">
    {{
        'results_for'
            |translate({ searchedTerm: '<mark class="highlight-search-term">' ~ semKeyword ~ '</mark>' })
            |raw
    }}
</p>

At some point, I need to insert the points where the code can break (since I assume you know German: "Sollbruchstellen"), and these points are usually around operators.

What do you think?

P.S.: I find the coding standard a little inconsistent, also. Why shouldn't we have spaces around |, but around all other operators like +, -, ~, etc.?

twbartel commented 4 years ago

Hello @urbantrout, I just published version 0.2.0, which improves adherence to the Twig coding standards. When long filter expressions don't fit in the line, there might still be breaks, though.

Can you give it a try?

twbartel commented 4 years ago

Closing this issue for now, as I consider it resolved. Please tell me if you think otherwise.