@@ -41,14 +41,14 @@ priority = 1
41
41
42
42
## Global Options
43
43
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.
45
45
46
46
## Formatter Options
47
47
48
48
- ` command ` - the command to invoke when applying the formatter.
49
49
- ` 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.
52
52
- ` priority ` - influences the order of execution. Greater precedence is given to lower numbers, with the default being ` 0 ` .
53
53
54
54
## Same file, multiple formatters?
@@ -65,145 +65,24 @@ Another consequence is that formatting is deterministic for a given file and a g
65
65
By setting the priority fields appropriately, you can control the order in which those formatters are applied for any
66
66
files they _ both happen to match on_ .
67
67
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
94
69
95
- A python formatter.
70
+ This is a variant of the Unix glob pattern. It supports all the usual
71
+ selectors such as ` * ` and ` ? ` .
96
72
97
- ``` toml
98
- command = " black"
99
- includes = [" *.py" ]
100
- ```
73
+ ### Examples
101
74
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.
129
77
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
190
79
191
- ### [ shfmt ] ( https://github.com/mvdan/sh )
80
+ Any formatter that follows the [ spec ] is supported out of the box.
192
81
193
- A shell code formatter .
82
+ Already 60+ formatters are supported .
194
83
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 > .
205
85
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.
207
87
208
- terraform fmt only supports formatting one file at the time. See
209
- https://github.com/hashicorp/terraform/pull/28191
88
+ [ spec ] : formatter-spec
0 commit comments