Shopify / prettier-plugin-liquid

Prettier Liquid/HTML plugin
https://npm.im/@shopify/prettier-plugin-liquid
MIT License
93 stars 15 forks source link

Additional linespaces added with every format #171

Closed andyxmas closed 11 months ago

andyxmas commented 1 year ago

Describe the bug In some liquid snippets, examples below, the when running prettier, have extra line spaces added every time.

Unformatted source I've done my best to make this as minimal as possible.

<script>  
  window.someKey = {
    {% if customer %}
      customer: {
        name: '{{ customer.first_name }}'
      },
    {% endif %}
    somethingElse: {
      anotherKey: `someString`
    }
  };
</script>

Expected output No change, or potentially some formatting, but not additional linespaces.

Actual output

<script>

  window.someKey = {
    {% if customer %}
      customer: {
        name: '{{ customer.first_name }}'
      },
    {% endif %}
    somethingElse: {
      anotherKey: `someString`
    }
  };

</script>

Debugging information

Additional context

charlespwd commented 1 year ago

Thanks for reporting :)

Catalin-G commented 1 year ago

Any news about this?

Wilhansen commented 1 year ago

took a stab in fixing the bug on a surface level ☝️

the bug triggers if the script tag contents contain both liquid tags and the backtick for template literals, in addition to the newline, the backtick also disables prettifying (or at least, indentation) of the block (but that's for another issue).

JasonHassold commented 1 year ago

I'm also having this issue, every time a script tag contains backticks

charlespwd commented 11 months ago

I believe this was fixed in the latest version by https://github.com/Shopify/theme-tools/pull/163