config: add new docstring-code-format knob (#8854)

This PR does the plumbing to make a new formatting option,
`docstring-code-format`, available in the configuration for end users.
It is disabled by default (opt-in). It is opt-in at least initially to
reflect a conservative posture. The intent is to make it opt-out at some
point in the future.

This was split out from #8811 in order to make #8811 easier to merge.
Namely, once this is merged, docstring code snippet formatting will
become available to end users. (See comments below for how we arrived at
the name.)

Closes #7146

## Test Plan

Other than the standard test suite, I ran the formatter over the CPython
and polars projects to ensure both that the result looked sensible and
that tests still passed. At time of writing, one issue that currently
appears is that reformatting code snippets trips the long line lint:
1905886802
This commit is contained in:
Andrew Gallant 2023-12-13 11:02:11 -05:00 committed by GitHub
parent 18452cf477
commit b6fb972e6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 505 additions and 55 deletions

View file

@ -173,7 +173,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -347,7 +347,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -521,7 +521,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -695,7 +695,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -869,7 +869,7 @@ quote-style = Single
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -1366,7 +1366,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -2736,7 +2736,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -4106,7 +4106,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -5476,7 +5476,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -6846,7 +6846,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Enabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -7090,7 +7090,9 @@ def doctest_long_lines():
This won't get wrapped even though it exceeds our configured
line width because it doesn't exceed the line width within this
docstring. e.g, the `f` in `foo` is treated as the first column.
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
>>> foo, bar, quux = this_is_a_long_line(
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
... )
But this one is long enough to get wrapped.
>>> foo, bar, quux = this_is_a_long_line(
@ -8211,7 +8213,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Enabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -8455,7 +8457,9 @@ def doctest_long_lines():
This won't get wrapped even though it exceeds our configured
line width because it doesn't exceed the line width within this
docstring. e.g, the `f` in `foo` is treated as the first column.
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
>>> foo, bar, quux = this_is_a_long_line(
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
... )
But this one is long enough to get wrapped.
>>> foo, bar, quux = this_is_a_long_line(
@ -9576,7 +9580,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Enabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -9820,11 +9824,22 @@ def doctest_long_lines():
This won't get wrapped even though it exceeds our configured
line width because it doesn't exceed the line width within this
docstring. e.g, the `f` in `foo` is treated as the first column.
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
>>> foo, bar, quux = this_is_a_long_line(
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
... )
But this one is long enough to get wrapped.
>>> foo, bar, quux = this_is_a_long_line(
... lion, giraffe, hippo, zeba, lemur, penguin, monkey, spider, bear, leopard
... lion,
... giraffe,
... hippo,
... zeba,
... lemur,
... penguin,
... monkey,
... spider,
... bear,
... leopard,
... )
"""
# This demostrates a normal line that will get wrapped but won't
@ -10941,7 +10956,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Enabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -11185,7 +11200,9 @@ def doctest_long_lines():
This won't get wrapped even though it exceeds our configured
line width because it doesn't exceed the line width within this
docstring. e.g, the `f` in `foo` is treated as the first column.
>>> foo, bar, quux = this_is_a_long_line(lion, giraffe, hippo, zeba, lemur, penguin, monkey)
>>> foo, bar, quux = this_is_a_long_line(
... lion, giraffe, hippo, zeba, lemur, penguin, monkey
... )
But this one is long enough to get wrapped.
>>> foo, bar, quux = this_is_a_long_line(

View file

@ -25,7 +25,7 @@ quote-style = Double
line-ending = CarriageReturnLineFeed
magic-trailing-comma = Respect
docstring-code = Enabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -136,7 +136,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -288,7 +288,7 @@ quote-style = Single
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -151,7 +151,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -327,7 +327,7 @@ quote-style = Single
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -35,7 +35,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -71,7 +71,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -16,7 +16,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -33,7 +33,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -50,7 +50,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -31,7 +31,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -64,7 +64,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -97,7 +97,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -82,7 +82,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -164,7 +164,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Enabled
```

View file

@ -66,7 +66,7 @@ quote-style = Single
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -137,7 +137,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -208,7 +208,7 @@ quote-style = Preserve
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -49,7 +49,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -105,7 +105,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Ignore
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```

View file

@ -234,7 +234,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Enabled
```

View file

@ -24,7 +24,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -49,7 +49,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```
@ -77,7 +77,7 @@ quote-style = Double
line-ending = LineFeed
magic-trailing-comma = Respect
docstring-code = Disabled
docstring-code-line-width = 88
docstring-code-line-width = "dynamic"
preview = Disabled
```