ValidScopedCSSClass
Warns when a CSS class used in an HTML class attribute is defined in the theme, but isn't reachable from the current file's scope.
A CSS class is in scope for a file when it's defined in any of the following:
- The file's own
{% stylesheet %}tag. - The
{% stylesheet %}tag of any ancestor file that directly renders this file (through{% render %},{% section %}, and so on). The full ancestor chain is traversed, but onlydirectreferences count—indirectandpresetreferences don't. - The
{% stylesheet %}tag of any snippet that this file (or any of its ancestors) renders through{% render %}, including nested snippet descendants. - Any
.cssfile in the theme'sassets/directory. These are always in scope.
The check doesn't report classes that aren't defined anywhere in the theme, because those might come from external sources, such as CDNs or utility frameworks. It also doesn't report dynamic class attributes that contain Liquid output tags (for example, class="{{ some_class }}"), because they can't be analyzed statically.
Anchor to ExamplesExamples
The following examples contain code snippets that either fail or pass this check.
Anchor to ✗ Fail✗ Fail
In the following example, other-class is defined in snippets/other.liquid, but that snippet isn't rendered from sections/section.liquid, so the class is out of scope:
sections/section.liquid
snippets/other.liquid
Anchor to ✓ Pass✓ Pass
In the following example, my-class is defined in the same file's {% stylesheet %} tag:
sections/section.liquid
Anchor to ✓ Pass✓ Pass
In the following example, parent-class is defined in an ancestor file that directly renders the block, so it's in scope for the block:
sections/section.liquid
blocks/child.liquid
Anchor to ✓ Pass✓ Pass
In the following example, asset-class is defined in a CSS asset file, and in a section file. No warning is displayed in sections/section1.liquid because asset-class is assumed globally in scope by being defined in the assets folder:
assets/theme.css
sections/section1.liquid
sections/section2.liquid
Anchor to ✓ Pass✓ Pass
In the following example, shared-style is defined in a snippet being imported by a parent file, but used the child file blocks/child.liquid:
sections/section.liquid
blocks/child.liquid
snippets/shared-styles.liquid
Anchor to OptionsOptions
The following example contains the default configuration for this check:
| Parameter | Description |
|---|---|
enabled | Whether this check is enabled. |
severity | The severity of the check. |
Anchor to Disabling this checkDisabling this check
You can disable this check if your theme relies heavily on class names that are defined in external stylesheets, inline scripts, or build-time CSS pipelines that the check can't analyze.