Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isSnippet, isBlock } from '../../to-schema';
import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
import { filePathSupportsLiquidDoc } from '../../liquid-doc/utils';
import { LiquidRawTag, NodeTypes, LiquidHtmlNode } from '@shopify/liquid-html-parser';

export const UnsupportedDocTag: LiquidCheckDefinition = {
meta: {
Expand All @@ -19,18 +20,30 @@ export const UnsupportedDocTag: LiquidCheckDefinition = {

create(context) {
const docTagName = 'doc';

if (filePathSupportsLiquidDoc(context.file.uri)) {
return {};
}
const snippetTagName = 'snippet';

return {
async LiquidRawTag(node) {
async LiquidRawTag(node: LiquidRawTag, ancestors: LiquidHtmlNode[]) {
if (node.name !== docTagName) {
return;
}

const isInSnippetOrBlockFile = filePathSupportsLiquidDoc(context.file.uri);
const immediateParent = ancestors.at(-1);
const isTopLevelInFile = immediateParent?.type === NodeTypes.Document;
const isDirectChildOfSnippetTag =
immediateParent?.type === NodeTypes.LiquidTag && immediateParent.name === snippetTagName;

if ((isInSnippetOrBlockFile && isTopLevelInFile) || isDirectChildOfSnippetTag) {
return;
}

const message = isInSnippetOrBlockFile
? `The \`${docTagName}\` tag cannot be nested inside any Liquid tags in a snippet or block file`
: `The \`${docTagName}\` must be placed directly within an inline snippet tag, not nested inside other tags`;

context.report({
message: `The \`${docTagName}\` tag can only be used within a snippet or block.`,
message,
startIndex: node.position.start,
endIndex: node.position.end,
suggest: [
Expand Down
Loading