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

Force braces around conditionals when concatenating #50

Closed mrkanister closed 4 years ago

mrkanister commented 4 years ago

Before, the formatter would apply the following simplification:

Input:

  {% icon 'name' with {
      classList: 'classA' ~ (not needsB ? ' classB')
  } %}

Output:

  {% icon 'name' with {
      classList: 'classA' ~ not needsB ? ' classB'
  } %}

Although operator precedence should allow us to drop the braces, this could e.g. cause the following to happen when rendering the template:

With braces:

  <span class="classA classB">...</span>

Without braces:

  <span class="  classB">...</span>

The left part of the concatenation essentially turned into a whitespace. Now, braces are being placed around these expression combinations.