Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/tidy-snakes-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme-check-node': patch
---

Fix cross-file LiquidDoc checks on Windows by normalising snippet paths before lookup.
46 changes: 43 additions & 3 deletions packages/theme-check-node/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { afterEach, assert, beforeEach, describe, expect, it } from 'vitest';
import { Config, SourceCodeType, getTheme, getThemeFilesPathPattern } from './index';
import { afterEach, assert, beforeEach, describe, expect, it, vi } from 'vitest';
import path from 'node:path';
import { Config, SourceCodeType, getTheme, getThemeFilesPathPattern, themeCheckRun } from './index';
import { Workspace, makeTempWorkspace } from './test/test-helpers';
import { pathToFileURL } from 'node:url';
import { fileURLToPath, pathToFileURL } from 'node:url';

describe('Unit: getTheme', () => {
let workspace: Workspace;
Expand Down Expand Up @@ -49,3 +50,42 @@ describe('Unit: getThemeFilesPathPattern', () => {
expect(normalizedGlob).to.equal(__dirname.replace(/\\/g, '/') + '/**/*.{liquid,json}');
});
});

describe('Integration: themeCheckRun', () => {
it('reports LiquidDoc errors across files when paths use Windows separators', async () => {
const workspace = await makeTempWorkspace({
locales: {
'en.default.json': '{}',
},
sections: {
'main.liquid': "{% render 'card' %}",
},
snippets: {
'card.liquid': `
{% doc %}
@param {string} title - The card title
{% enddoc %}
`,
},
});
const originalRelative = path.relative;

const relativeSpy = vi.spyOn(path, 'relative').mockImplementation((from, to) => {
const relative = originalRelative(from, to);
if (typeof from === 'string' && from.startsWith('file:')) {
return relative.replace(/\//g, '\\');
}
return relative;
});

try {
const { offenses } = await themeCheckRun(fileURLToPath(workspace.rootUri));
expect(
offenses.filter(({ check }) => check === 'MissingRenderSnippetArguments'),
).toHaveLength(1);
} finally {
relativeSpy.mockRestore();
await workspace.clean();
}
});
});
2 changes: 1 addition & 1 deletion packages/theme-check-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export async function themeCheckRun(
]));
const docDefinitions = new Map(
theme.map((file) => [
path.relative(URI.file(root).toString(), file.uri),
pathUtils.relative(file.uri, URI.file(root).toString()),
memo(async (): Promise<DocDefinition | undefined> => {
const ast = file.ast;
if (!isLiquidHtmlNode(ast)) {
Expand Down
Loading