Introduce IndentWidth (#7301)

This commit is contained in:
Micha Reiser 2023-09-13 14:52:24 +02:00 committed by GitHub
parent e122a96d27
commit 2d9b39871f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 187 additions and 199 deletions

View file

@ -1,5 +1,5 @@
use ruff_formatter::printer::{LineEnding, PrinterOptions, SourceMapGeneration};
use ruff_formatter::{FormatOptions, IndentStyle, LineWidth, TabWidth};
use ruff_formatter::{FormatOptions, IndentStyle, IndentWidth, LineWidth};
use ruff_python_ast::PySourceType;
use std::path::Path;
use std::str::FromStr;
@ -25,8 +25,8 @@ pub struct PyFormatOptions {
line_width: LineWidth,
/// The visual width of a tab character.
#[cfg_attr(feature = "serde", serde(default = "default_tab_width"))]
tab_width: TabWidth,
#[cfg_attr(feature = "serde", serde(default = "default_indent_width"))]
indent_width: IndentWidth,
line_ending: LineEnding,
@ -49,11 +49,11 @@ fn default_line_width() -> LineWidth {
}
fn default_indent_style() -> IndentStyle {
IndentStyle::Space(4)
IndentStyle::Space
}
fn default_tab_width() -> TabWidth {
TabWidth::try_from(4).unwrap()
fn default_indent_width() -> IndentWidth {
IndentWidth::try_from(4).unwrap()
}
impl Default for PyFormatOptions {
@ -62,7 +62,7 @@ impl Default for PyFormatOptions {
source_type: PySourceType::default(),
indent_style: default_indent_style(),
line_width: default_line_width(),
tab_width: default_tab_width(),
indent_width: default_indent_width(),
quote_style: QuoteStyle::default(),
line_ending: LineEnding::default(),
magic_trailing_comma: MagicTrailingComma::default(),
@ -110,8 +110,8 @@ impl PyFormatOptions {
}
#[must_use]
pub fn with_tab_width(mut self, tab_width: TabWidth) -> Self {
self.tab_width = tab_width;
pub fn with_indent_width(mut self, indent_width: IndentWidth) -> Self {
self.indent_width = indent_width;
self
}
@ -157,8 +157,8 @@ impl FormatOptions for PyFormatOptions {
self.indent_style
}
fn tab_width(&self) -> TabWidth {
self.tab_width
fn indent_width(&self) -> IndentWidth {
self.indent_width
}
fn line_width(&self) -> LineWidth {
@ -167,7 +167,7 @@ impl FormatOptions for PyFormatOptions {
fn as_print_options(&self) -> PrinterOptions {
PrinterOptions {
tab_width: self.tab_width,
indent_width: self.indent_width,
line_width: self.line_width,
line_ending: self.line_ending,
indent_style: self.indent_style,