Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Additional linespaces added with every format #171

Closed
andyxmas opened this issue Mar 8, 2023 · 5 comments
Closed

Additional linespaces added with every format #171

andyxmas opened this issue Mar 8, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@andyxmas
Copy link

andyxmas commented Mar 8, 2023

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

  • OSX
  • Version 1.0.6

Additional context

  • This happens in both the command line (version 1.0.6) and the vscode plugin (latest?)
  • In my testing, I can see that if I remove the ``` backticks, the issue does not present. Also, if I remove the {% if ... %} statement.
@andyxmas andyxmas added the bug Something isn't working label Mar 8, 2023
@charlespwd
Copy link
Collaborator

Thanks for reporting :)

@Catalin-G
Copy link

Any news about this?

Wilhansen pushed a commit to Wilhansen/prettier-plugin-liquid that referenced this issue Aug 7, 2023
The issue is due to the plugin treating an HtmlRawNode as preformatted
text not to be touched the moment it detects the ` character (for
template literals) anywhere in the body. Aside from not formatting the
contents, it doesn't strip the leading and trailing newlines resulting
in compounding new lines everytime prettier is run against the file.
This fixes the compounding line issue in particular but does not fix the
contents not being prettified when a ` is detected anywhere in the text.
@Wilhansen
Copy link

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
Copy link

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

@charlespwd
Copy link
Collaborator

I believe this was fixed in the latest version by Shopify/theme-tools#163

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants