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

Add support for case and when tags #78

Merged
merged 2 commits into from
Aug 22, 2022
Merged

Conversation

charlespwd
Copy link
Collaborator

@charlespwd charlespwd commented Aug 17, 2022

In this PR

  • Add support for case tag
  • Add support for when tag

Decisions

  • Never break case
  • Only break when when the undocumented comma or or syntax is used
    • Same way as the others

Examples

It should break and indent when statements, and not break the when
printWidth: 1
{% case candy.type %}
  {% when 'gummy bears' %}
    yum!
  {% else %}
    ok!
{% endcase %}

It should break on when comma syntax
printWidth: 1
{% case candy.type %}
  {% when 'gummy bears',
    'chocolate'
  %}
    yum!
  {% else %}
    ok!
{% endcase %}

It should break on when or syntax (and prefer commas)
printWidth: 1
{% case candy.type %}
  {% when 'gummy bears',
    'chocolate',
    'chips'
  %}
    yum!
  {% else %}
    ok!
{% endcase %}

@charlespwd charlespwd requested a review from a team August 17, 2022 19:19
@charlespwd charlespwd linked an issue Aug 18, 2022 that may be closed by this pull request
Base automatically changed from fix/62-conditional-tags to main August 19, 2022 17:33
Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @charlespwd! I've left only one minor/optional comment :)

Comment on lines +30 to +34
{% case candy.type %}
{% when 'gummy bears',
'chocolate',
'chips'
%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if users would prefer something like this:

Suggested change
{% case candy.type %}
{% when 'gummy bears',
'chocolate',
'chips'
%}
{% case candy.type %}
{% when 'gummy bears',
'chocolate',
'chips'
%}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that happens in languages like python and ruby but is really frowned upon in front-end communities (never seen it in JS, CSS, TS). I did see it in clojure/clojurescript but it takes a good editor plugin to handle it properly. Trying to do that manually is a PITA.

I feel like you should be able to manually indent your code reasonably and that feels hard. It's 4 tabs in! And if you use {%-, that'd be 4 tabs + 1 space.

😬

@charlespwd charlespwd merged commit f75f7ba into main Aug 22, 2022
@charlespwd charlespwd deleted the fix/63-case-when-tags branch August 22, 2022 16:33
@shopify-shipit shopify-shipit bot temporarily deployed to production August 26, 2022 14:08 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prettier Liquid: case, when
2 participants