Course contentsShow
← Web Development
Lesson 1444 of 2,98226. Code Quality ToolsFree lesson

CSS Preprocessor Support

Configuring Stylelint for Sass, SCSS, or Less with custom syntax parsers and plugins.

CSS Preprocessor Support

You'll learn how to configure Stylelint to work with Sass, SCSS, or Less files using custom syntax parsers and plugins.

Why Preprocessors Need Special Configuration

Out of the box, Stylelint expects standard CSS syntax. But preprocessors like Sass, SCSS, and Less introduce features like variables ($primary-color), nesting, mixins, and functions that aren't valid in plain CSS. Think of it like teaching your spell-checker a new dialect—you need to install a "dictionary" that understands the new grammar.

Adding Preprocessor Support

For SCSS/Sass, install the PostCSS syntax parser:

npm install --save-dev postcss-scss

Then update your .stylelintrc.json:

{
  "extends": "stylelint-config-standard",
  "customSyntax": "postcss-scss"
}

For Less, use:

npm install --save-dev postcss-less
{
  "customSyntax": "postcss-less"
}

Preprocessor-Specific Rules

You can also install plugins that add rules tailored to preprocessor features:

npm install --save-dev stylelint-scss
{
  "plugins": ["stylelint-scss"],
  "rules": {
    "scss/at-rule-no-unknown": true,
    "scss/dollar-variable-pattern": "^[a-z][a-zA-Z0-9]+$"
  }
}

This example enforces camelCase naming for Sass variables and validates Sass-specific at-rules like @include and @mixin.

Per-File Overrides

If your project mixes CSS and SCSS, use overrides:

{
  "extends": "stylelint-config-standard",
  "overrides": [
    {
      "files": ["**/*.scss"],
      "customSyntax": "postcss-scss"
    }
  ]
}

Key Takeaway: Stylelint requires custom syntax parsers (postcss-scss, postcss-less) to understand preprocessor syntax, and preprocessor-specific plugins enable linting of language-specific features like variables and mixins.