-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added in a check for theme block settings validation #620
base: main
Are you sure you want to change the base?
Conversation
b95fc84
to
866ea6c
Compare
docs: { | ||
description: 'Reports invalid preset settings for a theme block', | ||
recommended: true, | ||
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/preset-key-exists', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/preset-key-exists', | |
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/valid-block-preset-settings, |
name: 'Reports invalid preset settings for a theme block', | ||
docs: { | ||
description: 'Reports invalid preset settings for a theme block', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it only theme blocks or just blocks in general?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will validate on any block. I can remove "theme" so its more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, whatever block is in the presets settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think abstract block would be fine here
packages/theme-check-common/src/checks/valid-block-preset-settings/index.ts
Outdated
Show resolved
Hide resolved
startIndex: 0, | ||
endIndex: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to highlight the node. I don't think it's ok to have 0:0 for this check.
schema
has a ast
property you can use to find the node. We also have the nodeAtPath
util that can give you the AST node for a given "JSONPath"
const schema = await getSchema();
if (!schema) return;
if (isError(schema.validSchema) || isError(schema.ast)) return;
// imagine that we somehow find out that ["presets", 0, "settings", "unknown-id"] is invalid:
// we can report an error like this:
const settingsNode = nodeAtPath(schema.ast, ['presets', 0, 'settings']) as ObjectNode;
if (!settingsNode) throw new Error('Should not be happening');
// This is a PropertyNode | undefined
const propertyNode = settingsNode.children.find((child) => child.key.value === 'unknown-id');
if (!propertyNode) throw new Error('Should not be happening');
context.report({
message: `...`,
startIndex: schemaNodeOffset + propertyNode.loc!.start.offset,
endIndex: schemaNodeOffset + propertyNode.loc!.end.offset,
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Position information can't be ignored for this check. We'll probably need to rewrite it and iterate over each blocks separately rather than push all of them in the same bucket.
b20d7f0
to
0a7932b
Compare
05d6e6c
to
07c3295
Compare
3ef48eb
to
eee6ce7
Compare
Finished tests Added changeset
eee6ce7
to
6f90bcc
Compare
8f6b402
to
8745150
Compare
What are you adding in this PR?
First part of #602
Adding in a theme check for checking theme blocks for valid preset setting keys. The preset setting keys (and the presets of any theme block preset settings) must match the settings keys configured in either the preset settings or the nested theme block settings.
Docs PR: https://github.com/Shopify/shopify-dev/pull/51243
What's next? Any followup issues?
The next issue is to add the exact same type of theme check for section files, just with more coverage.
What did you learn?
A lot about presets, sections and theme blocks and how they are configured. That was the trickiest part of all of this (managing the types, knowing how to grab nested information, etc).
Before you deploy
changeset
allChecks
array insrc/checks/index.ts
yarn build
and committed the updated configuration filestheme-app-extension.yml
configchangeset
changeset