Skip to content
Draft
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .changeset/theme-check-docs-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@shopify/theme-check-common': patch
---

Add missing `docs.url` links so editors surface a "learn more" link on these diagnostics:
`LiquidComplexity`, `LiquidNestingDepth`, `LiquidSyntaxError`, `ExcessiveSettingsCount`,
`BlockArgumentSettingCollision`, `UnknownBlockSetting`, `MaxFileSize` (Liquid and JSON variants),
`SchemaSectionOrBlockOnly`, `SchemaOncePerFile`, `JavascriptTagInWrongFile`, `JavascriptOncePerFile`,
`StylesheetTagInWrongFile`, and `StylesheetOncePerFile`.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const BlockArgumentSettingCollision: LiquidCheckDefinition = {
description:
"Reports a plain block tag argument whose name matches a setting id in the target block's schema. The author likely intended block.settings.<name>. May overlap with UnrecognizedBlockArguments, which reports the same argument as undeclared.",
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/block-argument-setting-collision',
},
type: SourceCodeType.LiquidHtml,
severity: Severity.WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const ExcessiveSettingsCount: LiquidCheckDefinition<typeof schema> = {
description:
'Reports section or block schemas that declare more top-level settings than the configured maximum.',
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/excessive-settings-count',
},
type: SourceCodeType.LiquidHtml,
severity: Severity.WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const LiquidComplexity: LiquidCheckDefinition<typeof schema> = {
docs: {
description: 'Reports Liquid files with high cyclomatic complexity.',
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-complexity',
},
type: SourceCodeType.LiquidHtml,
severity: Severity.WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const LiquidNestingDepth: LiquidCheckDefinition<typeof schema> = {
docs: {
description: 'Reports Liquid files with deeply nested control-flow structures.',
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-nesting-depth',
},
type: SourceCodeType.LiquidHtml,
severity: Severity.WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const LiquidSyntaxError: LiquidCheckDefinition = {
docs: {
description: 'Reports Liquid syntax errors.',
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-syntax-error',
},
type: SourceCodeType.LiquidHtml,
severity: Severity.ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const MaxFileSize: LiquidCheckDefinition = {
docs: {
description: "Reports theme files that exceed Shopify's maximum file size.",
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/max-file-size',
},
type: SourceCodeType.LiquidHtml,
severity: Severity.ERROR,
Expand Down
29 changes: 21 additions & 8 deletions packages/theme-check-common/src/checks/raw-tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ interface RawTagCheckOptions {
tagName: RawTagName;
code: string;
message: string;
url: string;
}

function capitalize(tagName: RawTagName): string {
return tagName[0].toUpperCase() + tagName.slice(1);
}

function rawTagCheck({ tagName, code, message }: RawTagCheckOptions): LiquidCheckDefinition {
function rawTagCheck({ tagName, code, message, url }: RawTagCheckOptions): LiquidCheckDefinition {
return {
meta: {
code,
name: code,
docs: {
description: message,
recommended: true,
url,
},
type: SourceCodeType.LiquidHtml,
severity: Severity.ERROR,
Expand All @@ -46,7 +48,7 @@ function rawTagCheck({ tagName, code, message }: RawTagCheckOptions): LiquidChec

function sectionOrBlockOnlyCheck(
tagName: RawTagName,
{ allowSnippets }: { allowSnippets: boolean },
{ allowSnippets, url }: { allowSnippets: boolean; url: string },
): LiquidCheckDefinition {
const locations = allowSnippets ? 'section, block, or snippet' : 'section or block';

Expand All @@ -60,10 +62,11 @@ function sectionOrBlockOnlyCheck(
tagName,
code,
message: `{% ${tagName} %} is only valid in ${locations} files.`,
url,
});
}

function oncePerFileCheck(tagName: RawTagName): LiquidCheckDefinition {
function oncePerFileCheck(tagName: RawTagName, { url }: { url: string }): LiquidCheckDefinition {
const code = `${capitalize(tagName)}OncePerFile`;
const message = `{% ${tagName} %} can only appear once per file.`;

Expand All @@ -74,6 +77,7 @@ function oncePerFileCheck(tagName: RawTagName): LiquidCheckDefinition {
docs: {
description: message,
recommended: true,
url,
},
type: SourceCodeType.LiquidHtml,
severity: Severity.ERROR,
Expand Down Expand Up @@ -103,9 +107,9 @@ function oncePerFileCheck(tagName: RawTagName): LiquidCheckDefinition {

function sectionOrBlockOnlyUnlessAllowed(
tagName: RawTagName,
{ allowSnippets }: { allowSnippets: boolean },
{ allowSnippets, url }: { allowSnippets: boolean; url: string },
): LiquidCheckDefinition {
const check = sectionOrBlockOnlyCheck(tagName, { allowSnippets });
const check = sectionOrBlockOnlyCheck(tagName, { allowSnippets, url });

return {
...check,
Expand All @@ -121,13 +125,22 @@ function sectionOrBlockOnlyUnlessAllowed(

export const SchemaSectionOrBlockOnly = sectionOrBlockOnlyUnlessAllowed('schema', {
allowSnippets: false,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/schema-section-or-block-only',
});
export const SchemaOncePerFile = oncePerFileCheck('schema', {
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/schema-once-per-file',
});
export const SchemaOncePerFile = oncePerFileCheck('schema');
export const JavascriptTagInWrongFile = sectionOrBlockOnlyUnlessAllowed('javascript', {
allowSnippets: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/javascript-tag-in-wrong-file',
});
export const JavascriptOncePerFile = oncePerFileCheck('javascript', {
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/javascript-once-per-file',
});
export const JavascriptOncePerFile = oncePerFileCheck('javascript');
export const StylesheetTagInWrongFile = sectionOrBlockOnlyUnlessAllowed('stylesheet', {
allowSnippets: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/stylesheet-tag-in-wrong-file',
});
export const StylesheetOncePerFile = oncePerFileCheck('stylesheet', {
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/stylesheet-once-per-file',
});
export const StylesheetOncePerFile = oncePerFileCheck('stylesheet');
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const UnknownBlockSetting: LiquidCheckDefinition = {
description:
"Reports a block.settings.<name> argument in a block tag where <name> is not a setting id in the target block's schema.",
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/unknown-block-setting',
},
type: SourceCodeType.LiquidHtml,
severity: Severity.WARNING,
Expand Down
Loading