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 e0a0934
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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 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.
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';

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 = `
<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(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 () => {
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e0a0934

Please sign in to comment.