Skip to content

Commit 20ef1a4

Browse files
committed
ruff_python_formatter: make docstring-code-line-length default to 'dynamic'
I do feel like this is probably the right default and perhaps will be the least surprising. It also has the benefit of avoiding the line length lint in all cases.
1 parent 588f2c1 commit 20ef1a4

13 files changed

+60
-48
lines changed

crates/ruff_python_formatter/src/options.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,21 @@ impl DocstringCode {
308308
}
309309
}
310310

311-
#[derive(Copy, Clone, Eq, PartialEq, CacheKey)]
311+
#[derive(Copy, Clone, Default, Eq, PartialEq, CacheKey)]
312312
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
313313
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
314314
#[cfg_attr(feature = "serde", serde(untagged))]
315315
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
316316
pub enum DocstringCodeLineWidth {
317317
Fixed(LineWidth),
318+
#[default]
318319
#[cfg_attr(
319320
feature = "serde",
320321
serde(deserialize_with = "deserialize_docstring_code_line_width_dynamic")
321322
)]
322323
Dynamic,
323324
}
324325

325-
impl Default for DocstringCodeLineWidth {
326-
fn default() -> DocstringCodeLineWidth {
327-
DocstringCodeLineWidth::Fixed(default_line_width())
328-
}
329-
}
330-
331326
impl std::fmt::Debug for DocstringCodeLineWidth {
332327
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
333328
match *self {

crates/ruff_python_formatter/tests/snapshots/format@docstring.py.snap

+5-5
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ quote-style = Double
173173
line-ending = LineFeed
174174
magic-trailing-comma = Respect
175175
docstring-code = Disabled
176-
docstring-code-line-width = 88
176+
docstring-code-line-width = "dynamic"
177177
preview = Disabled
178178
```
179179

@@ -347,7 +347,7 @@ quote-style = Double
347347
line-ending = LineFeed
348348
magic-trailing-comma = Respect
349349
docstring-code = Disabled
350-
docstring-code-line-width = 88
350+
docstring-code-line-width = "dynamic"
351351
preview = Disabled
352352
```
353353

@@ -521,7 +521,7 @@ quote-style = Double
521521
line-ending = LineFeed
522522
magic-trailing-comma = Respect
523523
docstring-code = Disabled
524-
docstring-code-line-width = 88
524+
docstring-code-line-width = "dynamic"
525525
preview = Disabled
526526
```
527527

@@ -695,7 +695,7 @@ quote-style = Double
695695
line-ending = LineFeed
696696
magic-trailing-comma = Respect
697697
docstring-code = Disabled
698-
docstring-code-line-width = 88
698+
docstring-code-line-width = "dynamic"
699699
preview = Disabled
700700
```
701701

@@ -869,7 +869,7 @@ quote-style = Single
869869
line-ending = LineFeed
870870
magic-trailing-comma = Respect
871871
docstring-code = Disabled
872-
docstring-code-line-width = 88
872+
docstring-code-line-width = "dynamic"
873873
preview = Disabled
874874
```
875875

crates/ruff_python_formatter/tests/snapshots/format@docstring_code_examples.py.snap

+30-13
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ quote-style = Double
13661366
line-ending = LineFeed
13671367
magic-trailing-comma = Respect
13681368
docstring-code = Disabled
1369-
docstring-code-line-width = 88
1369+
docstring-code-line-width = "dynamic"
13701370
preview = Disabled
13711371
```
13721372
@@ -2736,7 +2736,7 @@ quote-style = Double
27362736
line-ending = LineFeed
27372737
magic-trailing-comma = Respect
27382738
docstring-code = Disabled
2739-
docstring-code-line-width = 88
2739+
docstring-code-line-width = "dynamic"
27402740
preview = Disabled
27412741
```
27422742
@@ -4106,7 +4106,7 @@ quote-style = Double
41064106
line-ending = LineFeed
41074107
magic-trailing-comma = Respect
41084108
docstring-code = Disabled
4109-
docstring-code-line-width = 88
4109+
docstring-code-line-width = "dynamic"
41104110
preview = Disabled
41114111
```
41124112
@@ -5476,7 +5476,7 @@ quote-style = Double
54765476
line-ending = LineFeed
54775477
magic-trailing-comma = Respect
54785478
docstring-code = Disabled
5479-
docstring-code-line-width = 88
5479+
docstring-code-line-width = "dynamic"
54805480
preview = Disabled
54815481
```
54825482
@@ -6846,7 +6846,7 @@ quote-style = Double
68466846
line-ending = LineFeed
68476847
magic-trailing-comma = Respect
68486848
docstring-code = Enabled
6849-
docstring-code-line-width = 88
6849+
docstring-code-line-width = "dynamic"
68506850
preview = Disabled
68516851
```
68526852
@@ -7090,7 +7090,9 @@ def doctest_long_lines():
70907090
This won't get wrapped even though it exceeds our configured
70917091
line width because it doesn't exceed the line width within this
70927092
docstring. e.g, the `f` in `foo` is treated as the first column.
7093-
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
7093+
>>> foo, bar, quux = this_is_a_long_line(
7094+
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
7095+
... )
70947096

70957097
But this one is long enough to get wrapped.
70967098
>>> foo, bar, quux = this_is_a_long_line(
@@ -8211,7 +8213,7 @@ quote-style = Double
82118213
line-ending = LineFeed
82128214
magic-trailing-comma = Respect
82138215
docstring-code = Enabled
8214-
docstring-code-line-width = 88
8216+
docstring-code-line-width = "dynamic"
82158217
preview = Disabled
82168218
```
82178219
@@ -8455,7 +8457,9 @@ def doctest_long_lines():
84558457
This won't get wrapped even though it exceeds our configured
84568458
line width because it doesn't exceed the line width within this
84578459
docstring. e.g, the `f` in `foo` is treated as the first column.
8458-
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
8460+
>>> foo, bar, quux = this_is_a_long_line(
8461+
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
8462+
... )
84598463

84608464
But this one is long enough to get wrapped.
84618465
>>> foo, bar, quux = this_is_a_long_line(
@@ -9576,7 +9580,7 @@ quote-style = Double
95769580
line-ending = LineFeed
95779581
magic-trailing-comma = Respect
95789582
docstring-code = Enabled
9579-
docstring-code-line-width = 88
9583+
docstring-code-line-width = "dynamic"
95809584
preview = Disabled
95819585
```
95829586
@@ -9820,11 +9824,22 @@ def doctest_long_lines():
98209824
This won't get wrapped even though it exceeds our configured
98219825
line width because it doesn't exceed the line width within this
98229826
docstring. e.g, the `f` in `foo` is treated as the first column.
9823-
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
9827+
>>> foo, bar, quux = this_is_a_long_line(
9828+
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
9829+
... )
98249830

98259831
But this one is long enough to get wrapped.
98269832
>>> foo, bar, quux = this_is_a_long_line(
9827-
... lion, giraffe, hippo, zeba, lemur, penguin, monkey, spider, bear, leopard
9833+
... lion,
9834+
... giraffe,
9835+
... hippo,
9836+
... zeba,
9837+
... lemur,
9838+
... penguin,
9839+
... monkey,
9840+
... spider,
9841+
... bear,
9842+
... leopard,
98289843
... )
98299844
"""
98309845
# This demostrates a normal line that will get wrapped but won't
@@ -10941,7 +10956,7 @@ quote-style = Double
1094110956
line-ending = LineFeed
1094210957
magic-trailing-comma = Respect
1094310958
docstring-code = Enabled
10944-
docstring-code-line-width = 88
10959+
docstring-code-line-width = "dynamic"
1094510960
preview = Disabled
1094610961
```
1094710962
@@ -11185,7 +11200,9 @@ def doctest_long_lines():
1118511200
This won't get wrapped even though it exceeds our configured
1118611201
line width because it doesn't exceed the line width within this
1118711202
docstring. e.g, the `f` in `foo` is treated as the first column.
11188-
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
11203+
>>> foo, bar, quux = this_is_a_long_line(
11204+
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
11205+
... )
1118911206

1119011207
But this one is long enough to get wrapped.
1119111208
>>> foo, bar, quux = this_is_a_long_line(

crates/ruff_python_formatter/tests/snapshots/format@docstring_code_examples_crlf.py.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ quote-style = Double
2525
line-ending = CarriageReturnLineFeed
2626
magic-trailing-comma = Respect
2727
docstring-code = Enabled
28-
docstring-code-line-width = 88
28+
docstring-code-line-width = "dynamic"
2929
preview = Disabled
3030
```
3131

crates/ruff_python_formatter/tests/snapshots/format@expression__bytes.py.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ quote-style = Double
136136
line-ending = LineFeed
137137
magic-trailing-comma = Respect
138138
docstring-code = Disabled
139-
docstring-code-line-width = 88
139+
docstring-code-line-width = "dynamic"
140140
preview = Disabled
141141
```
142142

@@ -288,7 +288,7 @@ quote-style = Single
288288
line-ending = LineFeed
289289
magic-trailing-comma = Respect
290290
docstring-code = Disabled
291-
docstring-code-line-width = 88
291+
docstring-code-line-width = "dynamic"
292292
preview = Disabled
293293
```
294294

crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ quote-style = Double
151151
line-ending = LineFeed
152152
magic-trailing-comma = Respect
153153
docstring-code = Disabled
154-
docstring-code-line-width = 88
154+
docstring-code-line-width = "dynamic"
155155
preview = Disabled
156156
```
157157

@@ -327,7 +327,7 @@ quote-style = Single
327327
line-ending = LineFeed
328328
magic-trailing-comma = Respect
329329
docstring-code = Disabled
330-
docstring-code-line-width = 88
330+
docstring-code-line-width = "dynamic"
331331
preview = Disabled
332332
```
333333

crates/ruff_python_formatter/tests/snapshots/format@fmt_on_off__fmt_off_docstring.py.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ quote-style = Double
3535
line-ending = LineFeed
3636
magic-trailing-comma = Respect
3737
docstring-code = Disabled
38-
docstring-code-line-width = 88
38+
docstring-code-line-width = "dynamic"
3939
preview = Disabled
4040
```
4141

@@ -71,7 +71,7 @@ quote-style = Double
7171
line-ending = LineFeed
7272
magic-trailing-comma = Respect
7373
docstring-code = Disabled
74-
docstring-code-line-width = 88
74+
docstring-code-line-width = "dynamic"
7575
preview = Disabled
7676
```
7777

crates/ruff_python_formatter/tests/snapshots/format@fmt_on_off__indent.py.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ quote-style = Double
1616
line-ending = LineFeed
1717
magic-trailing-comma = Respect
1818
docstring-code = Disabled
19-
docstring-code-line-width = 88
19+
docstring-code-line-width = "dynamic"
2020
preview = Disabled
2121
```
2222

@@ -33,7 +33,7 @@ quote-style = Double
3333
line-ending = LineFeed
3434
magic-trailing-comma = Respect
3535
docstring-code = Disabled
36-
docstring-code-line-width = 88
36+
docstring-code-line-width = "dynamic"
3737
preview = Disabled
3838
```
3939

@@ -50,7 +50,7 @@ quote-style = Double
5050
line-ending = LineFeed
5151
magic-trailing-comma = Respect
5252
docstring-code = Disabled
53-
docstring-code-line-width = 88
53+
docstring-code-line-width = "dynamic"
5454
preview = Disabled
5555
```
5656

crates/ruff_python_formatter/tests/snapshots/format@fmt_on_off__mixed_space_and_tab.py.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ quote-style = Double
3131
line-ending = LineFeed
3232
magic-trailing-comma = Respect
3333
docstring-code = Disabled
34-
docstring-code-line-width = 88
34+
docstring-code-line-width = "dynamic"
3535
preview = Disabled
3636
```
3737

@@ -64,7 +64,7 @@ quote-style = Double
6464
line-ending = LineFeed
6565
magic-trailing-comma = Respect
6666
docstring-code = Disabled
67-
docstring-code-line-width = 88
67+
docstring-code-line-width = "dynamic"
6868
preview = Disabled
6969
```
7070

@@ -97,7 +97,7 @@ quote-style = Double
9797
line-ending = LineFeed
9898
magic-trailing-comma = Respect
9999
docstring-code = Disabled
100-
docstring-code-line-width = 88
100+
docstring-code-line-width = "dynamic"
101101
preview = Disabled
102102
```
103103

crates/ruff_python_formatter/tests/snapshots/format@preview.py.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ quote-style = Double
8282
line-ending = LineFeed
8383
magic-trailing-comma = Respect
8484
docstring-code = Disabled
85-
docstring-code-line-width = 88
85+
docstring-code-line-width = "dynamic"
8686
preview = Disabled
8787
```
8888

@@ -164,7 +164,7 @@ quote-style = Double
164164
line-ending = LineFeed
165165
magic-trailing-comma = Respect
166166
docstring-code = Disabled
167-
docstring-code-line-width = 88
167+
docstring-code-line-width = "dynamic"
168168
preview = Enabled
169169
```
170170

crates/ruff_python_formatter/tests/snapshots/format@quote_style.py.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ quote-style = Single
6666
line-ending = LineFeed
6767
magic-trailing-comma = Respect
6868
docstring-code = Disabled
69-
docstring-code-line-width = 88
69+
docstring-code-line-width = "dynamic"
7070
preview = Disabled
7171
```
7272

@@ -137,7 +137,7 @@ quote-style = Double
137137
line-ending = LineFeed
138138
magic-trailing-comma = Respect
139139
docstring-code = Disabled
140-
docstring-code-line-width = 88
140+
docstring-code-line-width = "dynamic"
141141
preview = Disabled
142142
```
143143

@@ -208,7 +208,7 @@ quote-style = Preserve
208208
line-ending = LineFeed
209209
magic-trailing-comma = Respect
210210
docstring-code = Disabled
211-
docstring-code-line-width = 88
211+
docstring-code-line-width = "dynamic"
212212
preview = Disabled
213213
```
214214

crates/ruff_python_formatter/tests/snapshots/format@skip_magic_trailing_comma.py.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ quote-style = Double
4949
line-ending = LineFeed
5050
magic-trailing-comma = Respect
5151
docstring-code = Disabled
52-
docstring-code-line-width = 88
52+
docstring-code-line-width = "dynamic"
5353
preview = Disabled
5454
```
5555

@@ -105,7 +105,7 @@ quote-style = Double
105105
line-ending = LineFeed
106106
magic-trailing-comma = Ignore
107107
docstring-code = Disabled
108-
docstring-code-line-width = 88
108+
docstring-code-line-width = "dynamic"
109109
preview = Disabled
110110
```
111111

0 commit comments

Comments
 (0)