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
26 changes: 14 additions & 12 deletions packages/theme-check-common/src/checks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigTarget, JSONCheckDefinition, LiquidCheckDefinition } from '../types';

import { AppBlockMissingSchema } from './app-block-missing-schema';
import { AppBlockValidTags } from './app-block-valid-tags';
import { AssetPreload } from './asset-preload';
import { AssetSizeAppBlockCSS } from './asset-size-app-block-css';
Expand All @@ -11,9 +12,9 @@ import { CaptureOnContentForBlock } from './capture-on-content-for-block';
import { CdnPreconnect } from './cdn-preconnect';
import { ContentForHeaderModification } from './content-for-header-modification';
import { DeprecateBgsizes } from './deprecate-bgsizes';
import { DeprecateLazysizes } from './deprecate-lazysizes';
import { DeprecatedFilter } from './deprecated-filter';
import { DeprecatedTag } from './deprecated-tag';
import { DeprecateLazysizes } from './deprecate-lazysizes';
import { EmptyBlockContent } from './empty-block-content';
import { ImgWidthAndHeight } from './img-width-and-height';
import { JSONMissingBlock } from './json-missing-block';
Expand All @@ -25,18 +26,19 @@ import { MissingAsset } from './missing-asset';
import { MissingTemplate } from './missing-template';
import { PaginationSize } from './pagination-size';
import { ParserBlockingScript } from './parser-blocking-script';
import { SchemaPresetsBlockOrder } from './schema-presets-block-order';
import { SchemaPresetsStaticBlocks } from './schema-presets-static-blocks';
import { RemoteAsset } from './remote-asset';
import { RequiredLayoutThemeObject } from './required-layout-theme-object';
import { SchemaPresetsBlockOrder } from './schema-presets-block-order';
import { SchemaPresetsStaticBlocks } from './schema-presets-static-blocks';
import { TranslationKeyExists } from './translation-key-exists';
import { UnclosedHTMLElement } from './unclosed-html-element';
import { UndefinedObject } from './undefined-object';
import { UniqueSettingIds } from './unique-settings-id';
import { UniqueStaticBlockId } from './unique-static-block-id';
import { UnknownFilter } from './unknown-filter';
import { UnusedAssign } from './unused-assign';
import { ValidContentForArguments } from './valid-content-for-arguments';
import { ValidBlockTarget } from './valid-block-target';
import { ValidContentForArguments } from './valid-content-for-arguments';
import { ValidHTMLTranslation } from './valid-html-translation';
import { ValidJSON } from './valid-json';
import { ValidLocalBlocks } from './valid-local-blocks';
Expand All @@ -47,10 +49,10 @@ import { ValidSettingsKey } from './valid-settings-key';
import { ValidStaticBlockType } from './valid-static-block-type';
import { ValidVisibleIf, ValidVisibleIfSettingsSchema } from './valid-visible-if';
import { VariableName } from './variable-name';
import { AppBlockMissingSchema } from './app-block-missing-schema';
import { UniqueSettingIds } from './unique-settings-id';
import { VisibleIfUsage } from './visible-if-usage';

export const allChecks: (LiquidCheckDefinition | JSONCheckDefinition)[] = [
AppBlockMissingSchema,
AppBlockValidTags,
AssetPreload,
AssetSizeAppBlockCSS,
Expand All @@ -74,13 +76,12 @@ export const allChecks: (LiquidCheckDefinition | JSONCheckDefinition)[] = [
MatchingTranslations,
MissingAsset,
MissingTemplate,
AppBlockMissingSchema,
PaginationSize,
ParserBlockingScript,
SchemaPresetsBlockOrder,
SchemaPresetsStaticBlocks,
RemoteAsset,
RequiredLayoutThemeObject,
SchemaPresetsBlockOrder,
SchemaPresetsStaticBlocks,
TranslationKeyExists,
UnclosedHTMLElement,
UndefinedObject,
Expand All @@ -89,18 +90,19 @@ export const allChecks: (LiquidCheckDefinition | JSONCheckDefinition)[] = [
UnknownFilter,
UnusedAssign,
ValidBlockTarget,
ValidHTMLTranslation,
ValidContentForArguments,
ValidHTMLTranslation,
ValidJSON,
ValidLocalBlocks,
ValidRenderSnippetParams,
ValidSchema,
ValidSchemaName,
ValidSettingsKey,
ValidStaticBlockType,
ValidVisibleIf,
ValidVisibleIfSettingsSchema,
VariableName,
ValidRenderSnippetParams,
ValidSchemaName,
VisibleIfUsage,
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ describe('Module: SchemaPresetsStaticBlocks', () => {

const offenses = await runLiquidCheck(SchemaPresetsStaticBlocks, sourceCode, DEFAULT_FILE_NAME);
expect(offenses).toHaveLength(1);
console.log(offenses);
expect(offenses[0].message).toEqual(
'Static block block-2 is missing a corresponding content_for "block" tag.',
);
Expand Down Expand Up @@ -134,7 +133,6 @@ describe('Module: SchemaPresetsStaticBlocks', () => {

const offenses = await runLiquidCheck(SchemaPresetsStaticBlocks, sourceCode, DEFAULT_FILE_NAME);
expect(offenses).toHaveLength(1);
console.log(offenses);
expect(offenses[0].message).toEqual(
'Static block block-2 is missing a corresponding content_for "block" tag.',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
isInvalidPresetBlock,
validateNestedBlocks,
validateBlockFileExistence,
reportWarning,
reportOnJsonNode,
} from '../../utils';
type BlockNodeWithPath = {
node: Section.Block | ThemeBlock.Block | Preset.Block;
Expand Down Expand Up @@ -61,7 +61,7 @@ export const ValidBlockTarget: LiquidCheckDefinition = {
const exists = await validateBlockFileExistence(node.type, context);
if (!exists) {
errorsInRootLevelBlocks = true;
reportWarning(
reportOnJsonNode(
`Theme block 'blocks/${node.type}.liquid' does not exist.`,
offset,
typeNode,
Expand All @@ -87,7 +87,7 @@ export const ValidBlockTarget: LiquidCheckDefinition = {
const errorMessage = isPrivateBlockType
? `Theme block type "${node.type}" is a private block so it must be explicitly allowed in "blocks" at the root of this schema.`
: `Theme block type "${node.type}" must be allowed in "blocks" at the root of this schema.`;
reportWarning(errorMessage, offset, typeNode, context);
reportOnJsonNode(errorMessage, offset, typeNode, context);
}

if ('blocks' in node && node.blocks) {
Expand All @@ -110,7 +110,7 @@ export const ValidBlockTarget: LiquidCheckDefinition = {
const typeNode = nodeAtPath(ast, path)! as LiteralNode;
const exists = await validateBlockFileExistence(node.type, context);
if (!exists) {
reportWarning(
reportOnJsonNode(
`Theme block 'blocks/${node.type}.liquid' does not exist.`,
offset,
typeNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
import { nodeAtPath } from '../../json';
import { getSchema } from '../../to-schema';
import { isBlock, isSection } from '../../to-schema';
import { getBlocks, reportWarning } from './valid-block-utils';
import { getBlocks } from './valid-block-utils';
import { reportOnJsonNode } from '../../utils';

type BlockNodeWithPath = {
node: Section.Block | Preset.Block;
Expand Down Expand Up @@ -55,7 +56,7 @@ export const ValidLocalBlocks: LiquidCheckDefinition = {
if (staticBlockLocations.length > 0 && localBlockLocations.length > 0) {
staticBlockLocations.forEach((blockWithPath: BlockNodeWithPath) => {
const astNode = nodeAtPath(ast, blockWithPath.path)! as LiteralNode;
reportWarning(
reportOnJsonNode(
`Sections cannot use static theme blocks together with locally scoped blocks.`,
offset,
astNode,
Expand All @@ -71,7 +72,7 @@ export const ValidLocalBlocks: LiquidCheckDefinition = {
) {
localBlockLocations.forEach((blockWithPath: BlockNodeWithPath) => {
const astNode = nodeAtPath(ast, blockWithPath.path)! as LiteralNode;
reportWarning(
reportOnJsonNode(
'Sections cannot use theme blocks together with locally scoped blocks.',
offset,
astNode,
Expand All @@ -85,7 +86,7 @@ export const ValidLocalBlocks: LiquidCheckDefinition = {
if (localBlockLocations.length > 0) {
localBlockLocations.forEach((blockWithPath: BlockNodeWithPath) => {
const astNode = nodeAtPath(ast, blockWithPath.path)! as LiteralNode;
reportWarning(
reportOnJsonNode(
'Local scoped blocks are not supported in theme blocks.',
offset,
astNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,3 @@ export function getBlocks(validSchema: ThemeBlock.Schema | Section.Schema): {
hasRootLevelThemeBlocks: themeBlockLocations.some((block) => block.path[0] === 'blocks'),
};
}

export function reportWarning(
message: string,
offset: number,
astNode: LiteralNode,
context: Context<SourceCodeType.LiquidHtml>,
) {
context.report({
message,
startIndex: offset + getLocStart(astNode),
endIndex: offset + getLocEnd(astNode),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../../types';
import { nodeAtPath } from '../../json';
import { getSchema, isSectionSchema } from '../../to-schema';
import { BlockNodeWithPath, getBlocks, reportWarning } from '../../utils';
import { BlockNodeWithPath, getBlocks, reportOnJsonNode } from '../../utils';

export const ValidSettingsKey: LiquidCheckDefinition = {
meta: {
Expand Down Expand Up @@ -123,7 +123,7 @@ function validateSettingsKey(
? `Setting '${setting.key.value}' does not exist in 'blocks/${blockNode.type}.liquid'.`
: `Setting '${setting.key.value}' does not exist in schema.`;

reportWarning(errorMessage, offset, setting.key, context);
reportOnJsonNode(errorMessage, offset, setting.key, context);
}
}
}
Loading
Loading