Shopify / prettier-plugin-liquid

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

Keeps changing on every save [see video] #190

Closed masserra closed 11 months ago

masserra commented 1 year ago

Describe the bug When saving it won't keep it at a defined version, if saved several times it will keep changing the formatting.

Unformatted source

<script>
  console.log('Data: ', {{ metafields.custom | json }});
  console.log('Size: ', {{ artists | size }});
  console.log('Condition: ', `
    {%- if artists -%}
      {% if artists.size > 1 %}Various Artists{% else %}Single Artist{% endif %}
    {%- endif -%}
  `);
  console.log('Loop: ', `
    {%- if artists -%}
      {% for artist in artists %}
        {{ forloop.index }}
      {% endfor %}
    {%- endif -%}
  `);
  console.log('––––––––––––––––––––––––––––––––––––––');
</script>

Expected output

<script>
  console.log('Data: ', {{ metafields.custom | json }});
  console.log('Size: ', {{ artists | size }});
  console.log('Condition: ', `
    {%- if artists -%}
      {% if artists.size > 1 %}Various Artists{% else %}Single Artist{% endif %}
    {%- endif -%}
  `);
  console.log('Loop: ', `
    {%- if artists -%}
      {% for artist in artists %}
        {{ forloop.index }}
      {% endfor %}
    {%- endif -%}
  `);
  console.log('––––––––––––––––––––––––––––––––––––––');
</script>

Actual output 1 (after first save)

<script>

  console.log('Data: ', {{ metafields.custom | json }});
  console.log('Size: ', {{ artists | size }});
  console.log('Condition: ', `
    {%- if artists -%}
      {% if artists.size > 1 %}Various Artists{% else %}Single Artist{% endif %}
    {%- endif -%}
  `);
  console.log('Loop: ', `
    {%- if artists -%}
      {% for artist in artists %}
        {{ forloop.index }}
      {% endfor %}
    {%- endif -%}
  `);
  console.log('––––––––––––––––––––––––––––––––––––––');

</script>

Actual output 2 (after second save)

<script>

  console.log('Data: ', {{ metafields.custom | json }});
  console.log('Size: ', {{ artists | size }});
  console.log('Condition: ', `
    {%- if artists -%}
      {% if artists.size > 1 %}Various Artists{% else %}Single Artist{% endif %}
    {%- endif -%}
  `);
  console.log('Loop: ', `
    {%- if artists -%}
      {% for artist in artists %}
        {{ forloop.index }}
      {% endfor %}
    {%- endif -%}
  `);
  console.log('––––––––––––––––––––––––––––––––––––––');

</script>

Actual output 3 (after third save)

<script>

  console.log('Data: ', {{ metafields.custom | json }});
  console.log('Size: ', {{ artists | size }});
  console.log('Condition: ', `
    {%- if artists -%}
      {% if artists.size > 1 %}Various Artists{% else %}Single Artist{% endif %}
    {%- endif -%}
  `);
  console.log('Loop: ', `
    {%- if artists -%}
      {% for artist in artists %}
        {{ forloop.index }}
      {% endfor %}
    {%- endif -%}
  `);
  console.log('––––––––––––––––––––––––––––––––––––––');

</script>

And so on.... better perceived in the video below

Debugging information

https://github.com/Shopify/prettier-plugin-liquid/assets/5798388/ad8b75e5-857c-4c21-832b-5f7a520f1e8a

Additional context Fresh Dawn theme through Shopify Theme CLI installation

nikitaourazbaev commented 1 year ago

Seeing this too, in VS Code, Sublime Text and using Prettier CLI.

I think this might be the same issue as #171.

charlespwd commented 11 months ago

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