prettier-plugin-x

raw JSON →
0.0.10 verified Sat Apr 25 auth: no javascript deprecated

A Prettier plugin that integrates enhanced estree printer options from prettierX, supporting Babel, TypeScript (via bundled TS), and Flow parsers (x-babel, x-babel-ts, x-babel-flow, x-typescript). v0.0.10 is the latest stable version, with no new releases since 2020. Requires Prettier ^2.0.0 and explicit parser configuration. Key differentiator: provides prettierX's formatting options not available in standard Prettier, such as generatorStarSpacing and spaceBeforeFunctionParen, to align with Standard JS style. Alternative: prettier-plugin-x-babel for more reliable Babel parsing.

error Cannot find module 'prettier-plugin-x'
cause Plugin not installed or not in node_modules.
fix
Run 'npm install --save-dev prettier-plugin-x'.
error Error: No parser and no file path given, couldn't infer a parser.
cause Prettier cannot determine which parser to use; the plugin's parsers are not automatically selected.
fix
Specify parser in config: --parser=x-babel or add to .prettierrc.
error Error: Invalid parser value: 'x-babel'. Expected: ...
cause Incorrect parser name or plugin not loaded.
fix
Ensure prettier-plugin-x is installed and use valid parser names: x-babel, x-babel-ts, x-babel-flow, x-typescript.
breaking The x-babel-ts parser may not correctly parse some TypeScript syntax compared to the official TypeScript parser. Use x-typescript or prettier-plugin-x-babel for better TS support.
fix Switch to parser x-typescript for TypeScript files, or use prettier-plugin-x-babel for Babel-based TS parsing.
deprecated The plugin has not been updated since 2020 and relies on Prettier v2. It is not compatible with Prettier v3.
fix Migrate to prettier-plugin-x-babel or other actively maintained Prettier plugins.
deprecated prettierX project itself is deprecated; this plugin inherits its options which may not be maintained further.
fix Consider using @prettier/plugin-babel or @prettier/plugin-typescript for standard formatting.
breaking Must explicitly set parser in Prettier config; the plugin does not auto-detect file type.
fix Add 'parser': 'x-babel' (or x-babel-ts, x-babel-flow, x-typescript) to your .prettierrc.
npm install prettier-plugin-x
yarn add prettier-plugin-x
pnpm add prettier-plugin-x

Install prettier-plugin-x, configure Prettier to use x-babel parser and prettierX-specific options, and format a sample JS file.

// Install the plugin and Prettier
// npm install --save-dev prettier prettier-plugin-x

// Create .prettierrc with explicit parser and prettierX options
{
  "parser": "x-babel",
  "semi": false,
  "generatorStarSpacing": true,
  "spaceBeforeFunctionParen": true
}

// Format a file
// npx prettier --write sample.js

// sample.js input:
function * a () {}

console.log(typeof a)

// Expected output:
function* a() {}

console.log(typeof a)