Sass
sass/no-import
Load Sass files with @use and @forward, not @import, which is deprecated and will be removed in Dart Sass 3.
moderatestaticfe-sass
Why
@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.
Fix
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.
Examples
// bad
@import 'tokens';
.card { padding: $space-4; }
// good
@use 'tokens';
.card { padding: tokens.$space-4; }Sources
Facts
- Id
sass/no-import- Severity
- moderate
- 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-import