From e0a0934de17327a38b03d8faee248bb0c1b3f35c Mon Sep 17 00:00:00 2001 From: Ariba Rajput Date: Thu, 9 Jan 2025 13:44:26 -0500 Subject: [PATCH] Fixed MissingSchema theme check --- .changeset/hot-vans-fail.md | 5 +++++ .../src/checks/missing-schema/index.spec.ts | 9 +++++---- .../src/checks/missing-schema/index.ts | 9 +++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .changeset/hot-vans-fail.md diff --git a/.changeset/hot-vans-fail.md b/.changeset/hot-vans-fail.md new file mode 100644 index 000000000..7daaffc80 --- /dev/null +++ b/.changeset/hot-vans-fail.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme-check-common': minor +--- + +This update ensures that the MissingSchema theme check will only run on block files on theme app extensions, to avoid errors surfacing when the theme check is incorrectly run on snippets. diff --git a/packages/theme-check-common/src/checks/missing-schema/index.spec.ts b/packages/theme-check-common/src/checks/missing-schema/index.spec.ts index 15c14531d..137d37fa8 100644 --- a/packages/theme-check-common/src/checks/missing-schema/index.spec.ts +++ b/packages/theme-check-common/src/checks/missing-schema/index.spec.ts @@ -1,10 +1,9 @@ import { describe, expect, it } from 'vitest'; import { runLiquidCheck } from '../../test'; import { MissingSchema } from './index'; -import { Config } from '../../types'; describe('MissingSchema', () => { - it('should report an error when schema tag is missing on a theme app extension', async () => { + it('should report an error when schema tag is missing on a theme app extension (blocks only)', async () => { const sourceCode = ` `; - const offenses = await runLiquidCheck(MissingSchema, sourceCode); + let offenses = await runLiquidCheck(MissingSchema, sourceCode, 'blocks/footer.liquid'); expect(offenses).to.have.lengthOf(1); + offenses = await runLiquidCheck(MissingSchema, sourceCode, 'snippets/footer.liquid'); + expect(offenses).to.have.lengthOf(0); }); it('should not report when the schema is present on a theme app extension', async () => { @@ -81,7 +82,7 @@ describe('MissingSchema', () => { } {% endschema %}`; - const offenses = await runLiquidCheck(MissingSchema, sourceCode); + const offenses = await runLiquidCheck(MissingSchema, sourceCode, 'blocks/footer.liquid'); expect(offenses).to.have.lengthOf(0); }); }); diff --git a/packages/theme-check-common/src/checks/missing-schema/index.ts b/packages/theme-check-common/src/checks/missing-schema/index.ts index a31c0fb16..d1cad6e58 100644 --- a/packages/theme-check-common/src/checks/missing-schema/index.ts +++ b/packages/theme-check-common/src/checks/missing-schema/index.ts @@ -17,6 +17,15 @@ export const MissingSchema: LiquidCheckDefinition = { create(context) { let foundSchema = false; + const file = context.file; + const fileUri = file.uri; + const relativePath = context.toRelativePath(fileUri); + const isBlockFile = relativePath.startsWith('blocks/'); + + if (!isBlockFile) { + // Only lint block files as this check is invalid for snippets + return {}; + } return { async LiquidRawTag(node) {