Sass
sass/no-extend-class
Extend only placeholder selectors (%name), or use a mixin; @extend of a real class copies selectors everywhere it appears.
minorstaticfe-sass
Why
@extend .btn adds the extending selector to every rule in the compiled CSS that mentions .btn, including nested, modified and third-party ones. The output grows in unexpected places, the order of rules changes which style wins, and extending across @media is an error. Renaming or restyling .btn then changes unrelated components.
Fix
Put the shared declarations in a placeholder (%button-base) and extend that, or write a mixin (@include button-base) when the relationship is only "these look alike". In a component framework, reuse the component instead of the selector.
Examples
// bad
.save-button { @extend .btn; }
// good
%button-base { padding: 0.5rem 1rem; border-radius: 0.25rem; }
.btn, .save-button { @extend %button-base; }Sources
Facts
- Id
sass/no-extend-class- Severity
- minor
- Check
- static checked in the source by
audit - Applies to
scssvuesvelteastro- Only in projects with
sass- Taught by the skill
fe-sassSass (SCSS)- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain sass/no-extend-class