11import { isSnippet , isBlock } from '../../to-schema' ;
22import { LiquidCheckDefinition , Severity , SourceCodeType } from '../../types' ;
33import { filePathSupportsLiquidDoc } from '../../liquid-doc/utils' ;
4+ import { LiquidRawTag , NodeTypes , LiquidHtmlNode } from '@shopify/liquid-html-parser' ;
45
56export 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