prettier-stylelint
raw JSON →prettier-stylelint (v0.4.2) is a tool that formats CSS/SCSS/Less files by first running Prettier and then stylelint --fix, using a generated Prettier config derived from your stylelint config. It aims to produce formatted code that also passes stylelint rules, eliminating the need for manual alignment. The package includes a stylelint config that disables conflicting rules. It should be considered experimental and unmaintained; the last release was in 2018. Key differentiators from alternatives like stylelint-prettier or Prettier's own stylelint plugin: it generates Prettier config from stylelint rules, whereas modern approaches typically use stylelint-config-prettier or run Prettier before stylelint. The project has not seen updates for 6+ years, and the API example shows a mistake (using prettier-eslint instead of prettier-stylelint). Not recommended for new projects.
Common errors
error TypeError: format is not a function ↓
const format = require('prettier-stylelint'); error Cannot find module 'prettier-stylelint/config' ↓
./node_modules/prettier-stylelint/config.js or the correct path relative to your config. error prettier-stylelint: error: unknown option `--stdin' ↓
echo 'css' | prettier-stylelint Warnings
gotcha The API example in the README imports 'prettier-eslint' instead of 'prettier-stylelint', which is incorrect and will cause a runtime error. ↓
breaking Package is EOL: no updates since 2018, repository archived, and the generating Prettier config from stylelint rules approach is superseded by modern solutions. ↓
deprecated The package relies on deprecated Prettier API v1.x; may not work with Prettier v2+ or stylelint v14+. ↓
gotcha CLI uses default glob `**/*.{css,scss,less,sss}` but may omit common files like .styl or .sass if not included. ↓
Install
npm install prettier-stylelint yarn add prettier-stylelint pnpm add prettier-stylelint Imports
- default wrong
import format from 'prettier-stylelint'correctconst format = require('prettier-stylelint') - format wrong
const { format } = require('prettier-stylelint')correctconst format = require('prettier-stylelint') - config wrong
import 'prettier-stylelint/config'correctrequire('prettier-stylelint/config')
Quickstart
// Install: npm install prettier-stylelint --save-dev
// In your stylelint config (.stylelintrc or package.json)
{
"extends": [
"./node_modules/prettier-stylelint/config.js"
],
"rules": {
"indentation": 4,
"string-quotes": "single"
}
}
// Then run CLI:
// npx prettier-stylelint --write "src/**/*.css"
// Or use the API:
const format = require('prettier-stylelint');
const sourceCode = 'a[id="foo"] { content: "x"; }';
const options = {
text: sourceCode
};
const formatted = format(options);
console.log(formatted);
// Output:
// a[id='foo'] {
// content: 'x';
// }