Shopify / Shopify/theme-tools

False Positive "Variable Assigned but Not Used" in Style Tags

Open
#465 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Severity: 3
Dominant language
TypeScript
Stars
234
Forks
92
Avg merge
1d 3h
Merged PRs (30d)
6

Description

Description:

Theme check is incorrectly identifying variables assigned or captured within a {% liquid %} tag as assigned but not used. This occurs even though the variables are then used with echo withinstyle .

Steps to Reproduce:

  1. Create a Liquid template file.
  2. Inside a style {% liquid %} tag:
    • Assign a variable using {% assign shopName = shop.name %}.
    • Capture content using {% capture example %} and echo 'Shopify' {% endcapture %}.
    • Use echo to output the captured content (echo example) and the assigned variable (echo shopName).
  3. Run the linter or theme check.

Expected Behavior:

The linter should not report any errors for the assigned or captured variables since they are used within the style tag.

Actual Behavior:

The linter flags an error message stating "The variable is assigned but not used."

Source Code:

{%- liquid
                              
assign shopName = shop.name

capture example
  echo 'Shopify'
endcapture
                            
 style
  echo example
  echo shopName
endstyle
-%}

Additional Information:

  • OS: Mac
  • OS Version: Latest
  • Theme Check Version: Latest

Additional context
Screenshot 2024-08-04 at 12 49 56

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in a Liquid template and running the theme checker or linter; the issue does not name a source file or test. Trace how variables assigned or captured inside a style Liquid tag are checked when later used with echo, and consider the work complete when both variables no longer produce unused-variable errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.