Sass

sass/no-extend-class

Extend only placeholder selectors (%name), or use a mixin; @extend of a real class copies selectors everywhere it appears.

drobnastatycznefe-sass

Dlaczego

@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.

Poprawka

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.

Przykłady

// bad
.save-button { @extend .btn; }
// good
%button-base { padding: 0.5rem 1rem; border-radius: 0.25rem; }
.btn, .save-button { @extend %button-base; }

Źródła

Fakty

Identyfikator
sass/no-extend-class
Waga
drobna
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
scss vue svelte astro
Tylko w projektach z
sass
Uczy jej skill
fe-sass Sass (SCSS)
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain sass/no-extend-class