ruff_python_formatter: implement "dynamic" line width mode for docstring code formatting (#9098)

## Summary

This PR changes the internal `docstring-code-line-width` setting to
additionally accept a string value `dynamic`. When `dynamic` is set, the
line width is dynamically adjusted when reformatting code snippets in
docstrings based on the indent level of the docstring. The result is
that the reformatted lines from the code snippet should not exceed the
"global" line width configuration for the surrounding source.

This PR does not change the default behavior, although I suspect the
default should probably be `dynamic`.

## Test Plan

I added a new configuration to the existing docstring code tests and
also added a new set of tests dedicated to the new `dynamic` mode.
This commit is contained in:
Andrew Gallant 2023-12-12 09:58:07 -05:00 committed by GitHub
parent 5559827a78
commit b972455ac7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 3394 additions and 12 deletions

View file

@ -363,7 +363,7 @@ preview = {preview:?}"#,
line_ending = self.0.line_ending(),
magic_trailing_comma = self.0.magic_trailing_comma(),
docstring_code = self.0.docstring_code(),
docstring_code_line_width = self.0.docstring_code_line_width().value(),
docstring_code_line_width = self.0.docstring_code_line_width(),
preview = self.0.preview()
)
}