Commit 9cf09c7
committed
Merge configs from parent directories
Currently, `rustfmt` stops building its configuration after one
configuration file is found. However, users may expect that `rustfmt`
includes configuration options inhereted by configuration files in
parent directories of the directory `rustfmt` is run in.
The motivation for this commit is for a use case involving files that
should be ignored by `rustfmt`. Consider the directory structure
```
a
|-- rustfmt.toml
|-- b
|-- rustfmt.toml
|-- main.rs
```
Suppose `a/rustfmt.toml` has the option `ignore = ["b/main.rs"]`. A user
may expect that running `rusfmt` in either directory `a/` or `b/` will
ignore `main.rs`. Today, though, if `rustfmt` is run in `b/`, `main.rs`
will be formatted because only `b/rustfmt.toml` will be used for
configuration.
Although motivated by the use case for ignored files, this change sets
up `rustfmt` to incrementally populate all configuration options from
parent config files. The priority of population is closest config file
to most transient config file.
To avoid churn of the existing implementation for ignoring files,
populating the ignored files config option with multiple config files is
done by computing a join. Given config files "outer" and "inner", where
"inner" is of higher priority (nested in the directory of) "outer", we
merge their `ignore` configurations by finding the ignore files
specified in "outer" that are present in the "inner" directory, and
appending this to the files ignored by "inner".
This means that printing an `ignore` configuration may not be entirely
accurate, as it could be missing files that are not in the current
directory specified by transient configurations. These files are out of
the scope the `rustfmt` instance's operation, though, so for practical
purposes I don't think this matters.
Closes #38811 parent e44a71c commit 9cf09c7
File tree
4 files changed
+233
-62
lines changed- rustfmt-core
- rustfmt-bin/src/bin
- rustfmt-lib/src
- config
4 files changed
+233
-62
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
| 428 | + | |
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| |||
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
460 | | - | |
| 460 | + | |
461 | 461 | | |
462 | | - | |
| 462 | + | |
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
| |||
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
486 | | - | |
| 486 | + | |
487 | 487 | | |
488 | 488 | | |
489 | | - | |
490 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
491 | 499 | | |
492 | 500 | | |
493 | 501 | | |
| |||
496 | 504 | | |
497 | 505 | | |
498 | 506 | | |
499 | | - | |
| 507 | + | |
500 | 508 | | |
501 | 509 | | |
502 | 510 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
173 | 210 | | |
174 | 211 | | |
175 | 212 | | |
| |||
197 | 234 | | |
198 | 235 | | |
199 | 236 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 237 | + | |
| 238 | + | |
205 | 239 | | |
206 | 240 | | |
207 | 241 | | |
| |||
213 | 247 | | |
214 | 248 | | |
215 | 249 | | |
216 | | - | |
| 250 | + | |
217 | 251 | | |
218 | 252 | | |
219 | 253 | | |
220 | | - | |
| 254 | + | |
221 | 255 | | |
222 | 256 | | |
223 | 257 | | |
224 | 258 | | |
225 | 259 | | |
226 | 260 | | |
227 | 261 | | |
| 262 | + | |
228 | 263 | | |
229 | 264 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 265 | + | |
| 266 | + | |
235 | 267 | | |
236 | 268 | | |
237 | 269 | | |
238 | 270 | | |
239 | 271 | | |
240 | 272 | | |
241 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
242 | 278 | | |
243 | 279 | | |
244 | 280 | | |
245 | | - | |
| 281 | + | |
246 | 282 | | |
247 | 283 | | |
248 | 284 | | |
249 | 285 | | |
250 | 286 | | |
251 | 287 | | |
252 | 288 | | |
253 | | - | |
| 289 | + | |
254 | 290 | | |
255 | 291 | | |
256 | 292 | | |
257 | 293 | | |
258 | 294 | | |
259 | 295 | | |
260 | | - | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
261 | 299 | | |
262 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
263 | 311 | | |
264 | 312 | | |
265 | 313 | | |
266 | 314 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
295 | 318 | | |
296 | 319 | | |
297 | 320 | | |
| |||
300 | 323 | | |
301 | 324 | | |
302 | 325 | | |
303 | | - | |
| 326 | + | |
304 | 327 | | |
305 | 328 | | |
306 | 329 | | |
307 | 330 | | |
308 | 331 | | |
309 | 332 | | |
310 | | - | |
| 333 | + | |
311 | 334 | | |
312 | 335 | | |
313 | 336 | | |
| |||
417 | 440 | | |
418 | 441 | | |
419 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
420 | 479 | | |
421 | 480 | | |
422 | 481 | | |
| |||
568 | 627 | | |
569 | 628 | | |
570 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
571 | 661 | | |
572 | 662 | | |
573 | 663 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
53 | 69 | | |
54 | 70 | | |
55 | 71 | | |
| |||
149 | 165 | | |
150 | 166 | | |
151 | 167 | | |
152 | | - | |
153 | | - | |
| 168 | + | |
154 | 169 | | |
155 | 170 | | |
156 | | - | |
157 | | - | |
| 171 | + | |
158 | 172 | | |
159 | 173 | | |
160 | 174 | | |
| |||
164 | 178 | | |
165 | 179 | | |
166 | 180 | | |
167 | | - | |
168 | 181 | | |
169 | 182 | | |
170 | 183 | | |
| |||
397 | 410 | | |
398 | 411 | | |
399 | 412 | | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | 413 | | |
405 | 414 | | |
406 | 415 | | |
| |||
0 commit comments