wp-prettier
raw JSON → 3.0.3 verified Sat Apr 25 auth: no javascript
A fork of Prettier (opinionated code formatter) maintained by Automattic. Adds a `--paren-spacing` command line option that inserts extra spaces inside parentheses, matching the formatting style used in projects like Calypso and Gutenberg. Current stable version is 3.0.3, based on Prettier 3.x. Released on demand when new Prettier versions are rebased; versioning uses alpha/beta suffixes (e.g., 2.0.5-beta-1). Supports JavaScript, TypeScript, CSS, HTML, JSON, Markdown, YAML, GraphQL, and more. Alternative to upstream Prettier for WordPress ecosystem projects.
Common errors
error Cannot find module 'prettier' ↓
cause Package installed as 'wp-prettier' but imported as 'prettier' without npm alias.
fix
Install with alias:
npm i --save-dev 'prettier@npm:wp-prettier@latest' and then import from 'prettier'. error Unknown option: --paren-spacing ↓
cause Using upstream Prettier instead of wp-prettier.
fix
Ensure you are using the wp-prettier fork: verify package.json has
"prettier": "npm:wp-prettier@^3.0.0". error Error: Configuration file does not support the 'parenSpacing' option ↓
cause Using a config file (e.g., .prettierrc) that includes `parenSpacing`, but the parser does not recognize it.
fix
Add
--paren-spacing flag or set parenSpacing: true in config; note that it only affects JavaScript/TypeScript/JSX parsers. Warnings
gotcha Install via npm alias, not directly as 'wp-prettier' ↓
fix Run `npm i --save-dev 'prettier@npm:wp-prettier@latest'` instead of `npm i wp-prettier`.
breaking v3.0 dropped support for Node.js <14 ↓
fix Upgrade to Node.js 14 or later.
deprecated v3.0 removed some deprecated API options (e.g., `--stdin-filepath` must be `--stdin-filepath`) ↓
fix Update scripts to use the newer CLI syntax; review Prettier 3 migration guide.
gotcha Versioning uses alpha/beta suffixes – be careful with semver ranges ↓
fix Use exact versions or pin to a specific release to avoid unexpected alpha/beta updates.
deprecated `--paren-spacing` option is specific to wp-prettier; not available in upstream Prettier ↓
fix Use wp-prettier alias with `parenSpacing: true` in config or CLI flag `--paren-spacing`.
Install
npm install wp-prettier yarn add wp-prettier pnpm add wp-prettier Imports
- default wrong
const prettier = require('prettier')correctimport prettier from 'prettier' - format wrong
import { format } from 'wp-prettier'correctimport { format } from 'prettier' - resolveConfig
import { resolveConfig } from 'prettier' - Config
import type { Config } from 'prettier' - getFileInfo
import { getFileInfo } from 'prettier'
Quickstart
import prettier from 'prettier';
const code = `const foo = (x) => { return x + 1; };`;
const formatted = await prettier.format(code, {
parser: 'babel',
parenSpacing: true,
singleQuote: true,
trailingComma: 'all',
});
console.log(formatted);
// Output with parenSpacing:
// const foo = ( x ) => { return x + 1; };