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:
npx @soleil-se/stylelint-config@latest --setup
To install @soleil-se/stylelint-config
and stylelint
manually follow the steps below.
- Install
Install
@soleil-se/stylelint-config
andstylelint
.Terminal window npm i @soleil-se/stylelint-config stylelint --save-dev - Set project to ESM
Set the project so it resolves Node dependencies as ES modules.
{"name": "My project","private": true,"license": "UNLICENSED","type": "module",...} - 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"
inpackage.json
) the file extension should be.mjs
. - Reload Visual Studio Code
The editor needs to be reloaded for changes to take effect.
Migration
To migrate automatically run the following command:
npx @soleil-se/stylelint-config --setup
To migrate manually follow steps below.
- 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 ofstylelint
and@soleil-se/stylelint-config
.Terminal window npm remove stylelint @soleil-se/stylelint-config - 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 - Set project to ESM
Set the project so it resolves Node dependencies as ES modules.
{"name": "My project","private": true,"license": "UNLICENSED","type": "module",...} - 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"
inpackage.json
) the file extension should be.mjs
. - 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:
"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.
Less
To support an old legacy project still using Less install postcss-less
npm install postcss-less --save-dev
Then add the following to 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.
{ "scripts": { "stylelint": "npx stylelint ./path/to/css/**/*.css --allow-empty-input", "stylelint-fix": "npx stylelint ./path/to/css/**/*.css --fix --allow-empty-input" }}