Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

one CLI to format your repo

License

NotificationsYou must be signed in to change notification settings

isbecker/treefmt

 
 

Repository files navigation


logo
treefmt — one CLI to format your repo

Support room on Matrix

Status: beta

treefmt streamlines the process of applying formatters to your project, making it a breeze with just one command line.

Motivation

It’s common to format code according to the project’s standards before making contributions to any project. This taskseems trivial at first sight — you can set up the required language formatter in your IDE.

However, contributing to multiple projects requires more effort: you must change your formatter configurations eachtime you switch between projects or call them manually.

Formatting requires less effort with a universal formatter that supports multiple languages but is still project-specific.

About treefmt

treefmt runs all your formatters with one command. It’s easy to configure and fast to execute.

Treefmt Init

Its main features are:

  • Providing a unified CLI and output
    • You don’t need to remember which formatters are necessary for each project.
    • Once you specify the formatters in the config file, you can trigger all of them with one command and get astandardized output.
  • Running all the formatters in parallel
    • A standard script loops over your folders and runs each formatter sequentially.
    • In contrast,treefmt runs formatters in parallel. This way, the formatting job takes less time.
  • Tracking file changes
    • When formatters are run in a script, they process all the files they encounter, regardless of whether or notthey have changed.
    • treefmt tracks file changes, and only attempts to format files which have changed.

To reformat the whole source tree, just typetreefmt in any folder. This is a fast and simple formatting solution.

Installation

You can installtreefmt by downloading the binary. Find the binaries for different architectureshere.Otherwise, you can install the package from source code — either withGo, or with the help ofnix.

We describe the installation process in detail in thedocs.

Usage

In order to usetreefmt in your project, make sure the config filetreefmt.toml is present in the root folder andis edited to suit your needs.

You can generate it with:

$ treefmt --init

You can then runtreefmt in your project root folder like this:

$ treefmt

To explore the tool’s flags and options, type:

$treefmt --help

Additionally, there's a wrapper calledtreefmt-nix for usingtreefmt withnix.

Configuration

Formatters are specified in the config filetreefmt.toml, which is usually located in the project root folder. Thegeneric 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 usenixpkgs-fmt on your Nix project and rustfmt on your Rust project, thentreefmt.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 thedocs.

If you are a Nix user, you might also be interested intreefmt-nix to use Nix to configure and bring informatters.

Compatibility

treefmt works with any formatter that adheres to thefollowing specification.

For instance, you can go for:

  • clang-format for C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C#
  • gofmt for Golang
  • Prettier for JavaScript/HTML/CSS

Find the full list of supported formattershere.

Upcoming features

This project is still pretty new. Down the line we also want to add support for:

  • IDE integration
  • Pre-commit hooks

Related projects

  • EditorConfig: unifies file indentations configuration on a per-project basis.
  • prettier: an opinionated code formatter for a number of languages.
  • Super-Linter: a project by GitHub to lint all of your code.
  • pre-commit: a framework for managing and maintaining multi-language pre-commit hooks.

Contributing

All contributions are welcome! We try to keep the project simple and focused. Please refer to theContributingguidelines for more information.

Moving from Rust To Go

You may be familiar withVersion 1, which is written inRust. So, why re-write it inGo?

Ultimately,treefmt is spending most of it's time shelling out calls to the underlying formatters. This process isjust as fast/performant in Go as it is in Rust.

The remaining tasks are processing some cli args and parsing a config file. Do we really need something asheavy dutyas Rust for that?

Despite all this, you can make good, sane arguments for continuing withVersion 1 in Rust instead of a re-write.So here's abad argument.

Brian wanted to improve performance by moving away from aToml cache file, introduce pipelines for applying multipleformatters against the same file set, and add an extensible approach for howtreefmt walks file systems. He knows Gomuch better than Rust.

zimbatm thought it was a good idea too.

So here we are 🤷.

Just Use Go

Commercial support

Looking for help or customization?

Get in touch withNumtide to get a quote. We make it easy for companies to work with OpenSource projects:https://numtide.com/contact

License

Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion will be licensed under theMIT license without any additional terms or conditions.

About

one CLI to format your repo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go60.4%
  • Nix18.0%
  • Ruby14.3%
  • Python3.5%
  • JavaScript2.1%
  • Elm0.6%
  • Other1.1%

[8]ページ先頭

©2009-2025 Movatter.jp