Skip to content

Commit ed2960d

Browse files
authored
Merge branch 'main' into find-tree-root
2 parents 7f4697f + 3f44ec4 commit ed2960d

File tree

3 files changed

+17
-139
lines changed

3 files changed

+17
-139
lines changed

docs/.vitepress/config.mts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export default defineConfig({
2222
],
2323

2424
sidebar: [
25+
{ text: 'Motivation', link: '/about' },
2526
{ text: 'Quick Start', link: '/quick-start' },
2627
{ text: 'Install Treefmt', link: '/install' },
2728
{ text: 'Configure Treefmt', link: '/configure' },
2829
{ text: 'Run Treefmt', link: '/usage' },
29-
{ text: 'Motivation', link: '/about' },
3030
{ text: 'Formatter Spec', link: '/formatter-spec' },
3131
{ text: 'Contributing', link: '/contributing' },
3232
{ text: 'FAQ', link: '/faq' },

docs/configure.md

+15-136
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ priority = 1
4141

4242
## Global Options
4343

44-
- `excludes` - an optional list of glob patters used to exclude certain files from all formatters.
44+
- `excludes` - an optional list of [glob patterns](#glob-patterns-format) used to exclude certain files from all formatters.
4545

4646
## Formatter Options
4747

4848
- `command` - the command to invoke when applying the formatter.
4949
- `options` - an optional list of args to be passed to `command`.
50-
- `includes` - a list of glob patterns used to determine whether the formatter should be applied against a given path.
51-
- `excludes` - an optional list of glob patterns used to exclude certain files from this formatter.
50+
- `includes` - a list of [glob patterns](#glob-patterns-format) used to determine whether the formatter should be applied against a given path.
51+
- `excludes` - an optional list of [glob patterns](#glob-patterns-format) used to exclude certain files from this formatter.
5252
- `priority` - influences the order of execution. Greater precedence is given to lower numbers, with the default being `0`.
5353

5454
## Same file, multiple formatters?
@@ -65,145 +65,24 @@ Another consequence is that formatting is deterministic for a given file and a g
6565
By setting the priority fields appropriately, you can control the order in which those formatters are applied for any
6666
files they _both happen to match on_.
6767

68-
## Supported Formatters
69-
70-
Here is a list of all the formatters we tested. Feel free to send a PR to add other ones!
71-
72-
### [prettier](https://prettier.io/)
73-
74-
An opinionated code formatter that supports many languages.
75-
76-
```toml
77-
command = "prettier"
78-
options = ["--write"]
79-
includes = [
80-
"*.css",
81-
"*.html",
82-
"*.js",
83-
"*.json",
84-
"*.jsx",
85-
"*.md",
86-
"*.mdx",
87-
"*.scss",
88-
"*.ts",
89-
"*.yaml",
90-
]
91-
```
92-
93-
### [Black](https://github.com/psf/black)
68+
## Glob patterns format
9469

95-
A python formatter.
70+
This is a variant of the Unix glob pattern. It supports all the usual
71+
selectors such as `*` and `?`.
9672

97-
```toml
98-
command = "black"
99-
includes = ["*.py"]
100-
```
73+
### Examples
10174

102-
### [clang-format](https://clang.llvm.org/docs/ClangFormat.html)
103-
104-
A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.
105-
106-
```toml
107-
command = "clang-format"
108-
options = [ "-i" ]
109-
includes = [ "*.c", "*.cpp", "*.cc", "*.h", "*.hpp" ]
110-
```
111-
112-
Note: This example focuses on C/C++ but can be modified to use with other languages.
113-
114-
### Elm
115-
116-
```toml
117-
command = "elm-format"
118-
options = ["--yes"]
119-
includes = ["*.elm"]
120-
```
121-
122-
### Go
123-
124-
```toml
125-
command = "gofmt"
126-
options = ["-w"]
127-
includes = ["*.go"]
128-
```
75+
- `*.go` - match all files in the project that end with a ".go" file extension.
76+
- `vendor/*` - match all files under the vendor folder, recursively.
12977

130-
### [Ormolu](https://github.com/tweag/ormolu)
131-
132-
Haskell formatter. Make sure to use ormolu 0.1.4.0+ as older versions don't
133-
adhere to the spec.
134-
135-
```toml
136-
command = "ormolu"
137-
options = [
138-
"--ghc-opt", "-XBangPatterns",
139-
"--ghc-opt", "-XPatternSynonyms",
140-
"--ghc-opt", "-XTypeApplications",
141-
"--mode", "inplace",
142-
"--check-idempotence",
143-
]
144-
includes = ["*.hs"]
145-
```
146-
147-
### [stylish-haskell](https://github.com/jaspervdj/stylish-haskell)
148-
149-
Another Haskell formatter.
150-
151-
```toml
152-
command = "stylish-haskell"
153-
options = [ "--inplace" ]
154-
includes = [ "*.hs" ]
155-
```
156-
157-
### [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)
158-
159-
Nix code formatter.
160-
161-
```toml
162-
command = "nixpkgs-fmt"
163-
includes = ["*.nix"]
164-
```
165-
166-
### rustfmt
167-
168-
```toml
169-
command = "rustfmt"
170-
options = ["--edition", "2018"]
171-
includes = ["*.rs"]
172-
```
173-
174-
### [rufo](https://github.com/ruby-formatter/rufo)
175-
176-
Rufo is an opinionated ruby formatter. By default it exits with status 3 on
177-
file change so we have to pass the `-x` option.
178-
179-
```toml
180-
command = "rufo"
181-
options = ["-x"]
182-
includes = ["*.rb"]
183-
```
184-
185-
### cargo fmt
186-
187-
`cargo fmt` is not supported as it doesn't follow the spec. It doesn't allow
188-
to pass arbitrary files to be formatted, which treefmt relies on. Use `rustfmt`
189-
instead (which is what `cargo fmt` uses under the hood).
78+
## Supported Formatters
19079

191-
### [shfmt](https://github.com/mvdan/sh)
80+
Any formatter that follows the [spec] is supported out of the box.
19281

193-
A shell code formatter.
82+
Already 60+ formatters are supported.
19483

195-
```toml
196-
command = "shfmt"
197-
options = [
198-
"-i",
199-
"2", # indent 2
200-
"-s", # simplify the code
201-
"-w", # write back to the file
202-
]
203-
includes = ["*.sh"]
204-
```
84+
To find examples, take a look at <https://github.com/numtide/treefmt-nix/tree/main/examples>.
20585

206-
### terraform
86+
If you are a Nix user, you might also like <https://github.com/numtide/treefmt-nix>, which uses Nix to pull in the right formatter package and seamlessly integrates both together.
20787

208-
terraform fmt only supports formatting one file at the time. See
209-
https://github.com/hashicorp/terraform/pull/28191
88+
[spec]: formatter-spec

docs/quick-start.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ To run `treefmt` in your project, follow these steps:
1010
2. Ensure any formatters you wish to use are also installed e.g. `gofmt`
1111
3. Run `treefmt --init` to generate a basic configuration file `treefmt.toml`.
1212
4. Edit `treefmt.toml`, [configuring] formatters as desired.
13-
5. Run `treefmt` with the needed [flags & options].
13+
5. Run `treefmt` anywhere in your project to format the whole tree.
1414

1515
[install]: install
1616
[configuring]: configure
17-
[flags & options]: usage

0 commit comments

Comments
 (0)