-
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
Space around class_list #418
base: main
Are you sure you want to change the base?
Conversation
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.
Just a few tweaks and questions but looking good!
packages/theme-check-common/src/checks/space-after-class_list/index.ts
Outdated
Show resolved
Hide resolved
docs: { | ||
description: 'Warns you when there is no space after using the class_list filter', | ||
recommended: true, | ||
url: 'https://shopify.dev/docs/themes/tools/theme-check/checks/space-after-class_list', |
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 there another PR I can check out for this?
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.
knew I was forgetting something! I'll see how to add that one sec
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.
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.
lgtm! Thanks Dave!
Tyler had a great point that the same issue can happen with classes before class_list, so I'm going to update this theme check and its docs to account for that. |
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.
LGTM. One minor doc change suggestion but then youre good to go! Thanks Dave :)
@@ -104,7 +104,9 @@ If ever you want to see how the VS Code extension or playground would behave bef | |||
theme-docs download | |||
``` | |||
|
|||
6. Proceed to debug the VS Code extension or playground as usual. | |||
6. Note that you may have to delete the cached data directory (`~/Library/Caches/theme-liquid-docs-nodejs`) in order to see your changes. |
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.
Since this is general contribution docs, we should probably be a bit more specific about what this instruction is alluding to.
6. Note that you may have to delete the cached data directory (`~/Library/Caches/theme-liquid-docs-nodejs`) in order to see your changes. | |
6. Note when working on changes to theme-liquid-docs: You will have to delete the cached data directory (`~/Library/Caches/theme-liquid-docs-nodejs`) in order to see changes made to `packages/theme-check-docs-updater/data`. |
{ | ||
message: 'Add a space after the class_list filter', | ||
fix(corrector) { | ||
corrector.insert(errorPosition, ' '); |
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.
Nice!
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.
Thank you for this PR, @geddski! I've left only one minor suggestion about how we capture the absence of the space character. Please let me know what you think about that :)
''; | ||
|
||
// check for missing space after class_list | ||
const afterRegex = /([a-zA-Z0-9._-]+)\s*\|\s*class_list\s*}}([a-zA-Z0-9._-]+)/gm; |
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 believe we have valid cases, such as the following one where we want to raise an offense:
<div class="{{ block.settings.spacing | class_list }}{{ shop.name }}other-class">content</div>
It's a bit changeling to cover that case relying on the regex tho. Instead, I believe we may navigate in the AST and can check if the sibling node starts with a space:
What do you think?
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.
ah, another interesting case. I'm glad y'all know your liquid! Would it be correct then to say the filter's next sibling (if any) must be a TextNode that starts with whitespace?
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.
Yes, that's my understanding as well :)
What are you adding in this PR?
This theme check ensures that a space is used before and after the
class_list
filter. Otherwise the CSS classes before/after the filter will be concatenated to theclass_list
's generated class name, causing neither to work.For example this theme check catches this problematic case:
And this problematic case:
Before you deploy
changeset
allChecks
array insrc/checks/index.ts
yarn build
and committed the updated configuration files