From b2235f95052eb7ebbb485b0259399ab5790228d6 Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 25 Aug 2023 16:13:24 +0200 Subject: [PATCH] Fix tests --- crates/ruff_formatter/src/builders.rs | 48 ++++++++++++------- .../src/format_element/document.rs | 10 ++-- crates/ruff_formatter/src/lib.rs | 3 +- crates/ruff_formatter/src/macros.rs | 6 ++- crates/ruff_python_trivia/src/line_width.rs | 2 +- ruff.schema.json | 4 +- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/crates/ruff_formatter/src/builders.rs b/crates/ruff_formatter/src/builders.rs index 64be00fb39f2f5..de103d069dccd8 100644 --- a/crates/ruff_formatter/src/builders.rs +++ b/crates/ruff_formatter/src/builders.rs @@ -40,7 +40,8 @@ use Tag::*; /// /// Soft line breaks are emitted if the enclosing `Group` doesn't fit on a single line /// ``` -/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -161,7 +162,8 @@ pub const fn empty_line() -> Line { /// /// The printer breaks the lines if the enclosing `Group` doesn't fit on a single line: /// ``` -/// use ruff_formatter::{format_args, format, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format_args, format, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -537,8 +539,9 @@ impl Format for LineSuffixBoundary { /// ## Examples /// /// ```rust +/// use ruff_python_trivia::LineLength; /// use ruff_formatter::prelude::*; -/// use ruff_formatter::{format, write, LineLength}; +/// use ruff_formatter::{format, write}; /// /// #[derive(Debug, Copy, Clone)] /// enum MyLabels { @@ -1038,7 +1041,8 @@ pub fn block_indent(content: &impl Format) -> BlockIndent FormatResult<()> { @@ -1112,7 +1116,8 @@ pub fn soft_block_indent(content: &impl Format) -> BlockIndent /// fit on a single line. Otherwise, just inserts a space. /// /// ``` -/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -1244,7 +1249,8 @@ impl std::fmt::Debug for BlockIndent<'_, Context> { /// Adds line breaks and indents the content if the enclosing group doesn't fit on the line. /// /// ``` -/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -1349,7 +1355,8 @@ pub fn soft_space_or_block_indent(content: &impl Format) -> Bl /// /// The printer breaks the `Group` over multiple lines if its content doesn't fit on a single line /// ``` -/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -1454,7 +1461,8 @@ impl std::fmt::Debug for Group<'_, Context> { /// /// ``` /// # use ruff_formatter::prelude::*; -/// # use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// # use ruff_formatter::{format, format_args, SimpleFormatOptions}; /// /// # fn main() -> FormatResult<()> { /// use ruff_formatter::Formatted; @@ -1583,7 +1591,8 @@ impl std::fmt::Debug for ConditionalGroup<'_, Context> { /// ## Examples /// /// ``` -/// use ruff_formatter::{format, format_args, LineLength}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -1668,7 +1677,8 @@ impl Format for ExpandParent { /// /// Prints the trailing comma for the last array element if the `Group` doesn't fit on a single line /// ``` -/// use ruff_formatter::{format_args, format, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format_args, format, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// use ruff_formatter::printer::PrintWidth; /// @@ -1750,7 +1760,8 @@ where /// /// Omits the trailing comma for the last array element if the `Group` doesn't fit on a single line /// ``` -/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -1812,7 +1823,8 @@ impl IfGroupBreaks<'_, Context> { /// The item `[4]` in this example fits on a single line but the trailing comma should still be printed /// /// ``` - /// use ruff_formatter::{format, format_args, write, LineLength, SimpleFormatOptions}; + /// use ruff_python_trivia::LineLength; + /// use ruff_formatter::{format, format_args, write, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -1915,7 +1927,8 @@ impl std::fmt::Debug for IfGroupBreaks<'_, Context> { /// /// Indent the body of an arrow function if the group wrapping the signature breaks: /// ``` -/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions, write}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args, SimpleFormatOptions, write}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -1945,7 +1958,8 @@ impl std::fmt::Debug for IfGroupBreaks<'_, Context> { /// /// It doesn't add an indent if the group wrapping the signature doesn't break: /// ``` -/// use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions, write}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, format_args, SimpleFormatOptions, write}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -2017,7 +2031,8 @@ impl std::fmt::Debug for IndentIfGroupBreaks<'_, Context> { /// that spans multiple lines. /// /// ``` -/// # use ruff_formatter::{format, format_args, LineLength, SimpleFormatOptions, write}; +/// use ruff_python_trivia::LineLength; +/// # use ruff_formatter::{format, format_args, SimpleFormatOptions, write}; /// # use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -2432,7 +2447,8 @@ impl<'a, Context> BestFitting<'a, Context> { /// ### All Lines /// /// ``` - /// use ruff_formatter::{Formatted, LineLength, format, format_args, SimpleFormatOptions}; + /// use ruff_python_trivia::LineLength; + /// use ruff_formatter::{Formatted, format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { diff --git a/crates/ruff_formatter/src/format_element/document.rs b/crates/ruff_formatter/src/format_element/document.rs index 21457a9359b201..8efa835a260975 100644 --- a/crates/ruff_formatter/src/format_element/document.rs +++ b/crates/ruff_formatter/src/format_element/document.rs @@ -794,7 +794,7 @@ mod tests { soft_block_indent(&format_args![ text("Some longer content"), space(), - text("That should ultimately break"), + text("That should ultimately break for its length"), ]) ])] ) @@ -811,7 +811,7 @@ mod tests { "(", indent([ soft_line_break, - "Some longer content That should ultimately break" + "Some longer content That should ultimately break for its length" ]), soft_line_break ]) @@ -837,7 +837,7 @@ mod tests { #[test] fn display_elements_with_source_text_slice() { - let source_code = "Some longer content\nThat should ultimately break"; + let source_code = "Some longer content\nThat should ultimately break for its length"; let formatted = format!( SimpleFormatContext::default().with_source_code(source_code), [format_with(|f| { @@ -852,7 +852,7 @@ mod tests { ), space(), source_text_slice( - TextRange::at(TextSize::new(20), TextSize::new(28)), + TextRange::at(TextSize::new(20), TextSize::new(43)), ContainsNewlines::No ), ]) @@ -871,7 +871,7 @@ mod tests { "(", indent([ soft_line_break, - "Some longer content That should ultimately break" + "Some longer content That should ultimately break for its length" ]), soft_line_break ]) diff --git a/crates/ruff_formatter/src/lib.rs b/crates/ruff_formatter/src/lib.rs index bd8c5bcc78bc80..b333466a7183af 100644 --- a/crates/ruff_formatter/src/lib.rs +++ b/crates/ruff_formatter/src/lib.rs @@ -355,7 +355,8 @@ pub type FormatResult = Result; /// Implementing `Format` for a custom struct /// /// ``` -/// use ruff_formatter::{format, write, IndentStyle, LineLength}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{format, write, IndentStyle}; /// use ruff_formatter::prelude::*; /// use ruff_text_size::TextSize; /// diff --git a/crates/ruff_formatter/src/macros.rs b/crates/ruff_formatter/src/macros.rs index 62fe4a5e60b6dd..20c82e9595f4f1 100644 --- a/crates/ruff_formatter/src/macros.rs +++ b/crates/ruff_formatter/src/macros.rs @@ -153,7 +153,8 @@ macro_rules! format { /// ## Examples /// /// ``` -/// use ruff_formatter::{Formatted, LineLength, format, format_args, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{Formatted, format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { @@ -241,7 +242,8 @@ macro_rules! format { /// ### Enclosing group with `should_expand: true` /// /// ``` -/// use ruff_formatter::{Formatted, LineLength, format, format_args, SimpleFormatOptions}; +/// use ruff_python_trivia::LineLength; +/// use ruff_formatter::{Formatted, format, format_args, SimpleFormatOptions}; /// use ruff_formatter::prelude::*; /// /// # fn main() -> FormatResult<()> { diff --git a/crates/ruff_python_trivia/src/line_width.rs b/crates/ruff_python_trivia/src/line_width.rs index c5ad3a18e1f979..8fc4ce740e38b2 100644 --- a/crates/ruff_python_trivia/src/line_width.rs +++ b/crates/ruff_python_trivia/src/line_width.rs @@ -5,7 +5,7 @@ use std::hash::Hasher; use std::num::ParseIntError; use std::str::FromStr; -/// Validated value for the `line-length` option +/// The length of a line of text that is considered too long. /// /// The allowed range of values is 1..=320 #[derive(Clone, Copy, Debug, Eq, PartialEq)] diff --git a/ruff.schema.json b/ruff.schema.json index beb32b04ede191..9b97ac374b62b6 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1386,9 +1386,9 @@ "additionalProperties": false }, "LineLength": { - "description": "The length of a line of text that is considered too long.", + "description": "The length of a line of text that is considered too long.\n\nThe allowed range of values is 1..=320", "type": "integer", - "format": "uint", + "format": "uint16", "minimum": 0.0 }, "McCabeOptions": {