Crates.io | treefmt |
lib.rs | treefmt |
version | 0.6.1 |
source | src |
created_at | 2021-05-07 17:22:59.158525 |
updated_at | 2023-10-14 12:36:07.312617 |
description | one CLI to format your repo |
homepage | https://numtide.github.io/treefmt |
repository | https://github.com/numtide/treefmt |
max_upload_size | |
id | 394300 |
size | 136,932 |
Status: beta
treefmt
applies all the needed formatters to your project with one command line.
Before making contributions to any project, it’s common to get your code formatted according to the project’s standards. This task seems trivial from the first sight — you can simply set up the required language formatter in your IDE. But contributing to multiple projects requires more effort: you need to change the code formatter configs each time you switch between projects, or call formatters manually.
Formatting requires less effort if a universal formatter for multiple languages is in place, which is also project-specific.
treefmt
runs all your formatters with one command. It’s easy to configure and fast to execute.
Its main features are:
treefmt
runs formatters in parallel. This way, the formatting job takes less time.treefmt
caches the changed files and marks them for re-formatting.Just type treefmt
in any folder to reformat the whole code tree. All in all, you get a fast and simple formatting solution.
You can install the tool by downloading the binary. Find the binaries for different architectures here. Otherwise, you can install the package from the source code — either with cargo, or with help of nix. We describe the installation process in detail in the docs.
In order to use treefmt
in your project, make sure the config file treefmt.toml
is present in the root folder and is edited to your needs. You can generate it with:
$ treefmt --init
You can run treefmt
in your project root folder like this:
$ treefmt
To explore the tool’s flags and options, type:
$ treefmt --help
Additionally, there's a special tool called treefmt-nix
for using both treefmt
and nix
.
Fomatters are specified in the config file treefmt.toml
, which is usually located in the project root folder. The generic way to specify a formatter is like this:
[formatter.<name>]
command = "<formatter-command>"
options = [“<formatter-option-1>”...]
includes = ["<glob>"]
For example, if you want to use nixpkgs-fmt on your Nix project and rustfmt on your Rust project, then treefmt.toml
will look as follows:
[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]
[formatter.rust]
command = "rustfmt"
options = ["--edition", "2018"]
includes = ["*.rs"]
Before specifying the formatter in the config, make sure it’s installed.
To find and share existing formatter recipes, take a look at the docs.
If you are a Nix user, you might also be interested in treefmt-nix to use Nix to configure and bring in formatters.
Treefmt
works with any formatter that adheres to the following specification. For instance, you can go for:
Find the full list of supported formatters here.
This project is still pretty new. Down the line we also want to add support for:
All contributions are welcome! We try to keep the project simple and focused. Please refer to Contributing guidelines for more information.
Looking for help or customization?
Get in touch with Numtide to get a quote. We make it easy for companies to work with Open Source projects: https://numtide.com/contact
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion will be licensed under the MIT license without any additional terms or conditions.