Skip to content

feat(theme-check-common): warn when select default isn't a valid option#1185

Open
SinhSinhAn wants to merge 1 commit into
Shopify:mainfrom
SinhSinhAn:feat/valid-select-default
Open

feat(theme-check-common): warn when select default isn't a valid option#1185
SinhSinhAn wants to merge 1 commit into
Shopify:mainfrom
SinhSinhAn:feat/valid-select-default

Conversation

@SinhSinhAn

@SinhSinhAn SinhSinhAn commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

What are you adding in this PR?

This adds a new theme-check, ValidSelectDefault, that warns when a select or radio setting's default value isn't one of the values declared in its options. Today you can ship a schema whose default doesn't exist in options and theme-check stays silent. The merchant then sees the editor silently fall back to the first option (or no selection), which is confusing and easy to miss in review.

solves #943

The check validates three places:

  • A setting's default value.
  • A preset's settings values (presets[i].settings).
  • A section's default.settings values.

It runs in two variants, mirroring ValidVisibleIf:

  • ValidSelectDefault (LiquidCheck) → {% schema %} in sections/*.liquid and blocks/*.liquid.
  • ValidSelectDefaultSettingsSchema (JSONCheck) → config/settings_schema.json.

Severity is WARNING and it's recommended: true, so it surfaces out of the box without blocking themes that have legacy schemas.

Example

{
  "type": "select",
  "id": "alignment",
  "default": "this-is-not-an-option",
  "options": [
    { "value": "flex-start", "label": "t:options.alignment.left" },
    { "value": "center",     "label": "t:options.alignment.center" },
    { "value": "flex-end",   "label": "t:options.alignment.right" }
  ]
}

Now warns: Default value "this-is-not-an-option" for setting "alignment" is not one of the valid options: "flex-start", "center", "flex-end".

The preset case from the issue gets a warning pointing right at the offending value inside presets[i].settings.

What's next? Any followup issues?

None planned. The check leaves non-scalar mismatches to JSON schema validation, so it stays focused on the select/radio option case.

What did you learn?

The factory configs (all.yml / recommended.yml) are generated from meta.code, so two checks sharing the same code (the Liquid + JSON variants, like ValidVisibleIf) collapse to a single config entry.

Tophatting

  • I added screenshots of the changes (before and after the changes if applicable)

Tested via unit tests rather than screenshots (this is a non-visual lint check). 13 new tests in valid-select-default/index.spec.ts cover:

  • valid + invalid default for select and radio
  • setting with no default (no-op)
  • non-choice settings left alone
  • valid + invalid preset values
  • preset referencing a non-select setting (no-op)
  • section default.settings invalid value
  • config/settings_schema.json via the JSONCheck variant (valid, invalid, wrong-file path)
  • combined default + preset case reporting both
✓ packages/theme-check-common/src/checks/valid-select-default/index.spec.ts (13 tests)

The full theme-check-common checks suite stays green (780 tests across 79 files), and tsc --noEmit passes.

Before you deploy

  • This PR includes a new check

    • I included a minor bump changeset
    • I ran pnpm build and committed the updated configuration files (all.yml, recommended.yml)
      • If applicable, I've updated the theme-app-extension.yml config — not applicable; the check is generally relevant and isn't theme-app-extension specific.
      • [Shopifolk] I've made a PR to update the shopify.dev theme check docs — N/A (not a Shopifolk).
  • My feature is backward compatible

@aswamy aswamy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @SinhSinhAn, thanks for another PR. Please ensure all of your PRs (including this one) follows our PR template to ensure everything is tested properly before submitting it:
https://github.com/Shopify/theme-tools/blob/main/.github/PULL_REQUEST_TEMPLATE.md

I've also written some review comments below.

Comment thread packages/theme-check-common/src/checks/valid-select-default/index.ts Outdated
Warns when a select/radio setting's default value, a preset's setting
value, or a section default.settings value is not one of the setting's
declared options. Covers {% schema %} in sections/blocks and
config/settings_schema.json.

Closes Shopify#943
@SinhSinhAn SinhSinhAn force-pushed the feat/valid-select-default branch from e5c9de8 to 0f68bc0 Compare June 13, 2026 23:16
@SinhSinhAn

SinhSinhAn commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @aswamy! Addressed everything:

  • PR template - rewrote the description to follow the template (What/What's next/What did you learn/Tophatting/Before you deploy), with the new-check checklist filled in.
  • Recommended check configs —-rebased onto main (so I'm on pnpm now), ran pnpm build, and committed the regenerated all.yml and recommended.yml. Both now carry a ValidSelectDefault entry at severity 1.
  • Formatting - ran the formatter; the check files and checks/index.ts are prettier-clean.

The branch is rebased to a single commit on top of latest main. theme-check-common checks suite is green (780 tests) and tsc --noEmit passes.

@aswamy

aswamy commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@SinhSinhAn please include a screenshot to ensure this VSCode extension was actually tested when running theme-tools. Not just unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants