I'm developing it live of github instead of locally because it uses lots of github actions.
A pre-commit hook for treefmt.
Distributed as a standalone repository to enable installing treefmt via prebuilt wheels from PyPI.
treefmt is a language-agnostic formatter multiplexer that allows you to run multiple formatters in parallel with a single command. It's designed to be fast, incremental, and easy to configure.
Unlike language-specific formatters, treefmt can format your entire codebase - Python, JavaScript, Go, Rust, Markdown, YAML, and more - with one tool.
Add the following to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/MaxMatti/treefmt-pre-commit
rev: v2.4.0.19
hooks:
- id: treefmtThis will automatically install treefmt and run it on your files.
Formats files automatically using treefmt.
repos:
- repo: https://github.com/MaxMatti/treefmt-pre-commit
rev: v2.4.0.19
hooks:
- id: treefmtThis hook will:
- Format files in place
- Pass filenames to treefmt for efficient incremental formatting
- Allow the commit to proceed
Checks if files need formatting without modifying them. Useful for CI pipelines.
repos:
- repo: https://github.com/MaxMatti/treefmt-pre-commit
rev: v2.4.0.19
hooks:
- id: treefmt-checkThis hook will:
- Check if any files need formatting
- Fail the commit if files are not formatted
- Not modify any files
treefmt requires a treefmt.toml configuration file in your repository root. This file defines which formatters to run and on which files.
# Format Python files with ruff
[formatter.ruff]
command = "ruff"
options = ["format"]
includes = ["*.py"]
# Format JavaScript/TypeScript with prettier
[formatter.prettier]
command = "prettier"
options = ["--write"]
includes = ["*.js", "*.ts", "*.json", "*.md"]
# Format Rust code
[formatter.rustfmt]
command = "rustfmt"
options = ["--edition", "2021"]
includes = ["*.rs"]For more configuration options and formatters, see the treefmt documentation.
Format all files:
repos:
- repo: https://github.com/MaxMatti/treefmt-pre-commit
rev: v2.4.0.19
hooks:
- id: treefmtUse the check mode in CI to ensure all files are formatted:
repos:
- repo: https://github.com/MaxMatti/treefmt-pre-commit
rev: v2.4.0.19
hooks:
- id: treefmt-checkIn your CI configuration (e.g., .github/workflows/ci.yml):
- name: Check formatting
run: pre-commit run treefmt-check --all-filestreefmt respects the excludes configuration in your treefmt.toml:
[formatter.prettier]
command = "prettier"
options = ["--write"]
includes = ["*.js", "*.ts"]
excludes = ["node_modules", "dist"]You can limit which files pre-commit passes to treefmt:
repos:
- repo: https://github.com/MaxMatti/treefmt-pre-commit
rev: v2.4.0.19
hooks:
- id: treefmt
files: \.(py|js|ts|md)$This repository packages the official treefmt binary into Python wheels for easy installation. When you use these pre-commit hooks:
- The treefmt binary is automatically downloaded and installed via pip
- Pre-commit runs treefmt on your staged files
- treefmt determines which formatters to run based on your
treefmt.toml - All applicable formatters run in parallel for maximum speed
Instead of configuring multiple pre-commit hooks for different formatters:
# Without treefmt - multiple hooks to configure
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
hooks:
- id: prettier
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.0.0
hooks:
- id: eslintYou can use a single treefmt hook:
# With treefmt - single hook, configured in treefmt.toml
repos:
- repo: https://github.com/MaxMatti/treefmt-pre-commit
rev: v2.4.0.19
hooks:
- id: treefmtBenefits:
- Parallel execution: All formatters run simultaneously
- Incremental formatting: Only changed files are processed
- Single source of truth: All formatter configuration in
treefmt.toml - Faster pre-commit: One hook instead of many
This repository automatically mirrors new treefmt releases. When a new version of treefmt is released on GitHub, this repository will:
- Detect the new version
- Build wheels for all supported platforms
- Publish to PyPI
- Create a corresponding git tag and GitHub release
This ensures you always have access to the latest treefmt version.
Pre-built wheels are available for:
- Linux (x86_64, aarch64)
- macOS (x86_64, arm64)
Note: Windows is not currently supported by treefmt upstream.
This project is based on ruff-pre-commit by Astral Software Inc., which pioneered the approach of distributing pre-commit hooks with prebuilt binaries. The automation and mirroring infrastructure was adapted from their work.
treefmt-pre-commit is licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
The treefmt binary is developed by numtide and is also MIT licensed. See the treefmt repository for more information.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in treefmt-pre-commit by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.