ruff/crates/ruff_python_formatter/src/statement
Andrew Gallant b972455ac7
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.
2023-12-12 09:58:07 -05:00
..
clause.rs Add test and basic implementation for formatter preview mode (#8044) 2023-10-26 15:33:26 +00:00
mod.rs Preserve trailing statement semicolons when using `fmt: skip` (#8273) 2023-10-30 00:07:14 +00:00
stmt_ann_assign.rs Refactor the comment handling of a statement's last expression (#8920) 2023-12-04 05:12:12 +00:00
stmt_assert.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_assign.rs Fix handling of trailing target comment (#9051) 2023-12-08 05:00:36 +00:00
stmt_aug_assign.rs Refactor the comment handling of a statement's last expression (#8920) 2023-12-04 05:12:12 +00:00
stmt_break.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_class_def.rs Insert necessary blank line between class and leading comments (#8224) 2023-10-25 20:31:59 -04:00
stmt_continue.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_delete.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_expr.rs Preserve trailing semicolon for Notebooks (#8590) 2023-11-10 21:53:35 +05:30
stmt_for.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_function_def.rs Insert necessary blank line between class and leading comments (#8224) 2023-10-25 20:31:59 -04:00
stmt_global.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
stmt_if.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
stmt_import.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_import_from.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
stmt_ipy_escape_command.rs Memoize text width (#6552) 2023-09-06 07:10:13 +00:00
stmt_match.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_nonlocal.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
stmt_pass.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_raise.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_return.rs Refactor the comment handling of a statement's last expression (#8920) 2023-12-04 05:12:12 +00:00
stmt_try.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
stmt_type_alias.rs Inline trailing comments for type alias similar to assignments (#8941) 2023-12-04 05:27:04 +00:00
stmt_while.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
stmt_with.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
suite.rs ruff_python_formatter: implement "dynamic" line width mode for docstring code formatting (#9098) 2023-12-12 09:58:07 -05:00