Skip to content

Commit

Permalink
Fixed MissingSchema theme check
Browse files Browse the repository at this point in the history
  • Loading branch information
AribaRajput committed Jan 9, 2025
1 parent ca3a3f0 commit cc4bdb7
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 312 deletions.
5 changes: 0 additions & 5 deletions .changeset/chilled-bugs-juggle.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/hot-vans-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme-check-common': minor
---

This update ensures that the AppBlockMissingSchema 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.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { describe, expect, it } from 'vitest';
import { runLiquidCheck } from '../../test';
import { MissingSchema } from './index';
import { Config } from '../../types';
import { AppBlockMissingSchema } from './index';

describe('MissingSchema', () => {
it('should report an error when schema tag is missing on a theme app extension', async () => {
describe('AppBlockMissingSchema', () => {
it('should report an error when schema tag is missing on a theme app extension (blocks only)', async () => {
const sourceCode = `
<footer class="footer">
{% for block in section.blocks %}
Expand All @@ -23,8 +22,10 @@ describe('MissingSchema', () => {
</footer>
`;

const offenses = await runLiquidCheck(MissingSchema, sourceCode);
let offenses = await runLiquidCheck(AppBlockMissingSchema, sourceCode, 'blocks/footer.liquid');
expect(offenses).to.have.lengthOf(1);
offenses = await runLiquidCheck(AppBlockMissingSchema, 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 () => {
Expand Down Expand Up @@ -81,7 +82,11 @@ describe('MissingSchema', () => {
}
{% endschema %}`;

const offenses = await runLiquidCheck(MissingSchema, sourceCode);
const offenses = await runLiquidCheck(
AppBlockMissingSchema,
sourceCode,
'blocks/footer.liquid',
);
expect(offenses).to.have.lengthOf(0);
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ConfigTarget, LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';

export const MissingSchema: LiquidCheckDefinition = {
export const AppBlockMissingSchema: LiquidCheckDefinition = {
meta: {
code: 'MissingSchema',
name: 'Missing schema definitions in theme app extensions should be avoided',
code: 'AppBlockMissingSchema',
name: 'Missing schema definitions in app blocks (specific to theme app extensions) should be avoided',
docs: {
description: 'Report missing schema definitions in theme app extensions',
description: 'Report missing schema definitions in theme app extensions app blocks',
recommended: true,
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/missing-schema',
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/app-block-missing-schema',
},
severity: Severity.ERROR,
type: SourceCodeType.LiquidHtml,
Expand All @@ -17,6 +17,15 @@ export const MissingSchema: LiquidCheckDefinition = {

create(context) {
let foundSchema = false;
const relativePath = context.toRelativePath(context.file.uri);

/**
* Theme app extension blocks are the only types of files that can have a
* schema defined in them.
*/
if (!relativePath.startsWith('blocks/')) {
return {};
}

return {
async LiquidRawTag(node) {
Expand Down
6 changes: 2 additions & 4 deletions packages/theme-check-common/src/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ import { ValidSchema } from './valid-schema';
import { ValidSchemaName } from './valid-schema-name';
import { ValidStaticBlockType } from './valid-static-block-type';
import { VariableName } from './variable-name';
import { MissingSchema } from './missing-schema';
import { ValidBlockPresetSettings } from './valid-block-preset-settings';
import { AppBlockMissingSchema } from './app-block-missing-schema';

export const allChecks: (LiquidCheckDefinition | JSONCheckDefinition)[] = [
AppBlockValidTags,
Expand All @@ -71,7 +70,7 @@ export const allChecks: (LiquidCheckDefinition | JSONCheckDefinition)[] = [
MatchingTranslations,
MissingAsset,
MissingTemplate,
MissingSchema,
AppBlockMissingSchema,
PaginationSize,
ParserBlockingScript,
SchemaPresetsBlockOrder,
Expand All @@ -93,7 +92,6 @@ export const allChecks: (LiquidCheckDefinition | JSONCheckDefinition)[] = [
ValidStaticBlockType,
VariableName,
ValidSchemaName,
ValidBlockPresetSettings,
];

/**
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit cc4bdb7

Please sign in to comment.