Shopify / Shopify/theme-tools

theme-check incorrectly flags options_by_name keys containing spaces as invalid

Open
#1,204 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug
When a quoted string including a space is included within the opening line of a forloop, theme-check incorrectly reports is as invalid syntax.

Source

{%- for value in product.options_by_name['hello world'].values -%}
  {{ value }}
{%- endfor -%}

Expected behaviour

The syntax is fine - there are no issues using this syntax in a theme, so there should be no reported theme-check errors.

Actual behaviour

A syntax error is reported after the space in the quoted string.

Image

Also when theme-check tries to autofix the error on save, it actually creates broken syntax.

The snippet described earlier gets "corrected" to

{%- for value in product.options_by_name['hello -%}
  {{ value }}
{%- endfor -%}

I suspect simply not flagging the error to begin would prevent this.

Debugging information

  • OS [e.g. Windows, Mac, Linux]: Mac
  • OS Version: Tahoe 26.3.1 (a)
  • Theme Check Version [e.g. 0.1.0]: 3.94.1 (shopify-cli, I'm not sure if theme check has a different version or where I'd find it)

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

Reproduce the reported Liquid for-loop in theme-check 3.94.1 and trace the parser or diagnostic path handling bracketed keys with spaces. Add a regression test for the valid options_by_name['hello world'] expression, then verify that linting reports no error and autofix does not alter the syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, 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.