Draft
Conversation
bf4018b to
c4d206f
Compare
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>
c4d206f to
70d6111
Compare
aswamy
commented
Apr 10, 2026
| "vscode-uri": "^3.0.7" | ||
| }, | ||
| "devDependencies": { | ||
| "@shopify/theme-check-node": "^3.24.0" |
Contributor
Author
There was a problem hiding this comment.
I had to move it to a dev-dependency so we can let theme-check-node be dependent on the theme-graph.
Why? Because CLI needs the theme-graph to be able to run the theme-check to detect cross-file CSS usage.
| fs: NodeFileSystem, | ||
| getSectionSchema: getSectionSchemaFn as any, | ||
| getBlockSchema: getBlockSchemaFn as any, | ||
| getWebComponentDefinitionReference: () => undefined, |
Contributor
Author
There was a problem hiding this comment.
I don't want to recreate the whole graph because we don't need it for this theme-check, but might silently error out if we add a theme-check that needs this in the future 🤔
(but then again, we would silently fail if getReferences or getDependencies wasn't defined either so maybe not a HUGE deal 🤷)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new theme check
ValidScopedCSSClassthat warns when a CSS class used in an HTMLclassattribute may be defined outside the scope of the current file.This helps theme developers catch cases where a CSS class is used in a file but is only defined in a stylesheet tag that isn't accessible from that file's scope — indicating a potential dependency issue or misplaced style.
What is considered "in scope"
A CSS class is considered in scope for a file if it is defined in any of the following:
{% stylesheet %}tag — the file's own stylesheet{% stylesheet %}tags — any file that directly renders this file (via{% render %},{% section %}, etc.), traversed upward through the full ancestor chain. Onlydirecttype references count (notindirectorpreset){% render %}, including that snippet's own snippet descendants (recursive).cssfiles in the theme'sassets/directory are globally in scopeWhat is NOT reported
{{ variable }}) in class attributes are skipped since they can't be statically analyzedChanges
New files
packages/theme-check-common/src/checks/valid-scoped-css-class/— check implementation + tests (27 test cases)packages/theme-check-common/src/utils/styles.ts— CSS class extraction utilities (postcss-based parsing, asset/liquid file scanning) + tests (25 test cases)packages/theme-check-common/src/utils/traversal.ts— graph traversal utilities (ancestor BFS, snippet descendant BFS) + tests (15 test cases)Infrastructure changes
packages/theme-check-common/src/types.ts— addedgetDependenciestoDependenciesinterface (mirrors existinggetReferences)packages/theme-language-server-common/src/diagnostics/runChecks.ts— wiredgetDependenciestoThemeGraphManagerpackages/theme-check-node/src/index.ts— buildsThemeGraphin CLI mode and providesgetReferences/getDependenciesto checkspackages/theme-graph/package.json— moved@shopify/theme-check-nodefromdependenciestodevDependencies(only used in test helpers, eliminates circular dep)Performance
WeakMaponfsinstance +Mapon URI) so expensive operations run once per check run, not once per fileTest plan
yarn vitest run packages/theme-check-common/— all 923 tests passyarn vitest run packages/theme-check-node/— all 77 tests passyarn tsc --noEmitintheme-check-common,theme-check-node,theme-language-server-common— all compile cleannode packages/theme-check-node/dist/cli.js <theme-path>produces correct warnings🤖 Generated with Claude Code