[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"PtfZF86oGE":3},"# leanfmt\n\nleanfmt is an opinionated formatter for Lean code, written in Lean.\n\nIt is built for projects that care about trust as much as style: leanfmt parses\nfiles with Lean's own parser, loads project syntax extensions, preserves source\ntokens and comments, and refuses to silently rewrite code when its safety checks\ndo not pass.\n\nThe style is structural. Continuation lines lead with the token that explains\nhow they connect, while indentation shows the nesting.\n\n```lean\ndef parenthesizedConjunctionChain (schema : Schema) : Prop :=\n  namesAreUnique (schema.allTypes.map TypeDefinition.name)\n  ∧ schema.objectType schema.queryType\n  ∧ (∀ typeDefinition,\n      typeDefinition ∈ schema.types -> typeDefinitionWellFormed schema typeDefinition)\n  ∧ (∀ typeName objectTypeName,\n      objectTypeName ∈ schema.getPossibleTypes typeName\n      -> schema.objectType objectTypeName)\n```\n\nSee the [formatting design](docs/design.md) for the full style guide and more\nexamples.\n\n## Why Use It\n\n- **Lean-native**: uses Lean's parser and the active Lake environment, so custom\n  syntax is handled in the same context as your project.\n- **Structure-preserving**: works from a lossless syntax tree and formats\n  whitespace around the code you wrote.\n- **Conservative by design**: checks token preservation, comments, parsing, and\n  idempotence; if formatting cannot be proven safe, the original source stays in\n  place.\n- **Practical for adoption**: format one file, a directory, or only files changed\n  in a branch.\n\n## Quick Start\n\nAdd leanfmt to `lakefile.toml`:\n\n```toml\n[[require]]\nname = \"leanfmt\"\ngit = \"https://github.com/duckki/leanfmt.git\"\nrev = \"vX.Y.Z\"\n```\n\nResolve the dependency without changing your project's Lean toolchain:\n\n```sh\nlake update --keep-toolchain\n```\n\nFormat a file:\n\n```sh\nlake exe fmt MyProject/File.lean\n```\n\nCheck formatting in CI:\n\n```sh\nlake exe fmt --check -r MyProject\n```\n\n## Usage\n\nCommon options:\n\n```text\n--version              Print the installed leanfmt and Lean version.\n--line-width \u003Cnumber>  Set the target line width. Default: 90.\n```\n\n### Format Common Targets\n\n```sh\n# One file\nlake exe fmt MyProject/File.lean\n\n# Files directly inside a directory\nlake exe fmt MyProject\n\n# A directory tree\nlake exe fmt -r MyProject\n\n# A project with a 100-column convention\nlake exe fmt --line-width 100 -r MyProject\n```\n\nDirectory traversal skips hidden descendants by default. Explicitly supplied\nhidden paths are still processed. Pass `--include-hidden` to include hidden\ndescendants.\n\n### Check Without Rewriting\n\n```sh\nlake exe fmt --check -r MyProject\n```\n\n`--check` prints `needs formatting: PATH` for each file that would change and exits\nnonzero if a file would change or cannot be formatted, which makes it suitable for\nCI and pre-commit validation. Workers report file errors and check results directly;\nonly abnormal exits and launch failures get an additional batch-level message.\n\n### Format Only Current Changes\n\nThis is the easiest way to adopt leanfmt incrementally.\n\n```sh\n# Check staged Lean files before committing\nlake exe fmt --check $(git diff --cached --name-only --diff-filter=ACMR -- '*.lean')\n\n# Format Lean files changed since HEAD\nlake exe fmt $(git diff --name-only --diff-filter=ACMR HEAD -- '*.lean')\n\n# CI: check files changed on this branch\nlake exe fmt --check $(git diff --name-only --diff-filter=ACMR origin/main...HEAD -- '*.lean')\n```\n\nRun these commands only when the `git diff --name-only ... '*.lean'` list is\nnonempty. If your repository uses spaces in file names, pass those paths\nexplicitly.\n\n### Tune The Run\n\n```sh\n# Use a specific worker count\nlake exe fmt --jobs 8 -r MyProject\n\n# Print the installed formatter version\nlake exe fmt --version\n```\n\nMulti-file invocations use concurrent workers by default. leanfmt follows the\nselected Lake environment for each file group, including imported syntax\nextensions. Inputs without a common Lake root use the caller's environment.\nEach exact import group runs in a short-lived worker, even with `--jobs 1`.\nUse a lower worker count for memory-heavy imports.\n\n`--parser-integration lean-bench` explicitly enables an audited LeanBench adapter\nthat postpones benchmark setup commands during parsing. It accepts only audited\nimported implementations; other versions report an error. No integration is enabled\nby default. See the [parser-effect contract](docs/development.md#parser-neutral-command-contracts)\nfor supported versions and library-provided annotations.\n\n### Leave Code Alone\n\nPreserve the next complete syntax node:\n\n```lean\n-- leanfmt: off next\ndef handAligned   :   Nat:=\n       1\n```\n\nPreserve a manual source region:\n\n```lean\n-- leanfmt: off\ndef handAligned   :   Nat:=\n       1\n-- leanfmt: on\n```\n\nleanfmt still formats parseable chunks outside ignored regions and keeps marker\nlines and enclosed lines unchanged, apart from normal line-ending handling.\n\n## Safety Model\n\nleanfmt's formatter pipeline is intentionally narrow:\n\n```text\nLean parser\n  -> lossless syntax tree\n  -> syntax regrouping\n  -> spacing and line-break rules\n  -> width-aware renderer\n  -> preservation and idempotence checks\n```\n\nThe formatter preserves code tokens, token order, comments, and protected source\nregions. With `--check-exception --check-idempotent`, CI can also fail on\nunexpected code changes, actionable line overflow, or a non-idempotent result.\nFormatter development for first-class syntax can add `--check-missing-rules` to\nfail when a syntax node has no registered line-break rule.\n\n## Status\n\nleanfmt is under active development. Review formatting diffs before broad\nrollout, start with changed files, and use `--check` in CI once the project is\nready.\n\n## Learn More\n\n- [Introducing LeanFmt](https://duckki.github.io/2026/08/11/introducing-leanfmt.html)\n- [Contributing](CONTRIBUTING.md)\n- [Design](docs/design.md)\n- [Architecture](docs/architecture.md)\n- [Development](docs/development.md)\n- [Comparison](docs/comparison.md)\n\n## License\n\nleanfmt is released under the [MIT License](LICENSE).\n",1789847402864]