feat(theme-check-common): warn when select default isn't a valid option#1185
Open
SinhSinhAn wants to merge 1 commit intoShopify:mainfrom
Open
feat(theme-check-common): warn when select default isn't a valid option#1185SinhSinhAn wants to merge 1 commit intoShopify:mainfrom
SinhSinhAn wants to merge 1 commit intoShopify:mainfrom
Conversation
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
ee0c3f2 to
e5c9de8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #943.
Hey yall this PR wires up the warning @charlespwd asked for. Today you can happily write a
selectsetting whosedefaultdoesn't exist inoptions, and theme-check says nothing. Same story forpresets[].settingsand a section'sdefault.settingsblock — 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:selectorradiosetting'sdefaultisn't one of theoptions[].values, you get a warning on thedefaultline with the list of values it should have been.presets[i].settings.default.settingsblock.It runs in two places, mirroring how
ValidVisibleIfdoes it:LiquidCheck→{% schema %}insections/*.liquidandblocks/*.liquidJSONCheck→config/settings_schema.jsonThe check is
WARNINGseverity andrecommended: 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:
…gets a warning on the value itself, pointing right at the bad literal.
Test plan
valid-select-default/index.spec.tscovering:defaultforselectandradiodefault(no-op)default.settingsinvalid valueconfig/settings_schema.jsonviaJSONCheck(valid, invalid, wrong-file path)@shopify/theme-check-commonsuite stays green (875 tests, 98 files)minorbump