Hoppa till innehåll
This package has changed name, was previously @soleil/stylelint-config.
More information

@soleil-se/stylelint-config

Stylelint config based on stylelint-config-standard-scss, stylelint-config-recess-order and @stylistic/stylelint-plugin.

Prerequisites

A project using SCSS or CSS as styling language.

Installation

To install dependencies and setup configuration files for @soleil-se/stylelint-config run the following command:

Terminal window
npx @soleil-se/stylelint-config@latest --setup

To install @soleil-se/stylelint-config and stylelint manually follow the steps below.

  1. Install

    Install @soleil-se/stylelint-config and stylelint.

    Terminal window
    npm i @soleil-se/stylelint-config stylelint --save-dev
  2. Set project to ESM

    Set the project so it resolves Node dependencies as ES modules.

    {
    "name": "My project",
    "private": true,
    "license": "UNLICENSED",
    "type": "module",
    ...
    }
  3. Create config files

    Create .stylelintrc.js in the root of the project or app containing:

    .stylelintrc.js
    export default {
    extends: '@soleil-se/stylelint-config',
    }

    If the project is NOT using ESM as instructed in step 2 ("type": "module" in package.json) the file extension should be .mjs.

  4. Reload Visual Studio Code

    The editor needs to be reloaded for changes to take effect.

Migration

To migrate automatically run the following command:

Terminal window
npx @soleil-se/stylelint-config --setup

To migrate manually follow steps below.

  1. Uninstall old versions

    To manage npm peer dependency resolution it’s easiest to unistall and reinstall stylelint and @soleil-se/stylelint-config. Uninstall the old versions of stylelint and @soleil-se/stylelint-config.

    Terminal window
    npm remove stylelint @soleil-se/stylelint-config
  2. Install new versions

    Install version 16 of stylelint and version 4 of @soleil-se/stylelint-config.

    Terminal window
    npm i stylelint@16 @soleil-se/stylelint-config@4 --save-dev
  3. Set project to ESM

    Set the project so it resolves Node dependencies as ES modules.

    {
    "name": "My project",
    "private": true,
    "license": "UNLICENSED",
    "type": "module",
    ...
    }
  4. Change config to ESM

    Update the content of stylelintrc.js its content:

    .stylelintrc.js
    module.exports = {
    export default {
    extends: '@soleil-se/stylelint-config'
    }

    If the project is NOT using ESM as instructed in step 3 ("type": "module" in package.json) the file extension should be .mjs.

  5. Reload Visual Studio Code

    The editor needs to be reloaded for changes to take effect.

VS Code

Install stylelint for VS Code.

Settings

Open settings.json and add the following settings:

settings.json
"css.validate": false,
"less.validate": false,
"scss.validate": false,
"stylelint.validate": [
"css",
"less",
"postcss",
"scss",
"svelte",
"vue"
],
"[scss]": {
"editor.defaultFormatter": "stylelint.vscode-stylelint"
},
// If you want autofix enabled
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": "explicit"
}

Other syntaxes

If other syntaxes than CSS or SCSS needs to be supported you need to setup a custom config with the settings needed.

Read more about syntax.

Less

To support an old legacy project still using Less install postcss-less

Terminal window
npm install postcss-less --save-dev

Then add the following to stylelintrc.js

stylelintrc.js
export default {
extends: '@soleil-se/stylelint-config',
overrides: [{
files: '**/*.less',
customSyntax: 'postcss-less',
}],
};

CLI

Add the following to package.json and then adjust paths and file extensions.

package.json
{
"scripts": {
"stylelint": "npx stylelint ./path/to/css/**/*.css --allow-empty-input",
"stylelint-fix": "npx stylelint ./path/to/css/**/*.css --fix --allow-empty-input"
}
}

https://stylelint.io/user-guide/usage/cli