Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Space around class_list #418

wants to merge 8 commits into from

Conversation

geddski
Copy link

@geddski geddski commented Jul 15, 2024

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 the class_list's generated class name, causing neither to work.

For example this theme check catches this problematic case:

<div class="{{ block.settings.spacing | class_list }}other-class">
    content
</div>

And this problematic case:

<div class="other-class{{ block.settings.spacing | class_list }}">
    content
</div>

Before you deploy

  • This PR includes a new checks or changes the configuration of a check
    • I included a minor bump changeset
    • It's in the allChecks array in src/checks/index.ts
    • I ran yarn build and committed the updated configuration files

@geddski geddski requested a review from albchu July 15, 2024 21:23
@geddski geddski changed the title Space-after-classlist Space after class_list Jul 15, 2024
Copy link
Contributor

@albchu albchu left a 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!

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',
Copy link
Contributor

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?

Copy link
Author

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

Copy link
Author

Choose a reason for hiding this comment

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

packages/theme-check-common/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@albchu albchu left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks Dave!

@geddski geddski marked this pull request as draft July 17, 2024 06:40
@geddski
Copy link
Author

geddski commented Jul 17, 2024

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.

@geddski geddski changed the title Space after class_list Space around class_list Jul 18, 2024
@geddski geddski marked this pull request as ready for review July 18, 2024 23:49
@geddski geddski requested a review from albchu July 18, 2024 23:50
Copy link
Contributor

@albchu albchu left a 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.
Copy link
Contributor

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.

Suggested change
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, ' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@karreiro karreiro left a 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;
Copy link
Contributor

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:

Screenshot 2024-07-22 at 08 48 34

What do you think?

Copy link
Author

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?

Copy link
Contributor

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 :)

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.

3 participants