noUndeclaredClasses (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.5.0 - Diagnostic Category:
lint/nursery/noUndeclaredClasses - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUndeclaredClasses": "error" } } }}Description
Section titled “Description”Reports CSS class names in JSX className or class attributes that are not defined
in any imported CSS file.
When a JSX file imports CSS files, every class name used in className= or class=
attributes is checked against the available class definitions. Classes that are not
defined are reported.
This rule checks string literals, variable references (resolved through the semantic
model), call expressions like clsx(...) / classnames(...), object expression keys,
and array expressions. Dynamic class names that cannot be statically resolved are
silently skipped.
In Astro files, class:list={...} directives and class={...} attribute expressions
are also checked. CSS files imported in the frontmatter (import "./styles.css") are
included in the class resolution.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”import "./styles.css";export default () => <div className="missing" />;import "./styles.css";export default () => <div className="header" />;Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.