Shopify / theme-check

The Ultimate Shopify Theme Linter
Other
337 stars 95 forks source link

UnusedAssign reported when using "with" for render #582

Closed bakura10 closed 2 years ago

bakura10 commented 2 years ago

Hi,

Assuming the following Liquid code:

{%- case status -%}
  {%- when 'success' -%}
    {%- assign icon = 'success' -%}
  {%- when 'error' -%}
    {%- assign icon = 'error' -%}
  {%- when 'warning' -%}
    {%- assign icon = 'warning' -%}
{%- endcase -%}

<div class="banner banner--{{ status }} {% if text_alignment != 'left' %}justify-center{% endif %}">
  {%- render 'icon' with icon, width: icon_width, height: icon_width -%}
  {{- content -}}
</div>

The linter report the "icon" assigned to not be used (which is not the case, it is used in the "with" attribute).

charlespwd commented 2 years ago

Hey @bakura10, thanks for reporting!

(Side note: Looks like yet another ParseTreeVisitor shopify/liquid bug.)

charlespwd commented 2 years ago

Yeah we'd need @variable_name to be added here: https://github.com/Shopify/liquid/blob/master/lib/liquid/tags/render.rb#L78

charlespwd commented 2 years ago

@bakura, released in v1.11.0

bakura10 commented 2 years ago

Thanks a lot ! I will try and report ;)