You can check the answer to this problem on github, where I made a ticket some time ago:
https://github.com/prettier/prettier-vscode/issues/1051
I now have a better solution for using stylelint in VSCode:
I have a better option to use the stylelint, because the stylelint owner have created the official VSCode plugin!
https://marketplace.visualstudio.com/items?itemName=stylelint.vscode-stylelint
The plugin works almost out of the box. What you need to do is set up. You can use just settings.json in VSCode. Small example:
"stylelint.config": {
"rules": {
"at-rule-name-case": "lower",
"at-rule-name-space-after": "always-single-line",
"at-rule-semicolon-newline-after": "always",
}
}
Do you need a ready-to-use configuration?
No problem - you have to check this
- https://github.com/stylelint/stylelint-config-standard
- https://github.com/stylelint/stylelint-config-recommended
Do you need Formatting option (Shift + Alt + F)?
No problem. You can define keybinding for option Fix all auto-fixable problems. For example:
{
"key": "alt+shift+f",
"command": "stylelint.executeAutofix",
"when": "editorTextFocus && editorLangId == 'css'"
},
{
"key": "alt+shift+f",
"command": "stylelint.executeAutofix",
"when": "editorTextFocus && editorLangId == 'scss'"
},
{
"key": "alt+shift+f",
"command": "stylelint.executeAutofix",
"when": "editorTextFocus && editorLangId == 'less'"
}
Remember that not all stylelint options are available for autofixing (but most are)
Answer from kanlukasz on Stack Overflow
» npm install stylelint-config-prettier
» npm install prettier-stylelint
» npm install @stylelint/prettier-config
» npm install @lego/stylelint-config-prettier
You can integrate Prettier with stylelint by turning off the conflicting stylelint rules using the stylelint-config-prettier shared config.
For example:
// .stylelintrc
{
"extends": [
"stylelint-config-standard" // or whatever config you're using
"stylelint-config-prettier"
]
}
Prettier will then be responsible for the bulk of the formatting, and stylelint will be responsible for checking for possible errors and limiting languages features.
I am new to all of this, but might be able to help. I have been working on getting stylelint to autofix on save for just CSS. I have a .stylelintrc file in my project folder with all of my rules. The settings.json to stop Prettier from overriding:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[css]": {
"editor.defaultFormatter": null,
"editor.formatOnSave": false
},
"editor.formatOnSave": true,
"prettier.useTabs": true,
"prettier.proseWrap": "never",
"prettier.printWidth": 300,
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
}
}
Its working for me so far!