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/fix-disable-doc-tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme-check-common': patch
---

Fix theme-check-disable-next-line not working for checks inside doc tags
38 changes: 38 additions & 0 deletions packages/theme-check-common/src/disabled-checks/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Offense } from '..';
import { describe, it, expect } from 'vitest';
import { LiquidFilter, RenderMarkup } from './test-checks';
import { UndefinedObject } from '../checks/undefined-object';
import { UniqueDocParamNames } from '../checks/unique-doc-param-names';

const commentTypes = [
(text: string) => `{% # ${text} %}`,
Expand Down Expand Up @@ -257,6 +258,43 @@ ${buildComment('theme-check-enable')}
}),
);
});

it('should disable checks inside doc tags when disable-next-line is placed before the doc tag', async () => {
const file = `{% # theme-check-disable-next-line UniqueDocParamNames %}
{% doc %}
@param foo - first param
@param foo - duplicate param
{% enddoc %}`;

const offenses = await check({ 'code.liquid': file }, [UniqueDocParamNames]);
expect(offenses).to.have.length(0);
});

it('should disable all checks inside doc tags when disable-next-line is used without specific check names', async () => {
const file = `{% # theme-check-disable-next-line %}
{% doc %}
@param bar - first param
@param bar - duplicate param
{% enddoc %}`;

const offenses = await check({ 'code.liquid': file }, [UniqueDocParamNames]);
expect(offenses).to.have.length(0);
});

it('should still report offenses in doc tags when disable-next-line is not present', async () => {
const file = `{% doc %}
@param baz - first param
@param baz - duplicate param
{% enddoc %}`;

const offenses = await check({ 'code.liquid': file }, [UniqueDocParamNames]);
expect(offenses).to.have.length(1);
expect(offenses).toContainEqual(
expect.objectContaining({
message: "The parameter 'baz' is defined more than once.",
}),
);
});
});
});
});
8 changes: 8 additions & 0 deletions packages/theme-check-common/src/disabled-checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ export function findNextLinePosition(
/*
* If the node contains children nodes, we don't want to disable checks for them.
* We want to keep it exclusively to the tag itself.
*
* Exception: For `{% doc %}` tags, the checks we care about (ValidDocParamTypes,
* UniqueDocParamNames, ReservedDocParamNames, etc.) report offenses at positions
* inside the doc body. Using only `blockStartPosition` would miss those offenses,
* so we use the full `position` span to cover the entire tag including its body.
*/
if ('blockStartPosition' in nextNode) {
if (nextNode.type === LiquidHtmlNodeTypes.LiquidRawTag && nextNode.name === 'doc') {
return nextNode.position;
}
return nextNode.blockStartPosition;
}

Expand Down
Loading