Skip to content

Commit 7f6fdb4

Browse files
aswamyclaude
andcommitted
Add ValidScopedCSSClass theme check
Add a new theme check that warns when a CSS class used in an HTML class attribute may be defined outside the scope of the current file, helping catch misplaced styles and dependency issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d50ee14 commit 7f6fdb4

25 files changed

Lines changed: 1987 additions & 11 deletions

File tree

.changeset/rude-poems-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme-graph': patch
3+
---
4+
5+
[internal] Moving @shopify/theme-check-node to being a dev-dependency of the package

.changeset/small-items-marry.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@shopify/theme-language-server-common': minor
3+
'@shopify/theme-check-common': minor
4+
'@shopify/theme-check-node': minor
5+
---
6+
7+
Introduce new theme-check to detect invalid CSS class usage in HTML
8+
9+
`ValidScopedCSSClass` detects invalid CSS classes in HTML if it deems them being out of scope.
10+
A CSS class is in-scope if it matches any of the following:
11+
- The CSS class is declared in `assets/*.css` file
12+
- The CSS class is declared in the file's `stylesheet` tag
13+
- The CSS class is declared in a *direct* ancestor's `stylesheet` tag
14+
- The CSS class is declared in a snippet file's `stylesheet` tag that is rendered by this file or its direct ancestor (recursive)

packages/theme-check-common/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
"line-column": "^1.0.2",
3333
"lodash": "^4.17.23",
3434
"minimatch": "^10.2.1",
35+
"postcss": "^8.5.9",
36+
"postcss-safe-parser": "^7.0.1",
37+
"postcss-selector-parser": "^7.1.1",
3538
"vscode-json-languageservice": "^5.3.10",
3639
"vscode-uri": "^3.0.7"
3740
},
3841
"devDependencies": {
3942
"@types/line-column": "^1.0.0",
40-
"@types/lodash": "^4.17.20"
43+
"@types/lodash": "^4.17.20",
44+
"@types/postcss-safe-parser": "^5.0.4"
4145
}
4246
}

packages/theme-check-common/src/checks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { UnusedDocParam } from './unused-doc-param';
5252
import { ValidContentForArguments } from './valid-content-for-arguments';
5353
import { ValidContentForArgumentTypes } from './valid-content-for-argument-types';
5454
import { ValidBlockTarget } from './valid-block-target';
55+
import { ValidScopedCSSClass } from './valid-scoped-css-class';
5556
import { ValidHTMLTranslation } from './valid-html-translation';
5657
import { ValidJSON } from './valid-json';
5758
import { ValidDocParamTypes } from './valid-doc-param-types';
@@ -123,6 +124,7 @@ export const allChecks: (LiquidCheckDefinition | JSONCheckDefinition)[] = [
123124
ValidHTMLTranslation,
124125
ValidContentForArguments,
125126
ValidContentForArgumentTypes,
127+
ValidScopedCSSClass,
126128
ValidJSON,
127129
ValidDocParamTypes,
128130
ValidLocalBlocks,

0 commit comments

Comments
 (0)