theme-check
theme-check copied to clipboard
Do something about the UnusedAssign fixer and `formatOnSave: true`
When running the auto correct flag on theme check it's stripping content from the final when. Two examples below:
Before
{% case image_container_width %}
{% when 'small' %}
{%- assign product_image_width = 'medium-up--two-fifths' -%}
{%- assign product_description_width = 'medium-up--three-fifths' -%}
{%- assign product_image_size = '480x' -%}
{% when 'medium' %}
{%- assign product_image_width = 'medium-up--one-half' -%}
{%- assign product_description_width = 'medium-up--one-half' -%}
{%- assign product_image_size = '620x' -%}
{% when 'large' %}
{%- assign product_image_width = 'medium-up--three-fifths' -%}
{%- assign product_description_width = 'medium-up--two-fifths' -%}
{%- assign product_image_size = '740x' -%}
{% endcase %}
After
{% case image_container_width %}
{% when 'small' %}
{%- assign product_image_width = 'medium-up--two-fifths' -%}
{%- assign product_description_width = 'medium-up--three-fifths' -%}
{%- assign product_image_size = '480x' -%}
{% when 'medium' %}
{%- assign product_image_width = 'medium-up--one-half' -%}
{%- assign product_description_width = 'medium-up--one-half' -%}
{%- assign product_image_size = '620x' -%}
{% when 'large' %}
{%- assign product_image_size = '740x' -%}
{% endcase %}
Before
{% case section.settings.grid %}
{% when '1' %}
{%- assign grid_item_width = '' -%}
{% when '2' %}
{%- assign grid_item_width = 'medium-up--one-half' -%}
{% when '3' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-third' -%}
{% when '4' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-quarter' -%}
{% when '5' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-fifth' -%}
{% endcase %}
After
{% case section.settings.grid %}
{% when '1' %}
{%- assign grid_item_width = '' -%}
{% when '2' %}
{%- assign grid_item_width = 'medium-up--one-half' -%}
{% when '3' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-third' -%}
{% when '4' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-quarter' -%}
{% when '5' %}
{% endcase %}
I can't see any reason for the variables to be removed, if I check the settings schema for the grid it has those options in, yet the variable is being removed?
{
"type": "select",
"id": "grid",
"label": "Collections per row",
"default": "3",
"options": [
{
"value": "1",
"label": "1"
},
{
"value": "2",
"label": "2"
},
{
"value": "3",
"label": "3"
},
{
"value": "4",
"label": "4"
},
{
"value": "5",
"label": "5"
}
]
}
Oh wow... What's happening here is that you have an UnusedAssign and that it's being corrected (but only on the last assign). If you rerun the corrector, it'll start happening in the other branches.
I don't know if that's still a bug or how we should fix it. But I kind of agree that you might not want this feature to run with the fixer setup with formatOnSave: true
...
In the meantime, the proper course of action would be to disable the check:
{% comment %}theme-check-disable UnusedAssign{% endcomment %}
Or in your .theme-check.yml
UnusedAssign:
enabled: false