diff --git a/crates/ruff_formatter/src/builders.rs b/crates/ruff_formatter/src/builders.rs index 188123d976..33ea49724e 100644 --- a/crates/ruff_formatter/src/builders.rs +++ b/crates/ruff_formatter/src/builders.rs @@ -727,11 +727,11 @@ impl std::fmt::Debug for Indent<'_, Context> { } } -/// It reduces the indention for the given content depending on the closest [indent] or [align] parent element. +/// It reduces the indentation for the given content depending on the closest [indent] or [align] parent element. /// - [align] Undoes the spaces added by [align] -/// - [indent] Reduces the indention level by one +/// - [indent] Reduces the indentation level by one /// -/// This is a No-op if the indention level is zero. +/// This is a No-op if the indentation level is zero. /// /// # Examples /// @@ -863,7 +863,7 @@ where /// /// # Examples /// -/// ## Tab indention +/// ## Tab indentation /// /// ``` /// use std::num::NonZeroU8; @@ -904,11 +904,11 @@ where /// /// - the printer indents the function's `}` by two spaces because it is inside of an `align`. /// - the block `console.log` gets indented by two tabs. -/// This is because `align` increases the indention level by one (same as `indent`) +/// This is because `align` increases the indentation level by one (same as `indent`) /// if you nest an `indent` inside an `align`. -/// Meaning that, `align > ... > indent` results in the same indention as `indent > ... > indent`. +/// Meaning that, `align > ... > indent` results in the same indentation as `indent > ... > indent`. /// -/// ## Spaces indention +/// ## Spaces indentation /// /// ``` /// use std::num::NonZeroU8; @@ -952,11 +952,11 @@ where /// # } /// ``` /// -/// The printing of `align` differs if using spaces as indention sequence *and* it contains an `indent`. -/// You can see the difference when comparing the indention of the `console.log(...)` expression to the previous example: +/// The printing of `align` differs if using spaces as indentation sequence *and* it contains an `indent`. +/// You can see the difference when comparing the indentation of the `console.log(...)` expression to the previous example: /// -/// - tab indention: Printer indents the expression with two tabs because the `align` increases the indention level. -/// - space indention: Printer indents the expression by 4 spaces (one indention level) **and** 2 spaces for the align. +/// - tab indentation: Printer indents the expression with two tabs because the `align` increases the indentation level. +/// - space indentation: Printer indents the expression by 4 spaces (one indentation level) **and** 2 spaces for the align. pub fn align(count: u8, content: &Content) -> Align where Content: Format, @@ -992,12 +992,12 @@ impl std::fmt::Debug for Align<'_, Context> { } } -/// Inserts a hard line break before and after the content and increases the indention level for the content by one. +/// Inserts a hard line break before and after the content and increases the indentation level for the content by one. /// /// Block indents indent a block of code, such as in a function body, and therefore insert a line /// break before and after the content. /// -/// Doesn't create an indention if the passed in content is [`FormatElement.is_empty`]. +/// Doesn't create an indentation if the passed in content is [`FormatElement.is_empty`]. /// /// # Examples /// @@ -1035,7 +1035,7 @@ pub fn block_indent(content: &impl Format) -> BlockIndent std::fmt::Debug for IfGroupBreaks<'_, Context> { /// If you want to indent some content if the enclosing group breaks, use [`indent`]. /// /// Use [`if_group_breaks`] or [`if_group_fits_on_line`] if the fitting and breaking content differs more than just the -/// indention level. +/// indentation level. /// /// # Examples /// diff --git a/crates/ruff_formatter/src/format_element/tag.rs b/crates/ruff_formatter/src/format_element/tag.rs index ec0f306f51..853008e516 100644 --- a/crates/ruff_formatter/src/format_element/tag.rs +++ b/crates/ruff_formatter/src/format_element/tag.rs @@ -20,7 +20,7 @@ pub enum Tag { StartAlign(Align), EndAlign, - /// Reduces the indention of the specified content either by one level or to the root, depending on the mode. + /// Reduces the indentation of the specified content either by one level or to the root, depending on the mode. /// Reverse operation of `Indent` and can be used to *undo* an `Align` for nested content. StartDedent(DedentMode), EndDedent, diff --git a/crates/ruff_formatter/src/printer/call_stack.rs b/crates/ruff_formatter/src/printer/call_stack.rs index 858510ae7f..aa5c73dfda 100644 --- a/crates/ruff_formatter/src/printer/call_stack.rs +++ b/crates/ruff_formatter/src/printer/call_stack.rs @@ -1,7 +1,7 @@ use crate::format_element::tag::TagKind; use crate::format_element::PrintMode; use crate::printer::stack::{Stack, StackedStack}; -use crate::printer::{Indention, MeasureMode}; +use crate::printer::{Indentation, MeasureMode}; use crate::{IndentStyle, InvalidDocumentError, PrintError, PrintResult}; use std::fmt::Debug; use std::num::NonZeroU8; @@ -26,13 +26,13 @@ pub(super) struct StackFrame { /// data structures. Such structures should be stored on the [`PrinterState`] instead. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub(super) struct PrintElementArgs { - indent: Indention, + indent: Indentation, mode: PrintMode, measure_mode: MeasureMode, } impl PrintElementArgs { - pub(crate) fn new(indent: Indention) -> Self { + pub(crate) fn new(indent: Indentation) -> Self { Self { indent, ..Self::default() @@ -47,7 +47,7 @@ impl PrintElementArgs { self.measure_mode } - pub(super) fn indention(self) -> Indention { + pub(super) fn indentation(self) -> Indentation { self.indent } @@ -62,7 +62,7 @@ impl PrintElementArgs { } pub(crate) fn reset_indent(mut self) -> Self { - self.indent = Indention::default(); + self.indent = Indentation::default(); self } @@ -85,7 +85,7 @@ impl PrintElementArgs { impl Default for PrintElementArgs { fn default() -> Self { Self { - indent: Indention::Level(0), + indent: Indentation::Level(0), mode: PrintMode::Expanded, measure_mode: MeasureMode::FirstLine, } diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index 916dc5cad5..853d301d34 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -60,7 +60,7 @@ impl<'a> Printer<'a> { document: &'a Document, indent: u16, ) -> PrintResult { - let indentation = Indention::Level(indent); + let indentation = Indentation::Level(indent); self.state.pending_indent = indentation; let mut stack = PrintCallStack::new(PrintElementArgs::new(indentation)); @@ -135,7 +135,7 @@ impl<'a> Printer<'a> { self.print_char('\n'); } - self.state.pending_indent = args.indention(); + self.state.pending_indent = args.indentation(); } } @@ -883,7 +883,7 @@ struct PrinterState<'a> { pending_source_position: Option, /// The current indentation that should be written before the next text. - pending_indent: Indention, + pending_indent: Indentation, /// Caches if the code up to the next newline has been measured to fit on a single line. /// This is used to avoid re-measuring the same content multiple times. @@ -943,37 +943,37 @@ impl GroupModes { } #[derive(Copy, Clone, Eq, PartialEq, Debug)] -enum Indention { - /// Indent the content by `count` levels by using the indention sequence specified by the printer options. +enum Indentation { + /// Indent the content by `count` levels by using the indentation sequence specified by the printer options. Level(u16), - /// Indent the content by n-`level`s using the indention sequence specified by the printer options and `align` spaces. + /// Indent the content by n-`level`s using the indentation sequence specified by the printer options and `align` spaces. Align { level: u16, align: NonZeroU8 }, } -impl Indention { +impl Indentation { const fn is_empty(self) -> bool { - matches!(self, Indention::Level(0)) + matches!(self, Indentation::Level(0)) } - /// Creates a new indention level with a zero-indent. + /// Creates a new indentation level with a zero-indent. const fn new() -> Self { - Indention::Level(0) + Indentation::Level(0) } - /// Returns the indention level + /// Returns the indentation level fn level(self) -> u16 { match self { - Indention::Level(count) => count, - Indention::Align { level: indent, .. } => indent, + Indentation::Level(count) => count, + Indentation::Align { level: indent, .. } => indent, } } /// Returns the number of trailing align spaces or 0 if none fn align(self) -> u8 { match self { - Indention::Level(_) => 0, - Indention::Align { align, .. } => align.into(), + Indentation::Level(_) => 0, + Indentation::Align { align, .. } => align.into(), } } @@ -985,13 +985,15 @@ impl Indention { /// Keeps any the current value is [`Indent::Align`] and increments the level by one. fn increment_level(self, indent_style: IndentStyle) -> Self { match self { - Indention::Level(count) => Indention::Level(count + 1), + Indentation::Level(count) => Indentation::Level(count + 1), // Increase the indent AND convert the align to an indent - Indention::Align { level, .. } if indent_style.is_tab() => Indention::Level(level + 2), - Indention::Align { + Indentation::Align { level, .. } if indent_style.is_tab() => { + Indentation::Level(level + 2) + } + Indentation::Align { level: indent, align, - } => Indention::Align { + } => Indentation::Align { level: indent + 1, align, }, @@ -1005,23 +1007,23 @@ impl Indention { /// No-op if the level is already zero. fn decrement(self) -> Self { match self { - Indention::Level(level) => Indention::Level(level.saturating_sub(1)), - Indention::Align { level, .. } => Indention::Level(level), + Indentation::Level(level) => Indentation::Level(level.saturating_sub(1)), + Indentation::Align { level, .. } => Indentation::Level(level), } } - /// Adds an `align` of `count` spaces to the current indention. + /// Adds an `align` of `count` spaces to the current indentation. /// /// It increments the `level` value if the current value is [`Indent::IndentAlign`]. fn set_align(self, count: NonZeroU8) -> Self { match self { - Indention::Level(indent_count) => Indention::Align { + Indentation::Level(indent_count) => Indentation::Align { level: indent_count, align: count, }, // Convert the existing align to an indent - Indention::Align { level: indent, .. } => Indention::Align { + Indentation::Align { level: indent, .. } => Indentation::Align { level: indent + 1, align: count, }, @@ -1029,9 +1031,9 @@ impl Indention { } } -impl Default for Indention { +impl Default for Indentation { fn default() -> Self { - Indention::new() + Indentation::new() } } @@ -1191,7 +1193,7 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> { MeasureMode::AllLines | MeasureMode::AllLinesAllowTextOverflow => { // Continue measuring on the next line self.state.line_width = 0; - self.state.pending_indent = args.indention(); + self.state.pending_indent = args.indentation(); } } } @@ -1302,7 +1304,7 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> { // to ensure any trailing comments (that, unfortunately, are attached to the statement and not the expression) // fit too. self.state.line_width = 0; - self.state.pending_indent = unindented.indention(); + self.state.pending_indent = unindented.indentation(); return Ok(self.fits_text(Text::Token(")"), unindented)); } @@ -1615,7 +1617,7 @@ impl From for Fits { /// State used when measuring if a group fits on a single line #[derive(Debug)] struct FitsState { - pending_indent: Indention, + pending_indent: Indentation, has_line_suffix: bool, line_width: u32, } diff --git a/crates/ruff_python_codegen/src/stylist.rs b/crates/ruff_python_codegen/src/stylist.rs index 3c6ccb6cb1..ea37492c2f 100644 --- a/crates/ruff_python_codegen/src/stylist.rs +++ b/crates/ruff_python_codegen/src/stylist.rs @@ -36,7 +36,7 @@ impl<'a> Stylist<'a> { } pub fn from_tokens(tokens: &Tokens, locator: &'a Locator<'a>) -> Self { - let indentation = detect_indention(tokens, locator); + let indentation = detect_indentation(tokens, locator); Self { locator, @@ -60,7 +60,7 @@ fn detect_quote(tokens: &[Token]) -> Quote { Quote::default() } -fn detect_indention(tokens: &[Token], locator: &Locator) -> Indentation { +fn detect_indentation(tokens: &[Token], locator: &Locator) -> Indentation { let indent_range = tokens.iter().find_map(|token| { if matches!(token.kind(), TokenKind::Indent) { Some(token.range()) @@ -204,7 +204,7 @@ x = ( let stylist = Stylist::from_tokens(parsed.tokens(), &locator); assert_eq!(stylist.indentation(), &Indentation(" ".to_string())); - // formfeed indent, see `detect_indention` comment. + // formfeed indent, see `detect_indentation` comment. let contents = r" class FormFeedIndent: def __init__(self, a=[]):