noUnusedClasses (CSS)
Language CSS
Summary
Section titled “Summary”- Rule available since:
v2.5.0 - Diagnostic Category:
lint/nursery/noUnusedClasses - 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": { "noUnusedClasses": "error" } } }}Description
Section titled “Description”Reports CSS class selectors that are never referenced in any JSX or HTML file.
This rule checks all CSS class selectors (.foo) in a CSS file and verifies
that each class name is referenced somewhere in a class= or className=
attribute in an HTML or JSX file that imports (directly or transitively) the
CSS file.
Classes inside :global(.foo) are excluded from this check, as they are
intended to be used by external consumers without explicit imports.
SCSS limitations
Section titled “SCSS limitations”This rule does not evaluate SCSS. Interpolated class names are ignored, and @extend
references are not treated as class references. Statically named classes inside mixin bodies
are checked as authored even when the mixin is not included.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”.unused { color: red; } /* Class "unused" is never referenced */.used { color: blue; }import "./styles.css";export default () => <div className="used" />;.button { color: blue; }.container { padding: 1rem; }import "./styles.css";export default () => ( <div className="container"> <button className="button">Click</button> </div>);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.