prettier-stylelint

raw JSON →
0.4.2 verified Sat Apr 25 auth: no javascript abandoned

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.

error TypeError: format is not a function
cause Importing package incorrectly (e.g., using named import or non-CJS).
fix
Use const format = require('prettier-stylelint');
error Cannot find module 'prettier-stylelint/config'
cause Relative path in stylelint extends is wrong or module not installed.
fix
Ensure package is installed and use ./node_modules/prettier-stylelint/config.js or the correct path relative to your config.
error prettier-stylelint: error: unknown option `--stdin'
cause Possibly using a very old version (pre-0.3) where --stdin was not supported.
fix
Update to 0.4.2 or use pipe: echo 'css' | prettier-stylelint
gotcha The API example in the README imports 'prettier-eslint' instead of 'prettier-stylelint', which is incorrect and will cause a runtime error.
fix Use require('prettier-stylelint') as shown in the quickstart.
breaking Package is EOL: no updates since 2018, repository archived, and the generating Prettier config from stylelint rules approach is superseded by modern solutions.
fix Migrate to stylelint-prettier or stylelint-config-prettier combined with Prettier directly.
deprecated The package relies on deprecated Prettier API v1.x; may not work with Prettier v2+ or stylelint v14+.
fix Do not use; consider alternatives.
gotcha CLI uses default glob `**/*.{css,scss,less,sss}` but may omit common files like .styl or .sass if not included.
fix Explicitly specify file patterns if needed.
npm install prettier-stylelint
yarn add prettier-stylelint
pnpm add prettier-stylelint

Demonstrates usage with stylelint config extension and the JavaScript API.

// 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';
// }