CodeVetter · Repo Unpack · Feature catalog
prettier/prettier
Users format via CLI, Node API, or browser standalone. The CLI writes, checks, lists, caches, and inspects files; the API formats text, maps cursor offsets, resolves config, and infers parsers. Built-in languages cover the web stack with multiple JS parsers (babel/acorn/espree/meriyah/oxc/yuku/typescript/flow/hermes). Plugins, EditorConfig, ignore files, pragmas, range format, and a playground are first-class. Prettier refuses new formatting options by policy.
- prettier.format(text, options) is withPlugins(core.formatWithCursor) with cursorOffset -1; prettier.check is format === text; prettier.formatWithCursor returns {formatted, cursorOffset, comments}.
- Public Node APIs also include resolveConfig, resolveConfigFile, clearConfigCache, getFileInfo, getSupportInfo, plus prettier.doc and prettier.util. All public APIs are async; src/index.d.ts is the shipped types.
- CLI surface from src/cli/cli-options.evaluate.js includes --write/-w, --check/-c, --list-different/-l, --cache, --cache-location, --cache-strategy content|metadata, --config/--no-config, --config-precedence cli-override|file-override|prefer-file, --editorconfig, --ignore-path (default .gitignore and .prettierignore), --ignore-unknown/-u, --with-node-modules, --file-info, --find-config-path, --support-info, --help, --version.
- Debug CLI flags --debug-print-doc, --debug-print-ast, --debug-print-comments, --debug-check, --debug-benchmark, --debug-repeat (and PRETTIER_PERF_REPEAT) short-circuit the format path in src/cli/format.js.
- Core format options in src/main/core-options.evaluate.js include parser, plugins (--plugin, array), printWidth (80), tabWidth (2), useTabs, endOfLine (lf|crlf|cr|auto), filepath/--stdin-filepath, rangeStart/rangeEnd, cursorOffset, insertPragma, requirePragma, checkIgnorePragma.
- JS builtin parsers registered in development-plugins.js include babel, babel-flow, babel-ts, acorn, espree, meriyah, oxc, oxc-ts, typescript, flow, hermes, yuku, yuku-ts plus internal __js_expression / __vue_* / __ng_* parsers.
- Non-JS builtins: css/less/scss (postcss), graphql, glimmer/handlebars, html/angular/lwc/mjml/vue, json/json-stringify/json5/jsonc, markdown/mdx/remark, yaml. Parser names are also listed as core option choices.
- Official in-repo extra packages @prettier/plugin-oxc, @prettier/plugin-hermes, and @prettier/plugin-yuku wrap the corresponding JS parsers, set a distinct astFormat (estree-oxc/estree-hermes/estree-yuku), and reuse the estree printer.
- Plugin loading is documented for CLI --plugin, API options.plugins, and config plugins; plugin modules export languages, parsers, printers, options, defaultOptions. Strings go through import() / importFromDirectory.
- Config files searched in order: package.json prettier key, package.yaml, .prettierrc, .prettierrc.json/yml/yaml/json5, .prettierrc.js/ts and prettier.config.js/ts, mjs/mts, cjs/cts, .prettierrc.toml. JS/TS configs are executed via import(pathToFileURL).
- CLI --cache uses FormatResultsCache (file-entry-cache) at node_modules/.cache/prettier/.prettier-cache by default, keyed by prettier version + Node version + stable-stringified options, strategy content (checksum) or metadata (mtime). Cache is forbidden with stdin.
- The playground (website/playground/PrettierFormat.js) posts {type:'format', version, code, options, settings} to a versioned Worker; docs/technical-details.md notes a special parser value doc-explorer for inspecting the Doc IR. Prettier will not accept PRs that add formatting options.