Prevent `at-rule-no-unknown` from warning against Sass directives

See original GitHub issue

Describe the issue. Is it a bug or a feature request (new rule, new option, etc.)?

A feature request to not warn against Sass directives like @import, @function, and @if when using Sass or SCSS syntax.

Which rule, if any, is this issue related to?

at-rule-no-unknown

What CSS is needed to reproduce this issue?

e.g.

@function foo ($bar) {
  @if ($bar == 'a') {
    $baz: 'b';
  }
  @else if ($bar == 'b') {
    $baz: 'a';
  }
  @return $baz;
}

What stylelint configuration is needed to reproduce this issue?

e.g.

{
  "rules": {
    "at-rule-no-unknown": true,
  }
}

Which version of stylelint are you using?

6.9.0.

How are you running stylelint: CLI, PostCSS plugin, Node API?

CLI with stylelint foo.scss --config .stylelintrc --syntax scss.

Does your issue relate to non-standard syntax (e.g. SCSS, nesting, etc.)?

Yes, it’s related to SCSS directives.

What did you expect to happen?

No warnings to be flagged.

What actually happened (e.g. what warnings or errors you are getting)?

The following warnings were flagged:

foo.scss
1:1  ✖  Unexpected unknown at-rule "@function"   at-rule-no-unknown
2:3  ✖  Unexpected unknown at-rule "@if"         at-rule-no-unknown
5:3  ✖  Unexpected unknown at-rule "@else"       at-rule-no-unknown
8:3  ✖  Unexpected unknown at-rule "@return"     at-rule-no-unknown

Going over the Sass documentation results in the following list of keywords to additionally accept as known at-rules: @each, @else, @extend, @for, @function, @if, @include, @mixin, @return, @while.

The simplest solution would be to add these to the atRules set in src/reference/keywordSets.js, but that would incorrectly accept them in plain CSS. Creating a separate set for Sass directives will prevent that, but I can’t assess whether it’s easy to only consider that set in particular syntaxes.

It would be great if stylelint automatically applied this extra set when in Scss or Sass syntax.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:30
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

148reactions
datatypevoidcommented, May 20, 2018

@benbonnet

"rules": {
    . . .
    "at-rule-no-unknown": [true, {
      "ignoreAtRules": ["function", "if", "each", "include", "mixin"]
    }]
    . . .
  }

Reference

11reactions
alexander-akaitcommented, Jul 8, 2016

@VincentSmedinga stylelint rules not check non-standard syntax(not handling, not ignore and etc), use option ignoreAtRules: ['function', 'if'] for resolve this issue. We offically support only css syntax in rules. Maybe you are interested in stylelint-scss(some rules for only scss).

Read more comments on GitHub >

github_iconTop Results From Across the Web

At-Rules - Sass
@at-root puts styles within it at the root of the CSS document. @error causes compilation to fail with an error message. @warn prints...
Read more >
How do you get rid of these SASS linting errors when using ...
I'm using Tailwind in a Gatsby.js project. My environment is VSCode, using Prettier code formatter. How do I get rid of these linting...
Read more >
VS Code Errors and Warnings when using @tailwind directives
I have been using tailwindcss with laravel and laravel mix. I am having kind of weird issue because everything is working fine but...
Read more >
@tailwind unknown at rule | The AI Search Engine You Control
Unexpected unknown at-rule "@tailwind" scss/at-rule-no-unknown ... src/routes/about.svelte:47:5 Warn: Unknown at rule @apply (css) h1 { @apply text-red-500 ...
Read more >
Webpack missconfiguration when renaming .css to .scss - bud
When I change app.css and editor.css names to app.scss and ... "rules": { "at-rule-no-unknown": null, "scss/at-rule-no-unknown": true, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found