Skip to content

Commit 55e2001

Browse files
committed
Added doc tag support logic inside snippet tag
1 parent a73757e commit 55e2001

File tree

1 file changed

+13
-2
lines changed
  • packages/theme-check-common/src/checks/unsupported-doc-tag

1 file changed

+13
-2
lines changed

packages/theme-check-common/src/checks/unsupported-doc-tag/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isSnippet, isBlock } from '../../to-schema';
22
import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
33
import { filePathSupportsLiquidDoc } from '../../liquid-doc/utils';
4+
import { LiquidRawTag, NodeTypes, LiquidHtmlNode } from '@shopify/liquid-html-parser';
45

56
export const UnsupportedDocTag: LiquidCheckDefinition = {
67
meta: {
@@ -19,18 +20,28 @@ export const UnsupportedDocTag: LiquidCheckDefinition = {
1920

2021
create(context) {
2122
const docTagName = 'doc';
23+
const snippetTagName = 'snippet';
2224

2325
if (filePathSupportsLiquidDoc(context.file.uri)) {
2426
return {};
2527
}
2628

2729
return {
28-
async LiquidRawTag(node) {
30+
async LiquidRawTag(node: LiquidRawTag, ancestors: LiquidHtmlNode[]) {
2931
if (node.name !== docTagName) {
3032
return;
3133
}
34+
35+
const isInsideSnippetTag = ancestors.some((ancestor) => {
36+
return ancestor.type === NodeTypes.LiquidTag && ancestor.name === snippetTagName;
37+
});
38+
39+
if (isInsideSnippetTag) {
40+
return;
41+
}
42+
3243
context.report({
33-
message: `The \`${docTagName}\` tag can only be used within a snippet or block.`,
44+
message: `The \`${docTagName}\` tag can only be used within an inline snippet, snippet or block.`,
3445
startIndex: node.position.start,
3546
endIndex: node.position.end,
3647
suggest: [

0 commit comments

Comments
 (0)