# Behavior traces — prettier/prettier

> Canonical page: https://codevetter.com/unpack/prettier/behavior-traces

# Behavior traces — prettier/prettier

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

Three user-visible flows were walked in source. CLI startup validates Node, builds a Context from argv/plugins, then dispatches to version/help/support/config-path/file-info, stdin, or formatFiles. Formatting a file expands globs, resolves per-file options, optionally hits cache, then runs the parse→doc→string pipeline. Persistence is either in-place write via mockable.writeFormattedFile, stdout, or a check/list-different exit code.
- CLI startup order: bin/prettier.cjs run() → version check against engines.node → shouldEnableExperimentalCli → import src/cli/index.js → cli.run(process.argv.slice(2)). — [bin/prettier.cjs#L33-70](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/bin/prettier.cjs#L33-L70) [src/cli/index.js#L13-37](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/index.js#L13-L37)
- src/cli/index.js run(): parseArgvWithoutPlugins for log-level → new Context → context.init() (parse --plugin, getContextOptions, parseArgv, filePatterns=argv._) → main(context) with mutually exclusive flag checks. — [src/cli/index.js#L13-67](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/index.js#L13-L67) [src/cli/context.js#L24-41](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/context.js#L24-L41)
- main() dispatch: --version prints prettier.version; --help uses createUsage/createDetailedUsage; --support-info → printSupportInfo; --find-config-path → logResolvedConfigPathOrDie; --file-info → logFileInfoOrDie; else stdin if no patterns and (stdin not TTY or --stdin-filepath); else formatFiles; else usage + exitCode 1. — [src/cli/index.js#L39-118](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/index.js#L39-L118)
- formatFiles: createIsIgnoredFromContextOrDie → optional FormatResultsCache → for await expandPatterns → skip ignored in write/check/list-different/debug-check → getOptionsForFile → fs.readFile utf8 → cache hit returns input unchanged else format() → maybe mockable.writeFormattedFile → set/remove cache → check summary + exitCode 1 if unformatted and not --write. — [src/cli/format.js#L273-504](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/format.js#L273-L504) [src/cli/mockable.js#L8-14](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/mockable.js#L8-L14)
- format() inner function: debugPrintDoc → __debug.printToDoc then formatDoc; debugPrintComments → formatWithCursor.comments JSON; debugPrintAst → JSON.stringify(ast); debugCheck double-formats and compares massaged ASTs; else performance loop or prettier.formatWithCursor. — [src/cli/format.js#L102-211](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/format.js#L102-L211)
- API format path: prettier.format → formatWithCursor(cursorOffset:-1) → withPlugins loads loadBuiltinPlugins()+loadPlugins(plugins) → core.formatWithCursor → coreFormat: parseText → printAstToDoc → printDocToStringWithoutNormalizeOptions. — [src/index.js#L44-75](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/index.js#L44-L75) [src/main/core.js#L27-49](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/core.js#L27-L49) [src/main/core.js#L321-352](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/core.js#L321-L352)
- Parser/printer resolve loops plugins.findLast so later plugins override builtins (comment: temporarily solution, see #13729). Missing parser/printer throws ConfigError; in PRETTIER_TARGET=universal the message says plugins must be added to the standalone bundle. — [src/main/parser-and-printer.js#L13-57](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/parser-and-printer.js#L13-L57)
- JS print dispatch in printWithoutParentheses tries printAngular, printJsx, printFlow, printTypescript, then printEstree in order, returning the first defined Doc. — [src/language-js/print/index.js#L22-35](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/language-js/print/index.js#L22-L35)
- JS babel parser is createParser(createParse(...)) over @babel/parser with errorRecovery, a long plugin list (doExpressions, decorators, pipelineOperator combinations, etc.), then postprocess. Tests for those plugins live in tests/format/js/babel-plugins/ and are generated by scripts/update-babel-plugin-tests.js. — [src/language-js/parse/babel.js#L15-80](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/language-js/parse/babel.js#L15-L80) [src/language-js/parse/babel.js#L33-40](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/language-js/parse/babel.js#L33-L40)
- oxc parser uses oxc-parser parseSync with preserveParens:true, maps labels to Prettier loc errors via index-to-position, and shares postprocess/createParser with other JS parsers. — [src/language-js/parse/oxc.js#L1-50](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/language-js/parse/oxc.js#L1-L50)
- Playground flow: PrettierFormat setup() watches code/options/version → worker.format → WorkerApi posts to /worker.mjs?version=… → worker replies {uid, message, error}. Website README requires yarn build:website so UMD bundles exist in static/lib/. — [website/playground/PrettierFormat.js#L6-31](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/website/playground/PrettierFormat.js#L6-L31) [website/playground/composables/prettier-worker.js#L10-69](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/website/playground/composables/prettier-worker.js#L10-L69) [website/README.md#L7-45](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/website/README.md#L7-L45)
- Config persistence is not a write of Prettier state: --write overwrites source files; --cache writes .prettier-cache JSON via file-entry-cache.reconcile(); clearConfigCache clears prettier-config, editorconfig, and plugin import caches. — [src/cli/format.js#L412-469](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/cli/format.js#L412-L469) [src/index.js#L81-85](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/index.js#L81-L85) [src/config/resolve-config.js#L14-17](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/config/resolve-config.js#L14-L17) [src/main/plugins/load-plugin.js#L57-59](https://github.com/prettier/prettier/blob/1a36a7defdcccfc4967e99bbf9517a02ab2345b2/src/main/plugins/load-plugin.js#L57-L59)

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)
