Skip to content

Commit 9069c9f

Browse files
docs: update configuration info
1 parent 9124dd8 commit 9069c9f

File tree

1 file changed

+137
-5
lines changed

1 file changed

+137
-5
lines changed

Configurations.md

Lines changed: 137 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or
1717

1818
Below you find a detailed visual guide on all the supported configuration options of rustfmt:
1919

20+
## `array_width`
21+
22+
Maximum width of an array literal before falling back to vertical formatting.
23+
24+
- **Default value**: `60`
25+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
26+
- **Stable**: Yes
27+
28+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `array_width` will take precedence.
29+
30+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
31+
32+
## `attr_fn_like_width`
33+
34+
Maximum width of the args of a function-like attributes before falling back to vertical formatting.
35+
36+
- **Default value**: `70`
37+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
38+
- **Stable**: Yes
39+
40+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `attr_fn_like_width` will take precedence.
41+
42+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
2043

2144
## `binop_separator`
2245

@@ -272,6 +295,17 @@ where
272295
}
273296
```
274297

298+
## `chain_width`
299+
300+
Maximum width of a chain to fit on one line.
301+
302+
- **Default value**: `60`
303+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
304+
- **Stable**: Yes
305+
306+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `chain_width` will take precedence.
307+
308+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
275309

276310
## `color`
277311

@@ -717,6 +751,17 @@ trait Lorem {
717751
}
718752
```
719753

754+
## `fn_call_width`
755+
756+
Maximum width of the args of a function call before falling back to vertical formatting.
757+
758+
- **Default value**: `60`
759+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
760+
- **Stable**: Yes
761+
762+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `fn_call_width` will take precedence.
763+
764+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
720765

721766
## `fn_single_line`
722767

@@ -1881,6 +1926,18 @@ specific version of rustfmt is used in your CI, use this option.
18811926
- **Possible values**: any published version (e.g. `"0.3.8"`)
18821927
- **Stable**: No (tracking issue: #3386)
18831928

1929+
## `single_line_if_else_max_width`
1930+
1931+
Maximum line length for single line if-else expressions. A value of `0` (zero) results in if-else expressions always being broken into multiple lines. Note this occurs when `width_heuristics` is set to `Off`.
1932+
1933+
- **Default value**: `50`
1934+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
1935+
- **Stable**: Yes
1936+
1937+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `single_line_if_else_max_width` will take precedence.
1938+
1939+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
1940+
18841941
## `space_after_colon`
18851942

18861943
Leave a space after the colon.
@@ -2058,6 +2115,29 @@ fn main() {
20582115

20592116
See also: [`indent_style`](#indent_style).
20602117

2118+
## `struct_lit_width`
2119+
2120+
Maximum width in the body of a struct literal before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `width_heuristics` is set to `Off`.
2121+
2122+
- **Default value**: `18`
2123+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2124+
- **Stable**: Yes
2125+
2126+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `struct_lit_width` will take precedence.
2127+
2128+
See also [`max_width`](#max_width), [`width_heuristics`](#width_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
2129+
2130+
## `struct_variant_width`
2131+
2132+
Maximum width in the body of a struct variant before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `width_heuristics` is set to `Off`.
2133+
2134+
- **Default value**: `35`
2135+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2136+
- **Stable**: Yes
2137+
2138+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`width_heuristics`](#width_heuristics), but a value set directly for `struct_variant_width` will take precedence.
2139+
2140+
See also [`max_width`](#max_width) and [`width_heuristics`](#width_heuristics)
20612141

20622142
## `tab_spaces`
20632143

@@ -2248,15 +2328,45 @@ fn main() {
22482328
}
22492329
```
22502330

2251-
## `use_small_heuristics`
2331+
## `width_heuristics`
2332+
2333+
This option can be used to simplify the management and bulk updates of the granular width configuration settings ([`fn_call_width`](#fn_call_width), [`attr_fn_like_width`](#attr_fn_like_width), [`struct_lit_width`](#struct_lit_width), [`struct_variant_width`](#struct_variant_width), [`array_width`](#array_width), [`chain_width`](#chain_width), [`single_line_if_else_max_width`](#single_line_if_else_max_width)), that respectively control when formatted constructs are multi-lined/vertical based on width.
22522334

2253-
Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
2335+
Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `width_heuristics`.
22542336

2255-
- **Default value**: `"Default"`
2256-
- **Possible values**: `"Default"`, `"Off"`, `"Max"`
2337+
- **Default value**: `"Scaled"`
2338+
- **Possible values**: `"Scaled"`, `"Off"`, `"Max"`
22572339
- **Stable**: Yes
22582340

2259-
#### `Default` (default):
2341+
#### `Scaled` (default):
2342+
When `width_heuristics` is set to `Scaled`, the values for the granular width settings are calculated as a ratio of the value for `max_width`.
2343+
2344+
The ratios are:
2345+
* [`fn_call_width`](#fn_call_width) - `60%`
2346+
* [`attr_fn_like_width`](#attr_fn_like_width) - `70%`
2347+
* [`struct_lit_width`](#struct_lit_width) - `18%`
2348+
* [`struct_variant_width`](#struct_variant_width) - `35%`
2349+
* [`array_width`](#array_width) - `60%`
2350+
* [`chain_width`](#chain_width) - `60%`
2351+
* [`single_line_if_else_max_width`](#single_line_if_else_max_width) - `50%`
2352+
2353+
For example when `max_width` is set to `100`, the width settings are:
2354+
* `fn_call_width=60`
2355+
* `attr_fn_like_width=70`
2356+
* `struct_lit_width=18`
2357+
* `struct_variant_width=35`
2358+
* `array_width=60`
2359+
* `chain_width=60`
2360+
* `single_line_if_else_max_width=50`
2361+
2362+
and when `max_width` is set to `200`:
2363+
* `fn_call_width=120`
2364+
* `attr_fn_like_width=140`
2365+
* `struct_lit_width=36`
2366+
* `struct_variant_width=70`
2367+
* `array_width=120`
2368+
* `chain_width=120`
2369+
* `single_line_if_else_max_width=100`
22602370

22612371
```rust
22622372
enum Lorem {
@@ -2287,6 +2397,7 @@ fn main() {
22872397
```
22882398

22892399
#### `Off`:
2400+
When `width_heuristics` is set to `Off`, the granular width settings are functionally disabled and ignored. See the documentation for the respective width config options for specifics.
22902401

22912402
```rust
22922403
enum Lorem {
@@ -2315,6 +2426,16 @@ fn main() {
23152426
```
23162427

23172428
#### `Max`:
2429+
When `width_heuristics` is set to `Max`, then each granular width setting is set to the same value as `max_width`.
2430+
2431+
So if `max_width` is set to `200`, then all the width settings are also set to `200`.
2432+
* `fn_call_width=200`
2433+
* `attr_fn_like_width=200`
2434+
* `struct_lit_width=200`
2435+
* `struct_variant_width=200`
2436+
* `array_width=200`
2437+
* `chain_width=200`
2438+
* `single_line_if_else_max_width=200`
23182439

23192440
```rust
23202441
enum Lorem {
@@ -2332,6 +2453,17 @@ fn main() {
23322453
}
23332454
```
23342455

2456+
2457+
See also:
2458+
* [`max_width`](#max_width)
2459+
* [`fn_call_width`](#fn_call_width)
2460+
* [`attr_fn_like_width`](#attr_fn_like_width)
2461+
* [`struct_lit_width`](#struct_lit_width)
2462+
* [`struct_variant_width`](#struct_variant_width)
2463+
* [`array_width`](#array_width)
2464+
* [`chain_width`](#chain_width)
2465+
* [`single_line_if_else_max_width`](#single_line_if_else_max_width)
2466+
23352467
## `use_try_shorthand`
23362468

23372469
Replace uses of the try! macro by the ? shorthand

0 commit comments

Comments
 (0)