From e347d5abeb044d83c183cc83c876cf7ff2f6318c Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Fri, 23 Feb 2024 12:27:42 +0000 Subject: [PATCH] wip: started moving docs Signed-off-by: Brian McGee --- LICENSE.md | 2 +- README.md | 30 +-- default.nix | 15 ++ docs/assets/logo.png | Bin 0 -> 11131 bytes docs/assets/logo.svg | 384 +++++++++++++++++----------------- docs/book.toml | 9 + docs/contributing.md | 141 +++++++++++++ docs/faq.md | 19 ++ docs/formatters-spec.md | 51 +++++ docs/formatters.md | 273 ++++++++++++++++++++++++ docs/index-formatters.md | 6 + docs/index.md | 60 ++++++ docs/installation.md | 61 ++++++ docs/integrations.md | 9 + docs/quickstart.md | 14 ++ docs/treefmt-configuration.md | 43 ++++ docs/usage.md | 115 ++++++++++ flake.lock | 37 ++++ flake.nix | 6 +- mkdocs.yml | 27 +++ nix/devshell.nix | 5 +- nix/packages.nix | 6 + shell.nix | 15 ++ 23 files changed, 1118 insertions(+), 210 deletions(-) create mode 100644 default.nix create mode 100644 docs/assets/logo.png create mode 100644 docs/book.toml create mode 100644 docs/contributing.md create mode 100644 docs/faq.md create mode 100644 docs/formatters-spec.md create mode 100644 docs/formatters.md create mode 100644 docs/index-formatters.md create mode 100644 docs/index.md create mode 100644 docs/installation.md create mode 100644 docs/integrations.md create mode 100644 docs/quickstart.md create mode 100644 docs/treefmt-configuration.md create mode 100644 docs/usage.md create mode 100644 mkdocs.yml create mode 100644 shell.nix diff --git a/LICENSE.md b/LICENSE.md index d8ade38..f778e49 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Treefmt Contributors +Copyright (c) 2024 NumTide Sarl and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 237342f..95abf06 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Formatting requires less effort if a universal formatter for multiple languages Its main features are: -- Providing a unified CLI and output: You don’t need to remember which formatters are required for each project. Once you specify the formatters in the config file, you can trigger all of them with one command and get a standardized output. -- Running all the formatters in parallel: A standard script loops over your folders and runs each formatter consequentially. In contrast, `treefmt` runs formatters in parallel. This way, the formatting job takes less time. -- Caching the changed files: When formatters are run in a script, they process all the files they encounter, no matter whether the code has changed. This unnecessary work can be eliminated if only the changed files are formatted. `treefmt` caches the changed files and marks them for re-formatting. +- Providing a unified CLI and output: You don’t need to remember which formatters are required for each project. Once you specify the formatters in the config file, you can trigger all of them with one command and get a standardized output. +- Running all the formatters in parallel: A standard script loops over your folders and runs each formatter consequentially. In contrast, `treefmt` runs formatters in parallel. This way, the formatting job takes less time. +- Caching the changed files: When formatters are run in a script, they process all the files they encounter, no matter whether the code has changed. This unnecessary work can be eliminated if only the changed files are formatted. `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. @@ -93,9 +93,9 @@ If you are a Nix user, you might also be interested in [treefmt-nix](https://git `Treefmt` works with any formatter that adheres to the [following specification](https://github.com/numtide/treefmt/blob/main/docs/formatters-spec.md). For instance, you can go for: -- [clang-format](https://clang.llvm.org/docs/ClangFormat.html) for Java -- gofmt for Golang -- Prettier for JavaScript/HTML/CSS +- [clang-format](https://clang.llvm.org/docs/ClangFormat.html) for Java +- gofmt for Golang +- Prettier for JavaScript/HTML/CSS Find the full list of supported formatters [here](https://numtide.github.io/treefmt/formatters). @@ -103,18 +103,18 @@ Find the full list of supported formatters [here](https://numtide.github.io/tree This project is still pretty new. Down the line we also want to add support for: -- IDE integration -- Pre-commit hooks -- Effective support of multiple formatters +- IDE integration +- Pre-commit hooks +- Effective support of multiple formatters ## Related projects -- [EditorConfig](https://editorconfig.org/): unifies file indentations - configuration on a per-project basis. -- [prettier](https://prettier.io/): an opinionated code formatter for a number of languages. -- [Super-Linter](https://github.com/github/super-linter): a project by GitHub to lint all of your code. -- [pre-commit](https://pre-commit.com/): a framework for managing and - maintaining multi-language pre-commit hooks. +- [EditorConfig](https://editorconfig.org/): unifies file indentations + configuration on a per-project basis. +- [prettier](https://prettier.io/): an opinionated code formatter for a number of languages. +- [Super-Linter](https://github.com/github/super-linter): a project by GitHub to lint all of your code. +- [pre-commit](https://pre-commit.com/): a framework for managing and + maintaining multi-language pre-commit hooks. ## Contributing diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..9813375 --- /dev/null +++ b/default.nix @@ -0,0 +1,15 @@ +# This file provides backward compatibility to nix < 2.4 clients +{ system ? builtins.currentSystem }: +let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + + inherit (lock.nodes.flake-compat.locked) owner repo rev narHash; + + flake-compat = fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + sha256 = narHash; + }; + + flake = import flake-compat { inherit system; src = ./.; }; +in +flake.defaultNix \ No newline at end of file diff --git a/docs/assets/logo.png b/docs/assets/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..1324d7368ca9de6cc5dcd89beaea15e2fcf05384 GIT binary patch literal 11131 zcmXY%cQ~BQ*T?T&YpuR|XLTV&3!<(b5+!;>Cx}iE-RdN2gecLXMDM+BM6~FF=tM;C zy}z5^`~0!jz1QB??3_7s=FH6bexfwhl?m}^@c;lIRC%nR1ppw-R}cV$Vjf0rh1Qq{ zuFK=+uK_^4?cWFV+Rm07^COMBqJg`%v$gvhbGMhkn>TOxUOCynwlsHn$>;25lfElS z3jhc}ML|}_>(fq#cdM~((psQ>mc-(fi3wCtmh^o*gtQj|D=gD8JSlQJ*YQ_XY*A%? zAXXd3MT4lCI5Y}H zteQWSb32o|ntL5_a&whg_r_%CHluFJ#FrNdhseT1PeXz;QJR5H#x1U@*w?afHTJ(I z94GXoO^fBNyYm;>YaBnRNKhi?8)PrSlYd+$n%$CO)o9#dQvkO#LNcw@zC#@$ky|oP zauy^T?8MVFY=lf<%&&TXpva+|{WT;d7yV+Fu4K7DVIhVV^+ z47S=6*~YGrBGQoCKG%(fms#m2@9S{!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Ijq(pZevpWC!_BqSdR}2V;yl>dDYY{UN$hp7R89@vA zB4-40r7`@zbXS7LiTugH;Ojeed~7u9Bbt#$PJ)739k8Z9n25dg1+tJwcT8=#Bbdb! zpdWio8)qHZWSI8gkugn&J`cvmAe1P@I7crgA%6yR)`WTEH;BpVdKVVyoP7Z19j5n+tc~VP4wmKx zPkeW{C&`Mhcxs^6s>j~Yi#lEiCb00`wr19pTVQvhfGF0!q3_ih(C&+9I{KpJTX6yh z*_u1~9zz$k92}qcBKX? zZbj|8NYmXi5ibbm&if|UVY2{^O2ac>EMGBR2EYU3X~rW*O1=&YuABbD-{_97|KX?N b2X`RZzlz7nG7Nt);4Gk`sIE{hXBPZ_+HI~+ literal 0 HcmV?d00001 diff --git a/docs/assets/logo.svg b/docs/assets/logo.svg index 076ed55..bdd34b3 100644 --- a/docs/assets/logo.svg +++ b/docs/assets/logo.svg @@ -1,194 +1,194 @@ - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - \ No newline at end of file + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + inkscape:export-ydpi="512" + inkscape:export-xdpi="512" + inkscape:export-filename="/home/basile/dev/treefmt.png" + sodipodi:docname="treefmt.svg" + inkscape:version="1.0 (4035a4fb49, 2020-05-01)" + id="svg16" + version="1.1" + viewBox="0 0 12.7 12.7" + height="48" + width="48"> + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/docs/book.toml b/docs/book.toml new file mode 100644 index 0000000..2c936a0 --- /dev/null +++ b/docs/book.toml @@ -0,0 +1,9 @@ +[book] +authors = [ + "Andika Demas Riyandi ", + "Jonas Chevalier ", +] +language = "en" +multilingual = false +src = "." +title = "treefmt — one CLI to format your repo" diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 0000000..7ee554f --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,141 @@ +# Contribution guidelines + +This file contains instructions that will help you make a contribution. + +## Licensing + +The treefmt binaries and this user guide are licensed under the [MIT license](https://numtide.github.io/treefmt/LICENSE.html). + +## Before you contribute + +Here you can take a look at the [existing issues](https://github.com/numtide/treefmt/issues). Feel free to contribute, but make sure you have a [GitHub account](https://github.com/join) first :) . + +If you're new to open source, please read GitHub's guide on [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/). It's a quick read, and it's a great way to introduce yourself to how things work behind the scenes in open-source projects. + +Before sending a pull request, make sure that you've read all the guidelines. If you don't understand something, please [state your question clearly in an issue](https://github.com/numtide/treefmt/issues/new) or ask the community on the [treefmt matrix server](https://matrix.to/#/#treefmt:numtide.com). + +## Creating an issue + +If you need to create an issue, make sure to clearly describe it, including: + +- The steps to reproduce it if it's a bug +- The version of treefmt used +- The database driver and version +- The database version + +The cache database is stored in a toml file the ~/.cache/treefmt directory. + +## Making changes + +If you want to introduce changes to the project, please follow these steps: + +- Fork the repository on GitHub +- Create a branch on your fork. Don't commit directly to main +- Add the necessary tests for your changes +- Run treefmt in the source directory before you commit your changes +- Push your changes to the branch in your repository fork +- Submit a pull request to the original repository + +Make sure you based your commits on logical and atomic units! + +## Examples of git history + +Git history that we want to have: + +Git history that we are trying to avoid: + +
+ +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 + +``` + +
+ +
+ +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 + +``` + +
+ +Additionally, it's always good to work on improving documentation and adding examples. + +Thank you for considering contributing to `treefmt`. diff --git a/docs/faq.md b/docs/faq.md new file mode 100644 index 0000000..927d995 --- /dev/null +++ b/docs/faq.md @@ -0,0 +1,19 @@ +# FAQ + +## How does treefmt function? + +`Treefmt` traverses all your project's folders, maps files to specific code formatters, and formats the code accordingly. Other tools also traverse the filesystem, but not necessarily starting from the root of the project. + +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/.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. diff --git a/docs/formatters-spec.md b/docs/formatters-spec.md new file mode 100644 index 0000000..afe3edb --- /dev/null +++ b/docs/formatters-spec.md @@ -0,0 +1,51 @@ +# Formatter specification + +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. + +In this design, we rely on `treefmt` to do the tree traversal, and only invoke +the code formatter on the selected files. + +## Rules + +In order for the formatter to comply to this spec, it MUST follow the +following rules: + +### 1. Files passed as arguments + +In order to be integrated to `treefmt`'s workflow, the formatter's CLI must adhere to the following specification: + +``` + [options] [...] +``` + +Where: + +- `` is the name of the formatting tool. +- `[options]` is any number of flags and options that the formatter accepts. +- `[...]` is one or more files given to the formatter for processing. + +Example: + +``` +$ rustfmt --edition 2018 src/main.rs src/lib.rs +``` + +It SHOULD processes only the specified files. Files that are not passed SHOULD never be formatted. + +### 2. Write to changed files + +Whenever there is a change to the code formatting, the code formatter MUST +write to the changes back to the original location. + +If there is no changes to the original file, the formatter MUST NOT write to +the original location. + +### 3. Idempotent + +The code formatter SHOULD be indempotent. Meaning that it produces stable +outputs. + +### 4. Reliable + +We expect the formatter to be reliable and not break the semantic of the +formatted files. diff --git a/docs/formatters.md b/docs/formatters.md new file mode 100644 index 0000000..7cc3f3f --- /dev/null +++ b/docs/formatters.md @@ -0,0 +1,273 @@ +# Known formatters + +Here is a list of all the formatters we tested. Feel free to send a PR to add other ones! + +## Contents + +Single-language formatters: + +- [Cabal](#cabal) + - [cabal-fmt](#cabal-fmt) +- [Elm](#elm) + - [elm-format](#elm-format) +- [Golang](#golang) + - [gofmt](#gofmt) + - [gofumpt](#gofumpt) +- [Haskell](#haskell) + - [hlint](#hlint) + - [ormolu](#ormolu) + - [stylish-haskell](#stylish-haskell) +- [Lua](#lua) + - [StyLua](#stylua) +- [Nix](#nix) + - [alejandra](#alejandra) + - [nixpkgs-fmt](#nixpkgs-fmt) +- [OCaml](#ocaml) + - [ocamlformat](#ocamlformat) +- [PureScript](#purescript) + - [purs-tidy](#purs-tidy) +- [Python](#python) + - [black](#black) +- [Ruby](#ruby) + - [rufo](#rufo) +- [Rust](#rust) + - [rustfmt](#rustfmt) +- [Scala](#scala) + - [scalafmt](#scalafmt) +- [Shell](#shell) + - [shellcheck](#shellcheck) + - [shfmt](#shfmt) +- [Terraform](#terraform) + - [terraform fmt](#terraform-fmt) + +Multilanguage formatters: + +- [clang-format](#clang-format) +- [Prettier](#prettier) + +## Cabal + +### [cabal-fmt](https://github.com/phadej/cabal-fmt) + +``` +command = "cabal-fmt" +options = ["--inplace"] +includes = ["*.cabal"] +``` + +## Elm + +### [elm-format](https://numtide.github.io/treefmt/formatters.html#elm) + +``` +command = "elm-format" +options = ["--yes"] +includes = ["*.elm"] +``` + +## Golang + +### [gofmt](https://pkg.go.dev/cmd/gofmt) + +``` +command = "gofmt" +options = ["-w"] +includes = ["*.go"] + +``` + +### [gofumpt](https://github.com/mvdan/gofumpt) + +``` +command = "gofumpt" +includes = ["*.go"] + +``` + +## Haskell + +### [hlint](https://github.com/ndmitchell/hlint) + +``` +command = "hlint" +includes = [ "*.hs" ] +``` + +### [Ormolu](https://github.com/tweag/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"] +``` + +### [stylish-haskell](https://github.com/jaspervdj/stylish-haskell) + +``` +command = "stylish-haskell" +options = [ "--inplace" ] +includes = [ "*.hs" ] +``` + +## Lua + +### [StyLua](https://github.com/JohnnyMorganz/StyLua) + +``` +command = "stylua" +includes = ["*.lua"] +``` + +## Nix + +### [Alejandra](https://github.com/kamadorueda/alejandra) + +``` +command = "alejandra" +includes = ["*.nix"] +``` + +### [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) + +``` +command = "nixpkgs-fmt" +includes = ["*.nix"] +``` + +## OCaml + +### [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) + +``` +command = "ocamlformat" +options = ["-i"] +includes = ["*.ml", "*.mli"] +``` + +## PureScript + +### [purs-tidy](https://www.npmjs.com/package/purs-tidy) + +``` +command = "purs-tidy" +includes = ["*.purs"] +``` + +## Python + +### [black](https://github.com/psf/black) + +``` +command = "black" +includes = ["*.py"] +``` + +## Ruby + +### [rufo](https://github.com/ruby-formatter/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"] +``` + +## 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](https://github.com/rust-lang/rustfmt) + +``` +command = "rustfmt" +options = ["--edition", "2018"] +includes = ["*.rs"] +``` + +## Scala + +### [scalafmt](https://github.com/scalameta/scalafmt) + +``` +command = "scalafmt" +includes = ["*.scala"] +``` + +## Shell + +### [shellcheck](https://github.com/koalaman/shellcheck) + +``` +command = "shellcheck" +includes = ["*.sh"] +``` + +### [shfmt](https://github.com/mvdan/sh) + +``` +command = "shfmt" +options = [ + "-i", + "2", # indent 2 + "-s", # simplify the code + "-w", # write back to the file +] +includes = ["*.sh"] +``` + +## Terraform + +### [terraform](https://numtide.github.io/treefmt/formatters.html#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](https://github.com/hashicorp/terraform/pull/28191). + +``` +command = "terraform" +options = ["fmt"] +includes = ["*.tf"] +``` + +## Multi-language formatters + +### [clang-format](https://clang.llvm.org/docs/ClangFormat.html) + +A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code. + +``` +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](https://prettier.io/) + +An opinionated code formatter that supports many languages. + +``` +command = "prettier" +options = ["--write"] +includes = [ + "*.css", + "*.html", + "*.js", + "*.json", + "*.jsx", + "*.md", + "*.mdx", + "*.scss", + "*.ts", + "*.yaml", +] +``` diff --git a/docs/index-formatters.md b/docs/index-formatters.md new file mode 100644 index 0000000..beb7af8 --- /dev/null +++ b/docs/index-formatters.md @@ -0,0 +1,6 @@ +# Formatters + +In order to catch up with all the formatters available for different programming languages, we created two files as our guideline: + +1. [Formatter Specifications](./formatters-spec.md) — Guidelines for formatter creators to have a smooth integration with `treefmt` +1. [Formatter Example](./formatters.md) — List of the available formatters with the corresponding configs that can be inserted into `treefmt.toml` diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..27e1724 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,60 @@ +# 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. + +## 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. + +## 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. + +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 +``` + +...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 +``` + +The tool can be invoked manually or integrated into your CI. There's currently no integration with IDEs, but the feature is coming soon. + +## What we still need help with + +- **IDE integration:** Most of developers are used to formatting a file upon save in the IDE. So far, you can't use `treefmt` for this purpose, but we're working on it 😀 +- **Pre-commit hook:** It's good to have your code checked for adherence to the project's standards before commit. `treefmt` pre-commit hook won't let you commit if you have formatting issues. +- **Support of multiple formatters for one language:** In the current version, we advise you to avoid using multiple formatters for one and the same file type. This is because formatters are run in parallel and therefore may encounter issues while processing files. We are going to fix this issue soon, since there are cases when you may need more than one formatter per language. + +As a next step, learn how to [install] and [use] `treefmt`. + +[install]: installation.md +[use]: usage.md diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 0000000..467faed --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,61 @@ +# Installation + +There are two options to install `treefmt`: by downloading the latest binary, or by compiling and building the tool from source. + +## Installing with a binary file + +You can find the list of the latest binaries [here](https://github.com/numtide/treefmt/releases). + +## Building from source + +There are several ways to build `treefmt` from source. Your choice will depend on whether you're a [nix](https://github.com/NixOS/nix) user. + +### Non-Nix User + +To try the project without building it, run: + +``` +$ cargo run -- --help +``` + +The command will output the manual. You can run the tool in this manner with any other flag or option to format your project. + +To build a binary, you need to have rust installed. You can install it with [rustup](https://rustup.rs/). Now, if you want to build the project, switch to the project root folder and run: + +``` +$ cargo build +``` + +After the successful execution of the cargo build command, you will find the `treefmt` binary in the target folder. + +### Nix User + +[Nix](https://github.com/NixOS/nix) is a package manager foundational for NixOS. You can use it in NixOS and in any other OS equally. + +If you're using both `treefmt` and `nix`, you can go for [`treefmt-nix`](https://github.com/numtide/treefmt-nix), a special tool that makes installation and configuration of `treefmt` with `nix` easier. + +**Non-flake user** + +Here you also have two options: you can install `treefmt` with plain nix-build , or with nix-shell. + +To build the package with nix-build, just run: + +``` +$ nix-build -A treefmt +``` + +**Nix-flake user** + +If you want to use this repository with flakes, please enable the flakes feature first. To run the project with flakes without building it, you can execute the following command in the root folder: + +``` +$ nix run . -- --help +``` + +To build the project, run the following command in the root folder: + +``` +$ nix build +``` + +The `treefmt` binary will be available in the result folder. diff --git a/docs/integrations.md b/docs/integrations.md new file mode 100644 index 0000000..eef05e4 --- /dev/null +++ b/docs/integrations.md @@ -0,0 +1,9 @@ +# Integrations + +> add your project here. + +Here is a list of projects that integrate with treefmt. + +## the vim null-ls plugin + +See for usage. diff --git a/docs/quickstart.md b/docs/quickstart.md new file mode 100644 index 0000000..87a41f9 --- /dev/null +++ b/docs/quickstart.md @@ -0,0 +1,14 @@ +# Quickstart + +To run `treefmt` in your project, please follow these steps: + +1. [Install] the tool. +2. Install the needed formatters. +3. Run `treefmt --init`. This will generate the basic configuration file `treefmt.toml` containing the formatting rules. +4. Edit the configuration (see [here] how). +5. Run `treefmt` with the needed flags and options. You can check the supported options by executing `treefmt --help`. + +In the following sections we will guide you through installing and configuring `treefmt` in detail. + +[install]: installation.md +[here]: formatters-spec.md diff --git a/docs/treefmt-configuration.md b/docs/treefmt-configuration.md new file mode 100644 index 0000000..7d45a1c --- /dev/null +++ b/docs/treefmt-configuration.md @@ -0,0 +1,43 @@ +# Configuration + +`treefmt` can only be run in the presence of `treefmt.toml` where files are mapped to specific code formatters. + +Usually the config file sits in the project root folder. If you're running `treefmt` in one of the project's folders, then `treefmt` will look for the config in the parent folders up until the project's root. However, you can place the config anywhere in your project's file tree and specify the path in the ---config-file flag. + +The typical section of `treefmt.toml` looks like this: + +``` +[formatter.] +command = "" +options = [""...] +includes = [""...] +``` + +...where name is just an identifier. + +``` +[formatter.elm] +command = "elm-format" +options = ["--yes"] +includes = ["*.elm"] +``` + +Make sure you installed all the formatters specified in the config before running `treefmt`. If you don't want to install all formatters, you can still run `treefmt` by specifying the flag `--allow-missing-formatter`. This will make the program not error out if the needed formatter is missing. + +## Configuration format + +### `[formatter.]` + +This section describes the integration between a single formatter and treefmt. "Name" here is a unique ID of your formatter in the config file. It doesn't have to match the formatter name. + +- `command`: A list of arguments to be executed. This will be concatenated with the options attribute during invocation. The first argument is the name of the executable to run. +- `options`: A list of extra arguments to add to the command. These are typically project-specific arguments. +- `includes`: A list of glob patterns to match file names, including extensions and paths, used to select specific files for formatting. Typically, only file extensions are specified to pick all files written in a specific language. For instance,[`"*.sh"`] selects shell script files. But sometimes, you may need to specify a full file name, like [`"Makefile"`], or a pattern picking files in a specific folder, like [`"/home/user/project/*"`]. + +- `excludes`: A list of glob patterns to exclude from formatting. If any of these patterns match, the file will be excluded from formatting by a particular formatter. + +### `[global]` + +This section describes the configuration properties that apply to every formatter. + +- `excludes`: A list of glob patterns to deny. If any of these patterns match, the file won't be formatted. This list is appended to the individual formatter's excludes lists. diff --git a/docs/usage.md b/docs/usage.md new file mode 100644 index 0000000..6590d8a --- /dev/null +++ b/docs/usage.md @@ -0,0 +1,115 @@ +# Usage + +You can run treefmt by executing: + +`$ treefmt` + +or, if it's not in your `$PATH`: + +`$ ./treefmt` + +Treefmt has the following specification: + +``` +treefmt [FLAGS] [OPTIONS] [--] [paths]... +``` + +## Flags + +`--allow-missing-formatter` + +> Do not exit with an error if some of the configured formatters are missing. + +`--clear-cache` + +> Reset the evaluation cache. Invalidation should happen automatically if the formatting tool has been updated, or if the files to format have changed. If cache wasn't properly invalidated, you can use this flag to clear the cache. + +`--fail-on-change` + +> Exit with error if some files require re-formatting. This is useful for your CI if you want to detect if the contributed code was forgotten to be formatted. + +`-h, --help` + +> Prints available flags and options + +`--init` + +> Creates a new config file `treefmt.toml`. + +`--no-cache` + +> Tells `treefmt` to ignore the evaluation cache entirely. With this flag, you can avoid cache invalidation issues, if any. Typically, the machine that is running treefmt in the CI is starting with a fresh environment each time, so any calculated cache is lost. The `--no-cache` flag eliminates unnecessary work in the CI. + +`-q, --quiet` + +> Don't print output to stderr. + +`--stdin` + +> Format the content passed in stdin. + +`-V, --version` + +> Print version information. + +`-v, --verbose` + +> Change the log verbosity. Log verbosity is based off the number of 'v' used. With one `-v`, your logs will display `[INFO]` and `[ERROR]` messages, while `-vv` will also show `[DEBUG]` messages. + +`--config-file ` + +> Run with the specified config file which is not in the project tree. + +`-f, --formatters ...` + +> Only apply selected formatters. Defaults to all formatters. + +`-H, --hidden` + +> Also traverse hidden files (files that start with a .). This behaviour can be overridden with the `--no-hidden` flag. + +`--no-hidden` + +> Override the `--hidden` flag. Don't traverse hidden files. + +`--tree-root ` + +> Set the path to the tree root directory where treefmt will look for the files to format. Defaults to the folder holding the `treefmt.toml` file. It’s mostly useful in combination with `--config-file` to specify the project root which won’t coincide with the directory holding `treefmt.toml`. + +`-C ` + +> Run as if `treefmt` was started in `` instead of the current working directory (default: `.`). Equivalent to `cd ; treefmt`. + +## Arguments + +`...` + +> Paths to format. Defaults to formatting the whole tree + +## CI integration + +Typically, you would use treefmt in the CI with the `--fail-on-change` and `--no-cache flags`. Find the explanations above. + +You can you set a `treefmt` job in the GitHub pipeline for Ubuntu with nix-shell like this: + +``` +name: treefmt +on: + pull_request: + push: + branches: main +jobs: + formatter: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: cachix/cachix-action@v10 + with: + name: nix-community + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - name: treefmt + run: nix-shell --run "treefmt --fail-on-change --no-cache" +``` diff --git a/flake.lock b/flake.lock index 70c5801..0a04f79 100644 --- a/flake.lock +++ b/flake.lock @@ -21,6 +21,21 @@ "type": "github" } }, + "flake-compat": { + "locked": { + "lastModified": 1688025799, + "narHash": "sha256-ktpB4dRtnksm9F5WawoIkEneh1nrEvuxb5lJFt1iOyw=", + "owner": "nix-community", + "repo": "flake-compat", + "rev": "8bf105319d44f6b9f0d764efa4fdef9f1cc9ba1c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -111,6 +126,26 @@ "type": "github" } }, + "mkdocs-numtide": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1687786869, + "narHash": "sha256-KhaNnOTjj9FgPLtRHTFGa1RFXvSc+nF1UPcBiYf/CCY=", + "owner": "numtide", + "repo": "mkdocs-numtide", + "rev": "b3008171c75083f2bf2f1dc4e6781d4737dfaa49", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "mkdocs-numtide", + "type": "github" + } + }, "nix-filter": { "locked": { "lastModified": 1705332318, @@ -163,9 +198,11 @@ "root": { "inputs": { "devshell": "devshell", + "flake-compat": "flake-compat", "flake-parts": "flake-parts", "flake-root": "flake-root", "gomod2nix": "gomod2nix", + "mkdocs-numtide": "mkdocs-numtide", "nix-filter": "nix-filter", "nixpkgs": "nixpkgs", "treefmt-nix": "treefmt-nix" diff --git a/flake.nix b/flake.nix index 3fc06af..e3c27a7 100644 --- a/flake.nix +++ b/flake.nix @@ -18,8 +18,12 @@ url = "github:nix-community/gomod2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; - nix-filter.url = "github:numtide/nix-filter"; + mkdocs-numtide = { + url = "github:numtide/mkdocs-numtide"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-compat.url = "github:nix-community/flake-compat"; }; outputs = inputs @ {flake-parts, ...}: diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..665952d --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,27 @@ +INHERIT: !ENV MKDOCS_NUMTIDE_THEME + +### Site metadata ### + +site_name: treefmt +site_description: one CLI to format your repo +site_url: https://numtide.github.io/treefmt/ +repo_name: "numtide/treefmt" +repo_url: https://git.numtide.com/numtide/treefmt +edit_uri: edit/main/docs + +### Navigation ### + +nav: + - Home: index.md + - QuickStart: + - About: quickstart.md + - Installation: installation.md + - Configuration: treefmt-configuration.md + - Usage: usage.md + - Integrations: integrations.md + - Formatters: + - About: index-formatters.md + - Formatter Specification: formatters-spec.md + - Known Formatters: formatters.md + - FAQ: faq.md + - Contributing: contributing.md diff --git a/nix/devshell.nix b/nix/devshell.nix index 864a992..aa29ffc 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -6,6 +6,7 @@ config.perSystem = { pkgs, config, + inputs', ... }: { config.devshells.default = { @@ -25,7 +26,9 @@ # golang go delve - graphviz + + # docs + inputs'.mkdocs-numtide.packages.default ] ++ # include formatters for development and testing diff --git a/nix/packages.nix b/nix/packages.nix index 2a7d2e1..ae9d3b9 100644 --- a/nix/packages.nix +++ b/nix/packages.nix @@ -8,9 +8,15 @@ inputs', lib, pkgs, + system, ... }: { packages = rec { + docs = inputs.mkdocs-numtide.lib.${system}.mkDocs { + name = "treefmt-docs"; + src = ../.; + }; + treefmt = inputs'.gomod2nix.legacyPackages.buildGoApplication rec { pname = "treefmt"; version = "2.0.0+dev"; diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..c326229 --- /dev/null +++ b/shell.nix @@ -0,0 +1,15 @@ +# This file provides backward compatibility to nix < 2.4 clients +{ system ? builtins.currentSystem }: +let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + + inherit (lock.nodes.flake-compat.locked) owner repo rev narHash; + + flake-compat = fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + sha256 = narHash; + }; + + flake = import flake-compat { inherit system; src = ./.; }; +in +flake.shellNix \ No newline at end of file