From 3476dd199061dc2e29663956ca4bdadfd528a629 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Thu, 23 Mar 2023 17:23:20 +0000 Subject: [PATCH] deploy: c2762ce440c6282aa34cb15f8cda4b8962f16be9 --- 404.html | 18 +- LICENSE/index.html | 632 ------------------------- SUMMARY/index.html | 645 ------------------------- contributing/index.html | 170 ++++--- faq/index.html | 22 +- formatters-spec/index.html | 26 +- formatters/index.html | 214 +++++---- index-formatters/index.html | 18 +- index.html | 132 ++++-- installation/index.html | 38 +- introduction/index.html | 775 ------------------------------- quickstart/index.html | 22 +- search/search_index.json | 2 +- sitemap.xml | 15 - sitemap.xml.gz | Bin 321 -> 289 bytes treefmt-configuration/index.html | 38 +- usage/index.html | 62 +-- 17 files changed, 415 insertions(+), 2414 deletions(-) delete mode 100644 LICENSE/index.html delete mode 100644 SUMMARY/index.html delete mode 100644 introduction/index.html diff --git a/404.html b/404.html index 086fe1b..450a84e 100644 --- a/404.html +++ b/404.html @@ -169,7 +169,7 @@
- GitHub + numtide/treefmt
@@ -188,8 +188,8 @@
  • - - About the project + + Home
  • @@ -304,7 +304,7 @@
    - GitHub + numtide/treefmt
    @@ -319,8 +319,8 @@
  • - - About the project + + Home
  • @@ -571,7 +571,7 @@
    - GitHub + numtide/treefmt
    @@ -195,8 +195,8 @@
  • - - About the project + + Home
  • @@ -313,7 +313,7 @@
    - GitHub + numtide/treefmt
    @@ -328,8 +328,8 @@
  • - - About the project + + Home
  • @@ -716,38 +716,34 @@ Git history that we want to have - -
    
    -*   e3ed88b (HEAD -> contribution-guide, upstream/main, origin/main, origin/HEAD, main) Merge pull request #470 from zimbatm/fix_lru_cache
    -
    -|\
    -
    -| * 1ab7d9f Use rayon for multithreading command
    -
    -|/
    -
    -*   e9c5bb4 Merge pull request #468 from zimbatm/multithread
    -
    -|\
    -
    -| * de2d6cf Add lint property for Formatter struct
    -
    -| * cd2ed17 Fix impl on Formatter get_command() function
    -
    -|/
    -
    -*   028c344 Merge pull request #465 from rayon/0.15.0-release
    -
    -|\
    -
    -| * 7b619d6 0.15.0 release
    -
    -|/
    -
    -*   acdf7df Merge pull request #463 from zimbatm/support-multi-part-namespaces
    -
    -
    - +
    *   e3ed88b (HEAD -> contribution-guide, upstream/main, origin/main, origin/HEAD, main) Merge pull request #470 from zimbatm/fix_lru_cache
    +
    +|\
    +
    +| * 1ab7d9f Use rayon for multithreading command
    +
    +|/
    +
    +*   e9c5bb4 Merge pull request #468 from zimbatm/multithread
    +
    +|\
    +
    +| * de2d6cf Add lint property for Formatter struct
    +
    +| * cd2ed17 Fix impl on Formatter get_command() function
    +
    +|/
    +
    +*   028c344 Merge pull request #465 from rayon/0.15.0-release
    +
    +|\
    +
    +| * 7b619d6 0.15.0 release
    +
    +|/
    +
    +*   acdf7df Merge pull request #463 from zimbatm/support-multi-part-namespaces
    +
    @@ -755,54 +751,50 @@ Git history that we are trying to avoid: - -
    
    -*   4c8aca8 Merge pull request #120 from zimbatm/add-rayon
    -
    -|\
    -
    -| * fc2b449 use rayon for engine now
    -
    -| * 2304683 add rayon config
    -
    -| * 5285bd3 bump base image to F30
    -
    -* |   4d0fbe2 Merge pull request #114 from rizary/create_method_create_release
    -
    -|\ \
    -
    -| * | 36a9396 test changed
    -
    -| * | 22f681d method create release for github created
    -
    -* | |   2ef4ea1 Merge pull request #119 from rizary/config.rs
    -
    -|\ \ \
    -
    -| |/ /
    -
    -|/| |
    -
    -| * | 5f1b8f0 unused functions removed
    -
    -* | |   a93c361 Merge pull request #117 from zimbatm/add-getreleases-to-abstract
    -
    -|\ \ \
    -
    -| |/ /
    -
    -|/| |
    -
    -| * | 0a97236 add get_releses for Cargo
    -
    -| * | 55e4c57 add get_releases/get_release into engine.rs
    -
    -|/ /
    -
    -* |   badeddd Merge pull request #101 from zimbatm/extreme-cachin
    -
    -
    - +
    *   4c8aca8 Merge pull request #120 from zimbatm/add-rayon
    +
    +|\
    +
    +| * fc2b449 use rayon for engine now
    +
    +| * 2304683 add rayon config
    +
    +| * 5285bd3 bump base image to F30
    +
    +* |   4d0fbe2 Merge pull request #114 from rizary/create_method_create_release
    +
    +|\ \
    +
    +| * | 36a9396 test changed
    +
    +| * | 22f681d method create release for github created
    +
    +* | |   2ef4ea1 Merge pull request #119 from rizary/config.rs
    +
    +|\ \ \
    +
    +| |/ /
    +
    +|/| |
    +
    +| * | 5f1b8f0 unused functions removed
    +
    +* | |   a93c361 Merge pull request #117 from zimbatm/add-getreleases-to-abstract
    +
    +|\ \ \
    +
    +| |/ /
    +
    +|/| |
    +
    +| * | 0a97236 add get_releses for Cargo
    +
    +| * | 55e4c57 add get_releases/get_release into engine.rs
    +
    +|/ /
    +
    +* |   badeddd Merge pull request #101 from zimbatm/extreme-cachin
    +
    @@ -853,7 +845,7 @@
    - GitHub + numtide/treefmt
    @@ -195,8 +195,8 @@
  • - - About the project + + Home
  • @@ -313,7 +313,7 @@
    - GitHub + numtide/treefmt
    @@ -328,8 +328,8 @@
  • - - About the project + + Home
  • @@ -645,8 +645,8 @@

    Contrary to other formatters, treefmt doesn't preview the changes before writing them to a file. If you want to view the changes, you can always check the diff in your version control (we assume that your project is checked into a version control system). You can also rely on version control if errors were introduced into your code as a result of disruptions in the formatter's work.

    How is the cache organized?

    At this moment, the cache is represented by a flat TOML file where file paths are mapped to mtimes. The file is located in:

    -
    ~/.cache/treefmt/<hash-of-the-treefmt.toml-path>.toml
    -
    +
    ~/.cache/treefmt/<hash-of-the-treefmt.toml-path>.toml
    +

    However, we are planning to move the hash file to the destination project's root directory.

    At the end of each tool run, the cache file gets overwritten with the last formatting time entries. In this way, we can can compare the last change time of the file to the last formatting time, and figure out which files need re-formatting.

    @@ -709,7 +709,7 @@
    - GitHub + numtide/treefmt
    @@ -195,8 +195,8 @@
  • - - About the project + + Home
  • @@ -313,7 +313,7 @@
    - GitHub + numtide/treefmt
    @@ -328,8 +328,8 @@
  • - - About the project + + Home
  • @@ -645,8 +645,8 @@

    In order to keep the design of treefmt simple, we support only formatters which adhere to a certain standard. This document outlines this standard. If the formatter you would like to use doesn't comply with the rules, it's often possible to create a wrapper script that transforms the usage to match the specification.

    Command-line interface

    In order to be integrated to treefmt's workflow, the formatter's CLI must adhere to the following specification:

    -
    <command> [options] [...<files>]
    -
    +
    <command> [options] [...<files>]
    +

    Where:

    Example:

    -
    $ rustfmt --edition 2018 src/main.rs src/lib.rs
    -
    +
    $ rustfmt --edition 2018 src/main.rs src/lib.rs
    +

    Whenever a formatter is invoked with a list of files, it should processes only the specified files. Files that are not passed should never be formatted.

    If, and only if, a file has changed, the formatter will write the new content in place of the original one.

    Other requirements

    @@ -725,7 +725,7 @@
    - GitHub + numtide/treefmt
    @@ -195,8 +195,8 @@
  • - - About the project + + Home
  • @@ -313,7 +313,7 @@
    - GitHub + numtide/treefmt
    @@ -328,8 +328,8 @@
  • - - About the project + + Home
  • @@ -1357,146 +1357,144 @@

    Cabal

    cabal-fmt

    -
    command = "cabal-fmt"
    -options = ["--inplace"]
    -includes = ["*.cabal"]
    -
    +
    command = "cabal-fmt"
    +options = ["--inplace"]
    +includes = ["*.cabal"]
    +

    Elm

    elm-format

    -
    command = "elm-format"
    -options = ["--yes"]
    -includes = ["*.elm"]
    -
    +
    command = "elm-format"
    +options = ["--yes"]
    +includes = ["*.elm"]
    +

    Golang

    gofmt

    -
    command = "gofmt"
    -options = ["-w"]
    -includes = ["*.go"]
    -
    -
    +
    command = "gofmt"
    +options = ["-w"]
    +includes = ["*.go"]
    +

    gofumpt

    -
    command = "gofumpt"
    -includes = ["*.go"]
    -
    -
    +
    command = "gofumpt"
    +includes = ["*.go"]
    +

    Haskell

    hlint

    -
    command = "hlint"
    -includes = [ "*.hs" ]
    -
    +
    command = "hlint"
    +includes = [ "*.hs" ]
    +

    Ormolu

    Make sure to use ormolu 0.1.4.0+ as older versions don't adhere to the spec.

    -
    command = "ormolu"
    -options = [
    - "--ghc-opt", "-XBangPatterns",
    - "--ghc-opt", "-XPatternSynonyms",
    - "--ghc-opt", "-XTypeApplications",
    - "--mode", "inplace",
    - "--check-idempotence",
    -]
    -includes = ["*.hs"]
    -
    +
    command = "ormolu"
    +options = [
    + "--ghc-opt", "-XBangPatterns",
    + "--ghc-opt", "-XPatternSynonyms",
    + "--ghc-opt", "-XTypeApplications",
    + "--mode", "inplace",
    + "--check-idempotence",
    +]
    +includes = ["*.hs"]
    +

    stylish-haskell

    -
    command = "stylish-haskell"
    -options = [ "--inplace" ]
    -includes = [ "*.hs" ]
    -
    +
    command = "stylish-haskell"
    +options = [ "--inplace" ]
    +includes = [ "*.hs" ]
    +

    Lua

    StyLua

    -
    command = "stylua"
    -includes = ["*.lua"]
    -
    +
    command = "stylua"
    +includes = ["*.lua"]
    +

    Nix

    Alejandra

    -
    command = "alejandra"
    -includes = ["*.nix"]
    -
    +
    command = "alejandra"
    +includes = ["*.nix"]
    +

    nixpkgs-fmt

    -
    command = "nixpkgs-fmt"
    -includes = ["*.nix"]
    -
    +
    command = "nixpkgs-fmt"
    +includes = ["*.nix"]
    +

    OCaml

    ocamlformat

    -
    command = "ocamlformat"
    -options = ["-i"]
    -includes = ["*.ml", "*.mli"]
    -
    +
    command = "ocamlformat"
    +options = ["-i"]
    +includes = ["*.ml", "*.mli"]
    +

    PureScript

    purs-tidy

    -
    command = "purs-tidy"
    -includes = ["*.purs"]
    -
    +
    command = "purs-tidy"
    +includes = ["*.purs"]
    +

    Python

    black

    -
    command = "black"
    -includes = ["*.py"]
    -
    +
    command = "black"
    +includes = ["*.py"]
    +

    Ruby

    rufo

    Rufo is an opinionated ruby formatter. By default it exits with status 3 on file change so you have to pass the -x option.

    -
    command = "rufo"
    -options = ["-x"]
    -includes = ["*.rb"]
    -
    +
    command = "rufo"
    +options = ["-x"]
    +includes = ["*.rb"]
    +

    Rust

    cargo fmt is not supported as it doesn't follow the spec. It doesn't allow to pass arbitrary files to be formatter, an ability which treefmt relies on. Use rustfmt instead (which is what cargo fmt uses under the hood).

    rustfmt

    -
    command = "rustfmt"
    -options = ["--edition", "2018"]
    -includes = ["*.rs"]
    -
    +
    command = "rustfmt"
    +options = ["--edition", "2018"]
    +includes = ["*.rs"]
    +

    Scala

    scalafmt

    -
    command = "scalafmt"
    -includes = ["*.scala"]
    -
    +
    command = "scalafmt"
    +includes = ["*.scala"]
    +

    Shell

    shellcheck

    -
    command = "shellcheck"
    -includes = ["*.sh"]
    -
    +
    command = "shellcheck"
    +includes = ["*.sh"]
    +

    shfmt

    -
    command = "shfmt"
    -options = [
    - "-i",
    - "2",  # indent 2
    - "-s",  # simplify the code
    - "-w",  # write back to the file
    -]
    -includes = ["*.sh"]
    -
    +
    command = "shfmt"
    +options = [
    + "-i",
    + "2",  # indent 2
    + "-s",  # simplify the code
    + "-w",  # write back to the file
    +]
    +includes = ["*.sh"]
    +

    Terraform

    terraform

    Make sure to use terraform 1.3.0 or later versions, as earlier versions format only one file at a time. See the details here.

    -
    command = "terraform"
    -options = ["fmt"]
    -includes = ["*.tf"]
    -
    +
    command = "terraform"
    +options = ["fmt"]
    +includes = ["*.tf"]
    +

    Multi-language formatters

    clang-format

    A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.

    -
    command = "clang-format"
    -options = [ "-i" ]
    -includes = [ "*.c", "*.cpp", "*.cc", "*.h", "*.hpp" ]
    -
    +
    command = "clang-format"
    +options = [ "-i" ]
    +includes = [ "*.c", "*.cpp", "*.cc", "*.h", "*.hpp" ]
    +

    Note: This example focuses on C/C++ but can be modified to be used with other languages.

    Prettier

    An opinionated code formatter that supports many languages.

    -
    command = "prettier"
    -options = ["--write"]
    -includes = [
    - "*.css",
    - "*.html",
    - "*.js",
    - "*.json",
    - "*.jsx",
    - "*.md",
    - "*.mdx",
    - "*.scss",
    - "*.ts",
    - "*.yaml",
    -]
    -
    +
    command = "prettier"
    +options = ["--write"]
    +includes = [
    + "*.css",
    + "*.html",
    + "*.js",
    + "*.json",
    + "*.jsx",
    + "*.md",
    + "*.mdx",
    + "*.scss",
    + "*.ts",
    + "*.yaml",
    +]
    +
    @@ -1557,7 +1555,7 @@ includes = [
    - GitHub + numtide/treefmt
    @@ -195,8 +195,8 @@
  • - - About the project + + Home
  • @@ -313,7 +313,7 @@
    - GitHub + numtide/treefmt
    @@ -328,8 +328,8 @@
  • - - About the project + + Home
  • @@ -647,7 +647,7 @@
    - GitHub + numtide/treefmt
    @@ -192,11 +192,13 @@ + +
  • - - About the project + + Home
  • @@ -311,7 +313,7 @@
    - GitHub + numtide/treefmt
    @@ -324,11 +326,66 @@ + -
  • - - About the project + +
  • + + + + + + + + + + + Home + + + + +
  • @@ -597,38 +654,38 @@

    About the project

    -

    Treefmt is a formatting tool that saves you time: it provides developers with a universal way to trigger all formatters needed for the project in one place.

    +

    treefmt is a formatting tool that saves you time: it provides developers with a universal way to trigger all formatters needed for the project in one place.

    Background

    Typically, each project has its own code standards enforced by the project's owner. Any code contributions must match that given standard, i.e. be formatted in a specific manner.

    At first glance, the task of code formatting may seem trivial: the formatter can be automatically triggered when you save a file in your IDE. Indeed, formatting doesn't take much effort if you're working on a single project long term: setting up the formatters in your IDE won't take much of your time, and then you're ready to go.

    Contrary to that, if you're working on multiple projects at the same time, you may have to update your formatter configs in the IDE each time you switch between the projects. This is because formatter settings aren't project-specific --- they are set up globally for all projects.

    Alternatively, you can trigger formatters manually, one-by-one or in a script. Actually, for bigger projects, it's common to have a script that runs over your project's directories and calls formatters consequently. But it takes time to iterate through all the files.

    All the solutions take up a significant amount of time which a developer could spend doing the actual work. They also require you to remember which formatters and options are used by each project you are working on.

    -

    Treefmt solves these issues.

    +

    treefmt solves these issues.

    Why treefmt?

    -

    Treefmt's configuration is project-specific, so you don't need to re-configure formatters each time you switch between projects, like you have to when working with formatters in the IDE.

    +

    treefmt's configuration is project-specific, so you don't need to re-configure formatters each time you switch between projects, like you have to when working with formatters in the IDE.

    Contrary to calling formatters from the command line, there's no need to remember all the specific formatters required for each project. Once you set up the config, you can run the tool in any of your project's folders without any additional flags or options.

    Typically, formatters have different ways to say there was a specific error. With treefmt, you get a standardized output which is easier to understand than the variegated outputs of different formatters, so it takes less time to grasp what's wrong.

    In addition, treefmt works faster than the custom script solution because the changed files are cached and the formatters run only against them. Moreover, formatters are run in parallel, which makes the tool even faster.

    The difference may not be significant for smaller projects, but it gets quite visible as the project grows. For instance, take the caching optimization. It takes 9 seconds to traverse a project of 1507 files and no changes without caching:

    -
    traversed 1507 files
    -matched 828 files to formatters
    -left with 828 files after cache
    -of whom 0 files were re-formatted
    -all of this in 9s
    -
    +
    traversed 1507 files
    +matched 828 files to formatters
    +left with 828 files after cache
    +of whom 0 files were re-formatted
    +all of this in 9s
    +

    ...while it takes 124 milliseconds to traverse the same project with caching:

    -
    traversed 1507 files
    -matched 828 files to formatters
    -left with 0 files after cache
    -of whom 0 files were re-formatted
    -all of this in 124ms
    -
    +
    traversed 1507 files
    +matched 828 files to formatters
    +left with 0 files after cache
    +of whom 0 files were re-formatted
    +all of this in 124ms
    +

    The tool can be invoked manually or integrated into your CI. There's currently no integration with IDEs, but the feature is coming soon.

    Upcoming features

    As a next step, learn how to install and use treefmt.

    @@ -651,12 +708,33 @@ all of this in 124ms