theme-check
theme-check copied to clipboard
New check for `for` loops used for filtering by handle
# bad
{% for product in all_products %}
{% if product.handle == 'foobar' %}
{% assign p = product %}
{% endif %}
{% endif %}
# good
{% assign p = all_products.foobar %}
Also, potentially other checks for recommending https://shopify.dev/docs/themes/liquid/reference/objects/product#product-options_by_name, and such.
Not to detract from the main reason for this issue, but am wondering if it's also worth looking for nested liquid loops...
{% for product in collection.products %}
{% for tag in product.tags %}
{% for variant in product.variants %}
{% for collection in product.collections %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
It seems there are checks in place for nested snippets, but not for
loops.
If this warrants a separate issue just say the word :)
Oh yeah this is a very good idea @darryn! Please create an issue 😄