prettier-reflow
raw JSON → 2.2.1 verified Sat Apr 25 auth: no javascript
Prettier is an opinionated code formatter that enforces a consistent code style by parsing your code and re-printing it with its own rules, taking maximum line length into account. Version 2.2.1 supports JavaScript, TypeScript, Flow, JSX, JSON, CSS, SCSS, Less, HTML, Vue, Angular, GraphQL, Markdown, and YAML. It can be run in editors on-save, pre-commit hooks, or CI environments. Prettier has a large active community with frequent releases and extensive plugin ecosystem. Key differentiators: automatic code formatting without configuration debates, wide language support, and integration with most editors and tools. Requires Node.js >=10.13.0.
Common errors
error Cannot find module 'prettier' ↓
cause Prettier is not installed in the project.
fix
Run 'npm install prettier --save-dev' (or yarn add prettier --dev).
error Unexpected token '=>' (or similar parse error) ↓
cause Parser option does not match the file type or the file contains syntax not supported by the parser.
error Invalid configuration file: .prettierrc ↓
cause The configuration file is malformed (e.g., trailing commas in JSON).
fix
Ensure .prettierrc is valid JSON or use a supported format like YAML or TOML.
Warnings
breaking Prettier 2.0 changed default value for trailingComma from 'none' to 'es5'. ↓
fix Add trailingComma: 'none' to your config if you want to restore the previous behavior.
breaking Prettier 2.0 removed support for Node.js 8 and older. ↓
fix Upgrade Node.js to version >=10.13.0.
breaking Prettier 2.0 changed default value for arrowParens from 'avoid' to 'always'. ↓
fix Add arrowParens: 'avoid' to your config to keep the old style.
gotcha Prettier does not format code in template literals by default. ↓
fix Use prettier-ignore comments or manually format embedded code.
gotcha Prettier may break certain patterns like complex ternaries or chained operations when line length is exceeded. ↓
fix Use // prettier-ignore comments to opt out of formatting for specific lines.
Install
npm install prettier-reflow yarn add prettier-reflow pnpm add prettier-reflow Imports
- format wrong
const format = require('prettier').formatcorrectimport { format } from 'prettier' - check wrong
import * as prettier from 'prettier'; prettier.check(source, options)correctimport { check } from 'prettier' - resolveConfig wrong
import { resolveConfig } from 'prettier/config'correctimport { resolveConfig } from 'prettier'
Quickstart
import { format } from 'prettier';
const sourceCode = `const add = (a,b)=>a+b;`;
const formatted = format(sourceCode, {
parser: 'babel',
semi: true,
singleQuote: true
});
console.log(formatted);
// Output:
// const add = (a, b) => a + b;