Solution:
In order to allow single-line blocks in VSCode using Prettier - Code formatter extension, please take the following steps:
- Enable stylelint integration by adding this in the VSCode Settings (JSON):
"prettier.stylelintIntegration": true - Install stylelint and stylelint-prettier npm modules in your project directory.
npm install stylelint stylelint-prettier --save-dev - Add a .stylelintrc.json file at the root of your project directory with the following code:
{
"plugins": ["stylelint-prettier"],
"rules": {
"block-closing-brace-newline-after": "always-multi-line",
"block-closing-brace-empty-line-before": "never",
"block-closing-brace-space-before": "always",
"block-opening-brace-space-after": "always",
"block-opening-brace-space-before": "always",
"block-closing-brace-newline-before": "always-multi-line",
"block-opening-brace-newline-after": "always-multi-line",
"indentation": 4
}
}
You can add/customize more stylelint rules, see the entire list of rules here.
Took me a while to understand how to configure these options, if you're starting out with stylelint, I highly recommend you read its guidelines first.
Answer from Arslan Akram on Stack Overflow
» npm install stylelint-config-prettier-scss
» npm install prettier-plugin-css-order
Videos
Solution:
In order to allow single-line blocks in VSCode using Prettier - Code formatter extension, please take the following steps:
- Enable stylelint integration by adding this in the VSCode Settings (JSON):
"prettier.stylelintIntegration": true - Install stylelint and stylelint-prettier npm modules in your project directory.
npm install stylelint stylelint-prettier --save-dev - Add a .stylelintrc.json file at the root of your project directory with the following code:
{
"plugins": ["stylelint-prettier"],
"rules": {
"block-closing-brace-newline-after": "always-multi-line",
"block-closing-brace-empty-line-before": "never",
"block-closing-brace-space-before": "always",
"block-opening-brace-space-after": "always",
"block-opening-brace-space-before": "always",
"block-closing-brace-newline-before": "always-multi-line",
"block-opening-brace-newline-after": "always-multi-line",
"indentation": 4
}
}
You can add/customize more stylelint rules, see the entire list of rules here.
Took me a while to understand how to configure these options, if you're starting out with stylelint, I highly recommend you read its guidelines first.
I haven't known that vscode have that feature. One simple solution probably by specifying prettier-ignore?
/* prettier-ignore */
.some-class { background: #f00; }
Reference:
- https://prettier.io/docs/en/ignore.html#css
» npm install @fredluetkemeier/prettier-plugin-css-order
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!