stylelint-prettier
raw JSON →Runs Prettier as a Stylelint rule and reports formatting differences as individual Stylelint issues. Version 5.0.3 is current, requiring Node >=18.12.0, Prettier >=3.0.0, and Stylelint >=16.0.0. It integrates Prettier's opinionated formatting directly into the Stylelint linting workflow, allowing developers to catch formatting inconsistencies as lint errors during development or in CI. Unlike standalone Prettier checks, this plugin formats the output as Stylelint violations with precise line/column positions. It is maintained by the Prettier organization and follows the same release cadence as its peer dependencies. Key differentiator: it eliminates the need for separate Prettier CI checks and provides uniform reporting with other Stylelint rules.
Common errors
error Error: Cannot find module 'prettier' ↓
error Configuration for rule "prettier/prettier" is invalid: Value false should be an object or boolean. ↓
error Unknown rule: prettier/prettier ↓
error Parsing errors in your CSS file / unexpected token ↓
Warnings
deprecated stylelint-config-prettier is no longer needed for Stylelint v15+ because stylistic rules are deprecated and removed in v16. ↓
breaking Version 5.0.0 dropped support for Stylelint <16 and Prettier <3. Existing configs may break after upgrade. ↓
gotcha Passing options via Stylelint rule overrides .prettierrc for Prettier <1.7.0 but merges for newer versions. ↓
gotcha The rule name is 'prettier/prettier', not 'stylelint-prettier/prettier'. ↓
deprecated Stylelint v15 deprecated all stylistic rules that conflict with Prettier. The plugin may still work but expects those rules to be disabled. ↓
Install
npm install stylelint-prettier yarn add stylelint-prettier pnpm add stylelint-prettier Imports
- stylelint-prettier wrong
const sp = require('stylelint-prettier') (not a Node module to require at runtime)correctimport 'stylelint-prettier' (in plugins array) or use extends: ['stylelint-prettier/recommended'] - prettier/prettier wrong
{"rules": {"prettier/prettier": "error"}} (Stylelint uses true/false or severity options, not ESLint-style)correct"plugin": ["stylelint-prettier"] and "rules": { "prettier/prettier": true } - stylelint-config-prettier wrong
Extending stylelint-config-prettier without also adding stylelint-prettier (conflicts won't be overridden)correctnpm install stylelint-config-prettier --save-dev; extends: [..., 'stylelint-config-prettier']
Quickstart
// .stylelintrc
{
"extends": ["stylelint-prettier/recommended"],
"rules": {
"prettier/prettier": [true, {
"singleQuote": true,
"tabWidth": 2
}]
}
}