-
Notifications
You must be signed in to change notification settings - Fork 56
Updated the undefined-object theme check to skip over inline-snippets #1071
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
base: main
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
a73757e to
69282bb
Compare
dc2709d to
59d92da
Compare
59d92da to
6189068
Compare
|
|
||
| if (parent?.type === NodeTypes.RenderMarkup && parent.snippet === node) return; | ||
|
|
||
| if (isLiquidTag(parent) && parent.name === 'snippet' && parent.markup === node) return; |
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 this supposed to be a temporary fix or something instead of just adding it our list of valid liquid tags?
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 already added snippet to our list of valid liquid tags (in packages/liquid-html-parser/src/types.ts) but it still warns me 🤔
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 this because we load the tags from a different repo?
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 that repo is used for the documentation, autocomplete and validation of the tag itself. And also the capture tag is using a similar approach by skipping over the newly defined object in the capture tag so that the theme check won't warn you about it (I might just use the same format as the capture case)
29f7468 to
a2a2a95
Compare
a2a2a95 to
d859b07
Compare
| indexVariableScope(paramName, { | ||
| start: snippetAncestor.blockStartPosition.end, | ||
| end: snippetAncestor.blockEndPosition?.start, | ||
| }); |
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.
TIL Cool didn't even know we had a variable scope like this
d859b07 to
fa207a1
Compare
| const parent = last(ancestors); | ||
| if (isLiquidTag(parent) && isLiquidTagCapture(parent)) return; | ||
|
|
||
| if (isLiquidTag(parent) && isLiquidTagSnippet(parent) && parent.markup === node) return; |
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.
What's the parent.markup === node part supposed to catch?
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.
That's an oversight on my part. I think I added that before creating the isLiquidTagSnippet() function and forgot to remove it. Thanks!
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.
So i think you have the right logic, but i think you need to modify the logic on line 48:
if (relativePath.startsWith('snippets/') && !hasLiquidDoc(ast)) return {};
This might not make too much sense, but here is the logic:
- There exists real world snippets (especially old ones) that DONT have
doctag - The code above ensures that we only have UndefinedObject errors on snippets IF they have
doctag because technically, you can pass ANYTHING into snippets, and without adoctag we don't really know which one is Defined, and which one isn't - But by introducing inline snippets, we have a slight problem: having a
doctag inside the inline snippets don't mean the top-level snippet file has one too...
So we need a robust solution that works for the following situations:
- What happens when you have no doc tags in the parent snippet AND the inline snippets
- What happens when you have doc tag in the parent, but not in the inline snippets
- What happens when you have doc tag in the inline snippets, but not in the parent
- What happens when you have doc tag in both
I think we need to layout each situation before full implementation of 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.
Ok so basically we would want:
- no checks at all if both the snippet file and inline snippet don't have any doc tags
- yes checks when there is a doc tag at its respective scope, for example when there is a doc tag in the main snippet file and none inside the inline snippet:
{%- comment -%} snippets/my-snippet.liquid {%- endcomment -%}
{% doc %}
@param {string} parent_param
{% enddoc %}
{{ parent_param }} <- ✅ Should NOT warn
{{ undefined_in_parent }} <- ❓ Should this warn? YES
{% snippet inline_one %}
{{ undefined_in_inline }} <- ❓ Should this warn? NO
{% endsnippet %}
And when the doc tag is inside the inline snippet, the check will be activated only on the inside of the inline snippet, and not outside of it.
I'll implement this right now.
fa207a1 to
3274d57
Compare

What are you adding in this PR?
Disabled the "Undefined Object" theme check for the new
snippettag to prevent false positives.This change also includes making the check scope-aware based on inline snippets' doc tag parameters.
Behaviour before change:
Behaviour after change:
Before you deploy
changeset