Skip to content

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

Open
SinhSinhAn wants to merge 1 commit intoShopify: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 intoShopify:mainfrom
SinhSinhAn:feat/valid-select-default

Conversation

@SinhSinhAn
Copy link
Copy Markdown
Contributor

@SinhSinhAn SinhSinhAn commented Apr 20, 2026

Summary

Closes #943.

Hey yall this PR wires up the warning @charlespwd asked for. Today you can happily write a select setting whose default doesn't exist in options, and theme-check says nothing. Same story for presets[].settings and a section's default.settings block — you only find out the value is bogus when the editor silently falls back or when QA catches it.

This PR adds a new check, ValidSelectDefault, that catches all three cases up front:

  • If a select or radio setting's default isn't one of the options[].values, you get a warning on the default line with the list of values it should have been.
  • If a preset sets a value for a select/radio setting that isn't in that setting's options, you get a warning right on the offending value inside presets[i].settings.
  • Section schemas are covered the same way for their default.settings block.

It runs in two places, mirroring how ValidVisibleIf does it:

  • LiquidCheck{% schema %} in sections/*.liquid and blocks/*.liquid
  • JSONCheckconfig/settings_schema.json

The check is WARNING severity and recommended: true, so it shows up out of the box without being a merge-blocker for anyone with legacy schemas.

Example (from the issue)

{
  "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 flags: Default value "this-is-not-an-option" for setting "alignment" is not one of the valid options: "flex-start", "center", "flex-end".

And the preset case from the issue:

"presets": [
  {
    "name": "t:general.column",
    "settings": { "alignment": "this-is-not-an-option" }
  }
]

…gets a warning on the value itself, pointing right at the bad literal.

Test plan

  • 13 new unit tests in valid-select-default/index.spec.ts covering:
    • valid + invalid default for select and radio
    • setting with no default (no-op)
    • non-choice settings left alone
    • valid + invalid preset values
    • preset referencing non-select setting (no-op)
    • section default.settings invalid value
    • config/settings_schema.json via JSONCheck (valid, invalid, wrong-file path)
    • combined default + preset case reports both
  • Full @shopify/theme-check-common suite stays green (875 tests, 98 files)
  • Changeset added as a minor bump

@SinhSinhAn SinhSinhAn requested a review from a team as a code owner April 20, 2026 00:41
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 ee0c3f2 to e5c9de8 Compare April 20, 2026 00:42
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.

I would like to be warned when a select setting's default value is not a valid option.

1 participant