Skip to content

Commit 59d92da

Browse files
committed
Updated the undefined-object theme check to skip over inline-snippets
1 parent 69282bb commit 59d92da

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

.changeset/sweet-steaks-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme-check-common': minor
3+
---
4+
5+
Updated the `Undefined-object` theme check to skip over the new `snippet` tags

packages/theme-check-common/src/checks/undefined-object/index.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,18 @@ describe('Module: UndefinedObject', () => {
459459
assert(offenses.length == 0);
460460
expect(offenses).to.be.empty;
461461
});
462+
463+
it('should not report an offense for inline snippet names in snippet and render tags', async () => {
464+
const sourceCode = `
465+
{% snippet my_inline_snippet %}
466+
{% echo 'hello' %}
467+
{% endsnippet %}
468+
469+
{% render my_inline_snippet %}
470+
`;
471+
472+
const offenses = await runLiquidCheck(UndefinedObject, sourceCode);
473+
474+
expect(offenses).toHaveLength(0);
475+
});
462476
});

packages/theme-check-common/src/checks/undefined-object/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ export const UndefinedObject: LiquidCheckDefinition = {
142142
const parent = last(ancestors);
143143
if (isLiquidTag(parent) && isLiquidTagCapture(parent)) return;
144144

145+
if (parent?.type === NodeTypes.RenderMarkup && parent.snippet === node) return;
146+
147+
if (isLiquidTag(parent) && parent.name === 'snippet' && parent.markup === node) return;
148+
145149
variables.push(node);
146150
},
147151

0 commit comments

Comments
 (0)