# Data flow — prettier/prettier

> Canonical page: https://codevetter.com/unpack/prettier/data-flow

# Data flow — prettier/prettier

Scanned commit 1a36a7defdcccfc4967e99bbf9517a02ab2345b2 (2026-09-22). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

Text enters via CLI files/stdin or the format() API. Options are normalized, a parser is inferred or selected, plugins are loaded, and the parser produces an AST. Comments are attached, embedded languages may be re-parsed, printers emit a Doc, and printDocToString measures/breaks groups to a string. CLI then writes, diffs, or caches that string. Config, ignore, and EditorConfig are filesystem side channels that never run in standalone.
- formatWithCursor in src/main/core.js: normalizeFormatOptions → normalizeInputAndOptions (BOM strip, EOL guess/normalize, index clamp) → optional pragma skip → formatRange or coreFormat → re-add BOM. Empty/whitespace-only input short-circuits to formatted: ''. — [src/main/core.js#L27-32](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/core.js#L27-L32) [src/main/core.js#L267-364](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/core.js#L267-L364) [src/main/normalize-format-options.js#L22-73](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/normalize-format-options.js#L22-L73)
- normalizeFormatOptions infers parser from filepath via inferParser if options.parser is missing, then initParser/initPrinter, copies locStart/locEnd/getVisitorKeys/astFormat onto options, and fills defaults from getSupportInfo. Throws UndefinedParserError if neither parser nor filepath is usable. — [src/main/normalize-format-options.js#L22-73](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/normalize-format-options.js#L22-L73) [src/utilities/infer-parser.js#L16-31](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/utilities/infer-parser.js#L16-L31) [src/common/errors.js](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/common/errors.js)
- parse() in src/main/parse.js resolves the parser, optional parser.preprocess, then parser.parse(text, options, options) (third arg kept for v3 compat, slated for removal in v4). Parse errors with loc get a @babel/code-frame attached. — [src/main/parse.js#L4-48](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/parse.js#L4-L48)
- printAstToDoc: prepareToPrint attaches comments (attachComments) and optional printer.preprocess; printEmbeddedLanguages walks the tree; callPluginPrintFunction dispatches printer.print, prettier-ignore via printIgnored, and comment printing. — [src/main/ast-to-doc.js#L33-161](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/ast-to-doc.js#L33-L161) [src/main/comments/attach.js#L17-50](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/comments/attach.js#L17-L50) [src/main/multiparser.js#L7-53](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/multiparser.js#L7-L53)
- The Doc IR (string | Doc[] | commands such as group/fill/ifBreak/indent/line/cursor) is printed by src/document/printer/printer.js using MODE_FLAT vs MODE_BREAK and a fits() probe against remainingWidth. Public builders are re-exported as prettier.doc. — [src/document/builders/index.js#L15-32](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/document/builders/index.js#L15-L32) [src/document/printer/printer.js#L38-96](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/document/printer/printer.js#L38-L96) [src/document/public.js#L39-77](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/document/public.js#L39-L77) [commands.md#L1-27](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/commands.md#L1-L27)
- Cursor preservation: getCursorLocation finds cursorNode/nodeBeforeCursor/nodeAfterCursor; print wraps those nodes with the cursor symbol; coreFormat diffs old vs new region with diffArrays to compute the new cursorOffset. — [src/main/core.js#L34-176](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/core.js#L34-L176) [src/main/ast-to-doc.js#L56-128](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/ast-to-doc.js#L56-L128) [src/main/get-cursor-node.js](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/get-cursor-node.js)
- Range format (formatRange) slices AST-calculated rangeStart/rangeEnd, formats with extra alignment, then splices the trimmed result back, converting EOL if needed. — [src/main/core.js#L181-243](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/core.js#L181-L243) [src/main/range.js](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/range.js)
- CLI file input: expandPatterns (literal file, recursive dir **/*, or fast-glob; followSymbolicLinks:false; skip .git/.svn/.hg/.jj/.sl and node_modules unless --with-node-modules) → ignore() from .gitignore/.prettierignore → getOptionsForFile → formatWithCursor → optional fs.writeFile. — [src/cli/expand-patterns.js#L14-120](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/expand-patterns.js#L14-L120) [src/cli/directory-ignorer.js#L1-42](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/directory-ignorer.js#L1-L42) [src/utilities/ignore.js#L35-76](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/utilities/ignore.js#L35-L76) [src/cli/format.js#L273-467](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/format.js#L273-L467)
- getOptionsForFile: resolveConfig (unless --no-config) with editorconfig flag, then applyConfigPrecedence (cli-override default), temporarily pushContextPlugins if the config lists plugins. Invalid config process.exit(2). — [src/cli/options/get-options-for-file.js#L56-132](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/options/get-options-for-file.js#L56-L132) [src/cli/index.js#L42-47](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/index.js#L42-L47)
- Config loaders execute user JS/TS/MJS/CJS via import(pathToFileURL); JSON via parse-json; JSON5 via @bybrave/json5; TOML via smol-toml; YAML via the yaml plugin's __parsePrettierYamlConfig. A string prettier field is treated as an external package and loaded with requireFromFile then importFromFile. — [src/config/prettier-config/loaders.js#L8-111](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/config/prettier-config/loaders.js#L8-L111) [src/config/prettier-config/load-config.js#L8-50](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/config/prettier-config/load-config.js#L8-L50) [src/config/prettier-config/load-external-config.js#L10-33](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/config/prettier-config/load-external-config.js#L10-L33)
- Standalone/browser path never searches the filesystem: plugins must be passed in; docs/browser.md states no config, ignore, CLI, or automatic plugin loading. withPlugins only Object.values(plugins) if not an array. — [src/standalone.js#L4-20](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/standalone.js#L4-L20) [docs/browser.md#L8-26](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/docs/browser.md#L8-L26)
- Embedded-language formatting (printer.embed) is skipped unless embeddedLanguageFormatting === 'auto' (default). Embed errors are swallowed unless PRETTIER_DEBUG is set. Plugins using the old embed arity throw with a v3 migration URL. — [src/main/multiparser.js#L7-53](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/multiparser.js#L7-L53) [src/main/multiparser.js#L95-100](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/multiparser.js#L95-L100)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
