8000 Add ability to disable theme check for next line by graygilmore · Pull Request #796 · Shopify/theme-tools · GitHub
[go: up one dir, main page]

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

Add ability to disable theme check for next line #796

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

graygilmore
Copy link
Contributor

What are you adding in this PR?

Adds the ability to disable a theme check rule only on the next line with theme-check-disable-next-line:

{% # theme-check-disable-next-line UnknownFilter %}
{{ product | foo }}

Just like theme-check-disable you can pass no specific rule to disable all rules:

{% # theme-check-disable-next-line %}
{% assign x = product | foo %}

Before you deploy

  • I included a minor bump changeset
  • (will do this once we have approval of this approach) I've made a PR to update the shopify.dev theme check docs if applicable (link PR here).
  • My feature is backward compatible

@graygilmore graygilmore force-pushed the gg-add-next-line-disable branch from 58e6628 to fe96774 Compare February 15, 2025 22:46
disabledRanges.set(check, []);
}

const nextNewLineIndex = source.slice(position.end).indexOf('\n', 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the most fragile piece of this approach. When we're in this part of the code the source is just a string. What I'm doing here is getting the index of the second new line by passing 1 as the second argument to indexOf. The very first character after the slice should be a new line which should return an index of 0 so we add 1 to that number to change the starting point of the search.

                                              slice start                                slice end
                                                   v                                          v
{% # theme-check-disable-next-line UnknownFilter %}(\n  {{ product | broken }}\n{{ variable }})
                                                    ^^                        ^^
                                               first new line            next new line (end)

@graygilmore graygilmore force-pushed the gg-add-next-line-disable branch from fe96774 to 2fe1178 Compare February 15, 2025 22:49
@graygilmore graygilmore marked this pull request as ready for review February 15, 2025 22:53
@graygilmore graygilmore requested a review from a team as a code owner February 15, 2025 22:53

const offenses = await check({ 'code.liquid': file }, checks);

expect(offenses).toHaveLength(3);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is kind of self documenting, but I had to go up to verify that the expected # of offenses is 3, and that the file value was similar to that of the previous tests. Maybe we could add a comment for that?

@graygilmore graygilmore force-pushed the gg-add-next-line-disable branch from 2fe1178 to 9ceddef Compare February 21, 2025 15:53
Copy link
Collaborator
@charlespwd charlespwd left a comment

Choose a reason for hiding this comment

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

This feels OK but can we add a test for errors that might squiggly on multiple lines?

If the disable-next-line is not entirely covering the error, is it omitted?

  {% # theme-check-disable-next-line %}
  {% render "snippet", argUnknown:
    valueUndef
   %}

What if the squiggly is in a "pretty-formatted" thing but further down?

{% # theme-check-disable-next-line %}
{{ 'arg' 
  | unknown-filter
}}

Shouldn't we try to target the next node in the tree instead? Or is this code (that I probably wrote) really not working like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't we try to target the next node in the tree instead? Or is this code (that I probably wrote) really not working like that?

@charlespwd I wish. I tired tweaking stuff a bit but by the time we get to the check we don't have that information. I'm going to have one more look at this though and make sure it wouldn't be too hard to also pass "next sibling node".

@graygilmore graygilmore force-pushed the gg-add-next-line-disable branch from 9ceddef to 9a44917 Compare February 24, 2025 18:03
@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Rebased with main

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.

[Feature] Theme check - Disable checks using Liquid comments next-line
3 participants
0