Sass

sass/no-import

Load Sass files with @use and @forward, not @import, which is deprecated and will be removed in Dart Sass 3.

umiarkowanastatycznefe-sass

Dlaczego

@import puts every variable, mixin and function of every imported file into one global namespace, so names collide silently and nobody can tell where $primary comes from. A file imported twice is compiled twice. Dart Sass has deprecated it since 1.80.0 and prints a warning on every build; Dart Sass 3.0.0 removes it.

Poprawka

Use @use 'tokens'; and refer to members by namespace (tokens.$space-4, tokens.rem(24)); re-export a folder's partials from an index file with @forward. Configure a library with @use 'lib' with ($primary: #0a7) instead of setting variables before importing it. sass-migrator module --migrate-deps src/main.scss does most of the work. Plain CSS imports (url(...), a .css file, an http(s):// URL or one with a media query) are not affected.

Przykłady

// bad
@import 'tokens';
.card { padding: $space-4; }
// good
@use 'tokens';
.card { padding: tokens.$space-4; }

Źródła

Fakty

Identyfikator
sass/no-import
Waga
umiarkowana
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-import