mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 11:25:26 +00:00
ruff_python_formatter: add docstring-code-line-width internal setting (#9055)
## Summary This does the light plumbing necessary to add a new internal option that permits setting the line width of code examples in docstrings. The plan is to add the corresponding user facing knob in #8854. Note that this effectively removes the `same-as-global` configuration style discussed [in this comment](https://github.com/astral-sh/ruff/issues/8855#issuecomment-1847230440). It replaces it with the `{integer}` configuration style only. There are a lot of commits here, but they are each tiny to make review easier because of the changes to snapshots. ## Test Plan I added a new docstring test configuration that sets `docstring-code-line-width = 60` and examined the differences.
This commit is contained in:
parent
3aa6a30395
commit
07380e0657
16 changed files with 1728 additions and 296 deletions
|
@ -49,6 +49,12 @@ pub struct PyFormatOptions {
|
|||
/// enabled by default (opt-out) in the future.
|
||||
docstring_code: DocstringCode,
|
||||
|
||||
/// The preferred line width at which the formatter should wrap lines in
|
||||
/// docstring code examples. This only has an impact when `docstring_code`
|
||||
/// is enabled.
|
||||
#[cfg_attr(feature = "serde", serde(default = "default_line_width"))]
|
||||
docstring_code_line_width: LineWidth,
|
||||
|
||||
/// Whether preview style formatting is enabled or not
|
||||
preview: PreviewMode,
|
||||
}
|
||||
|
@ -77,6 +83,7 @@ impl Default for PyFormatOptions {
|
|||
magic_trailing_comma: MagicTrailingComma::default(),
|
||||
source_map_generation: SourceMapGeneration::default(),
|
||||
docstring_code: DocstringCode::default(),
|
||||
docstring_code_line_width: default_line_width(),
|
||||
preview: PreviewMode::default(),
|
||||
}
|
||||
}
|
||||
|
@ -119,6 +126,10 @@ impl PyFormatOptions {
|
|||
self.docstring_code
|
||||
}
|
||||
|
||||
pub fn docstring_code_line_width(&self) -> LineWidth {
|
||||
self.docstring_code_line_width
|
||||
}
|
||||
|
||||
pub const fn preview(&self) -> PreviewMode {
|
||||
self.preview
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue