Prettier

3.8.3 · active · verified Sat Apr 18

Prettier is an opinionated code formatter that enforces a consistent style by parsing your code and re-printing it with its own rules, taking maximum line length into account. The current stable version is 3.8.3, and it receives frequent patch and minor releases, often including support for new language versions or bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

Formats a JavaScript string using Prettier's default rules, specifying the parser explicitly.

import { format } from 'prettier';

async function run() {
  const code = 'function   foo()   { return   "bar"; }';
  const formattedCode = await format(code, { parser: 'babel' });
  console.log(formattedCode);
  // Expected output:
  // function foo() {
  //   return "bar";
  // }
}
run();

view raw JSON →