Skip to content

Commit d281688

Browse files
committed
Added doc tag support logic inside snippet tag
1 parent fa207a1 commit d281688

File tree

1 file changed

+19
-6
lines changed
  • packages/theme-check-common/src/checks/unsupported-doc-tag

1 file changed

+19
-6
lines changed

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

Lines changed: 19 additions & 6 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,30 @@ export const UnsupportedDocTag: LiquidCheckDefinition = {
1920

2021
create(context) {
2122
const docTagName = 'doc';
22-
23-
if (filePathSupportsLiquidDoc(context.file.uri)) {
24-
return {};
25-
}
23+
const snippetTagName = 'snippet';
2624

2725
return {
28-
async LiquidRawTag(node) {
26+
async LiquidRawTag(node: LiquidRawTag, ancestors: LiquidHtmlNode[]) {
2927
if (node.name !== docTagName) {
3028
return;
3129
}
30+
31+
const isInSnippetOrBlockFile = filePathSupportsLiquidDoc(context.file.uri);
32+
const immediateParent = ancestors.at(-1);
33+
const isTopLevelInFile = immediateParent?.type === NodeTypes.Document;
34+
const isDirectChildOfSnippetTag =
35+
immediateParent?.type === NodeTypes.LiquidTag && immediateParent.name === snippetTagName;
36+
37+
if ((isInSnippetOrBlockFile && isTopLevelInFile) || isDirectChildOfSnippetTag) {
38+
return;
39+
}
40+
41+
const message = isInSnippetOrBlockFile
42+
? `The \`${docTagName}\` tag must be a top-level tag within a snippet/block file`
43+
: `The \`${docTagName}\` must be placed directly within an inline snippet tag, not nested inside other tags`;
44+
3245
context.report({
33-
message: `The \`${docTagName}\` tag can only be used within a snippet or block.`,
46+
message,
3447
startIndex: node.position.start,
3548
endIndex: node.position.end,
3649
suggest: [

0 commit comments

Comments
 (0)