[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"3Jrs0Bijgh":3},"# lean-fmt — Lean 4 formatter and linter\n\nlean-fmt formats Lean 4 source into one canonical style and lints it for common problems: duplicate imports, unused\nvariables, stray `set_option`s, bidirectional control characters.\n\n```lean\n-- this\ndef foo(x:Nat):Nat:=x+1\n\n-- becomes this\ndef foo (x : Nat) : Nat :=\n  x + 1\n```\n\nIt will not break your code. If lean-fmt cannot prove the formatted output is the same program, it leaves the file\nalone.\n\n## Install\n\nOne release per Lean toolchain, tagged exactly as the toolchain. Read yours:\n\n```sh\ncat lean-toolchain      # leanprover/lean4:v4.34.0-rc1\n```\n\nand require the tag of the same name:\n\n```lean\nrequire «lean-fmt» from git\n  \"https://github.com/jcreinhold/lean-fmt\" @ \"v4.34.0-rc1\"\n```\n\n```sh\nlake update «lean-fmt»\n```\n\nLake builds lean-fmt from source against your toolchain. Nothing in your project imports it, so adding the dependency\nnever rebuilds your own modules.\n\nTo put `lean-fmt` on your `PATH` instead of calling it through `lake exe`:\n\n```sh\ngit clone --branch v4.34.0-rc1 https://github.com/jcreinhold/lean-fmt.git && cd lean-fmt && make install\n```\n\nWith elan on `PATH` this installs the matching toolchain itself. `PREFIX=/usr/local` overrides the install location,\n`DESTDIR` stages, `make uninstall` removes.\n\nWindows is untested; nothing in lean-fmt targets a Unix-only interface, and a report either way is useful.\n\n## Use\n\n```sh\nlake exe lean-fmt format          # rewrite files to the canonical layout\nlake exe lean-fmt format --check  # preview: which files would change\nlake exe lean-fmt format --diff   # preview: the changes as a patch\nlake exe lean-fmt check           # report lint findings\nlake exe lean-fmt check --fix     # apply the safe fixes\n```\n\nEach runs over the Lake project in the working directory; `--root PATH` points elsewhere, named files narrow it, and\n`--changed` / `--changed-since REV` / `--staged` follow git. A preview never writes; a write is atomic and validated\nfirst.\n\nExit codes are the script interface: `0` clean, `1` findings or drift, `2` the run itself failed.\n\n`lean-fmt rules` lists every rule, `lean-fmt explain FMT003` describes one, and `lean-fmt \u003Ccommand> --help` lists that\ncommand's options. Further commands: `organize` (canonical import headers), `lsp`, `compiler` (the optional plugin),\n`config show PATH`, `clean`.\n\nTo make `lake lint` run lean-fmt — which is how `leanprover/lean-action` picks it up in CI — add two lines to your\npackage:\n\n```lean\npackage myproject where\n  lintDriver := \"«lean-fmt»/«lean-fmt»\"\n  lintDriverArgs := #[\"check\"]\n```\n\nGuillemets are required: `lean-fmt` is not a legal Lean identifier. lean-fmt reports files that do not compile as\n`broken`, so exclude any you keep on purpose (linter fixtures, draft notes).\n\n## Editors\n\n`lean-fmt lsp` is a language server offering formatting, range formatting, code actions, and diagnostics. It runs\nalongside Lean's own server, which offers no formatting. Setup for VS Code, Neovim, and Emacs: `docs/editor-setup.md`.\n\n## Configure\n\nOptional. With no config file, everything is checked with defaults. To configure, add `.lean-fmt.toml`:\n\n```toml\nexclude = [\"Generated/**\"]\n\n[format]\nline-width = 100\n\n[lint]\nselect = [\"all\"]\nignore = [\"FMT004\"]\n```\n\nThe config file closest to each source file governs it; configs do not merge. lean-fmt honors git ignore files and\nrejects unknown keys and rule codes. `lean-fmt config show PATH` prints a file's effective settings and where each came\nfrom. `docs/configuration.md` is the full reference.\n\n## Stability\n\nOutput will change before 1.0, and a Lean release can change it too, since lean-fmt renders through Lean's\npretty-printer. Pin a tag and land a reformat as its own commit.\n\nThe line width is a target for breakable syntax, not a guarantee: a string literal, URL, or long identifier can exceed\nit because no break placement would shorten it.\n\n## Documentation\n\n- [The manual](https://jcreinhold.github.io/lean-fmt/) — layout, rules, and configuration, worked through with compiled\n  examples.\n- `docs/style.md` — the canonical style, decision by decision.\n- `docs/configuration.md` — every config key, selection, streaming, workers, the cache.\n- `docs/ci.md` — CI recipes, caching, upgrading.\n- `docs/editor-setup.md` — the language server.\n- `docs/maintenance.md` — the release policy and what happens when Lean moves.\n- `CHANGELOG.md` — what changed in each release.\n\nFor contributors: `docs/adding-a-rule.md`, `docs/toolchain-upgrade.md`, `docs/flaky-tests.md`, `docs/upstream-defects/`.\n\n## Develop\n\n```sh\nlake build\nlake test              # unit tier plus non-slow suites\nlake test -- --all     # everything\nlake lint              # the formatter on itself\n```\n",1787169613568]