prettier-stylelint-formatter
raw JSON → 0.5.1-beta.2 verified Sat Apr 25 auth: no javascript
A tool that formats CSS/SCSS/Less style files by running Prettier then stylelint --fix in sequence. It auto-generates a Prettier config from a stylelint config and disables conflicting rules. Stable version 0.5.1-beta.2 is a pre-release fork of prettier-stylelint by hugomrdias. It provides both a CLI and API, supports glob patterns, stdin, and respects .gitignore/.prettierignore. Compared to alternatives like prettier-eslint, this package focuses on style files (CSS, SCSS, Less, SSS) and integrates with stylelint.
Common errors
error Cannot find module 'prettier-stylelint-formatter' ↓
cause Package is not installed or not in node_modules.
fix
Run
npm install prettier-stylelint-formatter --save-dev or yarn add prettier-stylelint-formatter -D. error TypeError: format is not a function ↓
cause Using ES import syntax on a CommonJS module with a default export that is the function.
fix
Use require:
const format = require('prettier-stylelint-formatter'). error SyntaxError: Unexpected token '?' ↓
cause The package may use optional chaining not supported in older Node.js versions.
fix
Upgrade Node.js to >=14.0.0 or use a transpiler.
Warnings
breaking Version 0.5.1-beta.2 is a beta release; API and CLI may have breaking changes before stable release. ↓
fix Pin to a specific version or wait for stable release.
deprecated The package is a fork of the deprecated prettier-stylelint; the original is no longer maintained. ↓
fix Consider using stylelint-prettier or prettier-stylelint-recommended instead.
gotcha The CLI --write flag overwrites files in place; it is recommended to commit changes before running. ↓
fix Always run `git commit` before using --write, or use --stdin with output redirection.
gotcha The config merge logic may not respect all stylelint config structures (e.g., plugins, processors). ↓
fix Manually validate the merged config by running stylelint separately.
Install
npm install prettier-stylelint-formatter yarn add prettier-stylelint-formatter pnpm add prettier-stylelint-formatter Imports
- format wrong
import format from 'prettier-stylelint-formatter'correctconst format = require('prettier-stylelint-formatter') - PrettierStylelintFormatter (default import type)
import prettierStylelint from 'prettier-stylelint-formatter' - CLI usage wrong
prettier-stylelint --fixcorrectnpx prettier-stylelint --write "**/*.css"
Quickstart
// Install: npm install prettier-stylelint-formatter --save-dev
// API example
const format = require('prettier-stylelint-formatter');
const sourceCode = 'a[id="foo"] { content: "x"; }';
const options = {
text: sourceCode,
// Optional: specify a stylelint config file path
// config: '/path/to/.stylelintrc'
};
const formatted = format(options);
console.log(formatted);
// Output: a[id='foo'] {
// content: 'x';
// }
// CLI: npx prettier-stylelint --write "src/**/*.css"