From f18a1f70de329a2700f16a4bf4875b911acf88d1 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 26 Jun 2023 14:15:55 +0200 Subject: [PATCH] Add tests for skip magic trailing comma ## Summary This PR adds tests that verify that the magic trailing comma is not respected if disabled in the formatter options. Our test setup now allows to create a `.options.json` file that contains an array of configurations that should be tested. ## Test Plan It's all about tests :) --- Cargo.lock | 3 +- crates/ruff_formatter/src/lib.rs | 24 ++--- crates/ruff_python_formatter/Cargo.toml | 17 +++- .../skip_magic_trailing_comma.options.json | 8 ++ .../ruff/skip_magic_trailing_comma.py | 22 +++++ crates/ruff_python_formatter/src/builders.rs | 2 +- crates/ruff_python_formatter/src/options.rs | 38 +++++++- .../ruff_python_formatter/tests/fixtures.rs | 91 +++++++++++++++---- .../format@expression__attribute.py.snap | 3 +- .../format@expression__binary.py.snap | 3 +- ...rmat@expression__boolean_operation.py.snap | 3 +- .../format@expression__compare.py.snap | 3 +- .../snapshots/format@expression__dict.py.snap | 3 +- .../snapshots/format@expression__list.py.snap | 3 +- .../format@expression__slice.py.snap | 3 +- .../format@expression__string.py.snap | 3 +- .../format@expression__tuple.py.snap | 3 +- .../format@expression__unary.py.snap | 3 +- .../format@skip_magic_trailing_comma.py.snap | 88 ++++++++++++++++++ .../format@statement__assign.py.snap | 3 +- .../snapshots/format@statement__break.py.snap | 3 +- ...format@statement__class_definition.py.snap | 3 +- .../snapshots/format@statement__for.py.snap | 3 +- .../format@statement__function.py.snap | 3 +- .../snapshots/format@statement__if.py.snap | 3 +- .../snapshots/format@statement__while.py.snap | 3 +- .../tests/snapshots/format@trivia.py.snap | 3 +- 27 files changed, 268 insertions(+), 79 deletions(-) create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.options.json create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.py create mode 100644 crates/ruff_python_formatter/tests/snapshots/format@skip_magic_trailing_comma.py.snap diff --git a/Cargo.lock b/Cargo.lock index 91d79253be..5dd0ae65ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2065,8 +2065,9 @@ dependencies = [ "ruff_text_size", "rustc-hash", "rustpython-parser", + "serde", + "serde_json", "similar", - "test-case", ] [[package]] diff --git a/crates/ruff_formatter/src/lib.rs b/crates/ruff_formatter/src/lib.rs index 4e40deb77d..5c99ebba87 100644 --- a/crates/ruff_formatter/src/lib.rs +++ b/crates/ruff_formatter/src/lib.rs @@ -59,10 +59,8 @@ use std::num::ParseIntError; use std::str::FromStr; #[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[derive(Default)] pub enum IndentStyle { /// Tab @@ -112,10 +110,8 @@ impl std::fmt::Display for IndentStyle { /// /// The allowed range of values is 1..=320 #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct LineWidth(u16); impl LineWidth { @@ -278,10 +274,8 @@ impl FormatOptions for SimpleFormatOptions { /// Lightweight sourcemap marker between source and output tokens #[derive(Debug, Copy, Clone, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct SourceMarker { /// Position of the marker in the original source pub source: TextSize, @@ -340,10 +334,8 @@ where pub type PrintResult = Result; #[derive(Debug, Clone, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Printed { code: String, range: Option, diff --git a/crates/ruff_python_formatter/Cargo.toml b/crates/ruff_python_formatter/Cargo.toml index 91ba277792..e781baf3ef 100644 --- a/crates/ruff_python_formatter/Cargo.toml +++ b/crates/ruff_python_formatter/Cargo.toml @@ -25,8 +25,23 @@ itertools = { workspace = true } once_cell = { workspace = true } rustc-hash = { workspace = true } rustpython-parser = { workspace = true } +serde = { workspace = true, optional = true } [dev-dependencies] +ruff_formatter = { path = "../ruff_formatter", features = ["serde"]} + insta = { workspace = true, features = ["glob"] } -test-case = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } similar = { workspace = true } + +[[test]] +name = "ruff_python_formatter_fixtures" +path = "tests/fixtures.rs" +test = true +required-features = [ "serde" ] + + +[features] +serde = ["dep:serde", "ruff_formatter/serde"] +default = ["serde"] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.options.json b/crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.options.json new file mode 100644 index 0000000000..f842b9e3ff --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.options.json @@ -0,0 +1,8 @@ +[ + { + "magic_trailing_comma": "respect" + }, + { + "magic_trailing_comma": "ignore" + } +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.py new file mode 100644 index 0000000000..8f4c58789a --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.py @@ -0,0 +1,22 @@ +( + "First entry", + "Second entry", + "last with trailing comma", +) + +( + "First entry", + "Second entry", + "last without trailing comma" +) + +( + "First entry", + "Second entry", + "third entry", + "fourth entry", + "fifth entry", + "sixt entry", + "seventh entry", + "eigth entry", +) diff --git a/crates/ruff_python_formatter/src/builders.rs b/crates/ruff_python_formatter/src/builders.rs index db52ed9b91..d3b64ce34b 100644 --- a/crates/ruff_python_formatter/src/builders.rs +++ b/crates/ruff_python_formatter/src/builders.rs @@ -220,7 +220,7 @@ impl<'fmt, 'ast, 'buf> JoinCommaSeparatedBuilder<'fmt, 'ast, 'buf> { if let Some(last_end) = self.last_end.take() { if_group_breaks(&text(",")).fmt(self.fmt)?; - if self.fmt.options().magic_trailing_comma().is_preserve() + if self.fmt.options().magic_trailing_comma().is_respect() && matches!( first_non_trivia_token(last_end, self.fmt.context().contents()), Some(Token { diff --git a/crates/ruff_python_formatter/src/options.rs b/crates/ruff_python_formatter/src/options.rs index e7302a69df..e886a30b60 100644 --- a/crates/ruff_python_formatter/src/options.rs +++ b/crates/ruff_python_formatter/src/options.rs @@ -2,6 +2,11 @@ use ruff_formatter::printer::{LineEnding, PrinterOptions}; use ruff_formatter::{FormatOptions, IndentStyle, LineWidth}; #[derive(Clone, Debug)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(default) +)] pub struct PyFormatOptions { /// Specifies the indent style: /// * Either a tab @@ -9,6 +14,7 @@ pub struct PyFormatOptions { indent_style: IndentStyle, /// The preferred line width at which the formatter should wrap lines. + #[cfg_attr(feature = "serde", serde(default = "default_line_width"))] line_width: LineWidth, /// The preferred quote style to use (single vs double quotes). @@ -18,6 +24,10 @@ pub struct PyFormatOptions { magic_trailing_comma: MagicTrailingComma, } +fn default_line_width() -> LineWidth { + LineWidth::try_from(88).unwrap() +} + impl PyFormatOptions { pub fn magic_trailing_comma(&self) -> MagicTrailingComma { self.magic_trailing_comma @@ -36,6 +46,16 @@ impl PyFormatOptions { self.magic_trailing_comma = trailing_comma; self } + + pub fn with_indent_style(&mut self, indent_style: IndentStyle) -> &mut Self { + self.indent_style = indent_style; + self + } + + pub fn with_line_width(&mut self, line_width: LineWidth) -> &mut Self { + self.line_width = line_width; + self + } } impl FormatOptions for PyFormatOptions { @@ -69,6 +89,11 @@ impl Default for PyFormatOptions { } #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "kebab-case") +)] pub enum QuoteStyle { Single, #[default] @@ -105,14 +130,19 @@ impl TryFrom for QuoteStyle { } #[derive(Copy, Clone, Debug, Default)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "kebab-case") +)] pub enum MagicTrailingComma { #[default] - Preserve, - Skip, + Respect, + Ignore, } impl MagicTrailingComma { - pub const fn is_preserve(self) -> bool { - matches!(self, Self::Preserve) + pub const fn is_respect(self) -> bool { + matches!(self, Self::Respect) } } diff --git a/crates/ruff_python_formatter/tests/fixtures.rs b/crates/ruff_python_formatter/tests/fixtures.rs index 34e41229a9..43a94051e7 100644 --- a/crates/ruff_python_formatter/tests/fixtures.rs +++ b/crates/ruff_python_formatter/tests/fixtures.rs @@ -1,16 +1,18 @@ +use ruff_formatter::FormatOptions; use ruff_python_formatter::{format_module, PyFormatOptions}; use similar::TextDiff; use std::fmt::{Formatter, Write}; -use std::fs; +use std::io::BufReader; use std::path::Path; +use std::{fmt, fs}; #[test] fn black_compatibility() { let test_file = |input_path: &Path| { let content = fs::read_to_string(input_path).unwrap(); - let printed = - format_module(&content, PyFormatOptions::default()).expect("Formatting to succeed"); + let options = PyFormatOptions::default(); + let printed = format_module(&content, options.clone()).expect("Formatting to succeed"); let expected_path = input_path.with_extension("py.expect"); let expected_output = fs::read_to_string(&expected_path) @@ -18,7 +20,7 @@ fn black_compatibility() { let formatted_code = printed.as_code(); - ensure_stability_when_formatting_twice(formatted_code); + ensure_stability_when_formatting_twice(formatted_code, options); if formatted_code == expected_output { // Black and Ruff formatting matches. Delete any existing snapshot files because the Black output @@ -66,7 +68,7 @@ fn black_compatibility() { write!(snapshot, "{}", CodeFrame::new("diff", &diff)).unwrap(); write!(snapshot, "{}", Header::new("Ruff Output")).unwrap(); - write!(snapshot, "{}", CodeFrame::new("py", formatted_code)).unwrap(); + write!(snapshot, "{}", CodeFrame::new("py", &formatted_code)).unwrap(); write!(snapshot, "{}", Header::new("Black Output")).unwrap(); write!(snapshot, "{}", CodeFrame::new("py", &expected_output)).unwrap(); @@ -89,21 +91,52 @@ fn format() { let test_file = |input_path: &Path| { let content = fs::read_to_string(input_path).unwrap(); - let printed = - format_module(&content, PyFormatOptions::default()).expect("Formatting to succeed"); + let options = PyFormatOptions::default(); + let printed = format_module(&content, options.clone()).expect("Formatting to succeed"); let formatted_code = printed.as_code(); - ensure_stability_when_formatting_twice(formatted_code); + ensure_stability_when_formatting_twice(formatted_code, options); - let snapshot = format!( - r#"## Input -{} + let mut snapshot = format!("## Input\n{}", CodeFrame::new("py", &content)); -## Output -{}"#, - CodeFrame::new("py", &content), - CodeFrame::new("py", formatted_code) - ); + let options_path = input_path.with_extension("options.json"); + if let Ok(options_file) = fs::File::open(options_path) { + let reader = BufReader::new(options_file); + let options: Vec = + serde_json::from_reader(reader).expect("Options to be a valid Json file"); + + writeln!(snapshot, "## Outputs").unwrap(); + + for (i, options) in options.into_iter().enumerate() { + let printed = + format_module(&content, options.clone()).expect("Formatting to succeed"); + let formatted_code = printed.as_code(); + + ensure_stability_when_formatting_twice(formatted_code, options.clone()); + + writeln!( + snapshot, + "### Output {}\n{}{}", + i + 1, + CodeFrame::new("", &DisplayPyOptions(&options)), + CodeFrame::new("py", &formatted_code) + ) + .unwrap(); + } + } else { + let options = PyFormatOptions::default(); + let printed = format_module(&content, options.clone()).expect("Formatting to succeed"); + let formatted_code = printed.as_code(); + + ensure_stability_when_formatting_twice(formatted_code, options); + + writeln!( + snapshot, + "## Output\n{}", + CodeFrame::new("py", &formatted_code) + ) + .unwrap(); + } insta::with_settings!({ omit_expression => true, @@ -118,8 +151,8 @@ fn format() { } /// Format another time and make sure that there are no changes anymore -fn ensure_stability_when_formatting_twice(formatted_code: &str) { - let reformatted = match format_module(formatted_code, PyFormatOptions::default()) { +fn ensure_stability_when_formatting_twice(formatted_code: &str, options: PyFormatOptions) { + let reformatted = match format_module(formatted_code, options) { Ok(reformatted) => reformatted, Err(err) => { panic!( @@ -170,11 +203,11 @@ impl std::fmt::Display for Header<'_> { struct CodeFrame<'a> { language: &'a str, - code: &'a str, + code: &'a dyn std::fmt::Display, } impl<'a> CodeFrame<'a> { - fn new(language: &'a str, code: &'a str) -> Self { + fn new(language: &'a str, code: &'a dyn std::fmt::Display) -> Self { Self { language, code } } } @@ -187,3 +220,21 @@ impl std::fmt::Display for CodeFrame<'_> { writeln!(f) } } + +struct DisplayPyOptions<'a>(&'a PyFormatOptions); + +impl fmt::Display for DisplayPyOptions<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + writeln!( + f, + r#"indent-style = {indent_style} +line-width = {line_width} +quote-style = {quote_style:?} +magic-trailing-comma = {magic_trailing_comma:?}"#, + indent_style = self.0.indent_style(), + line_width = self.0.line_width().value(), + quote_style = self.0.quote_style(), + magic_trailing_comma = self.0.magic_trailing_comma() + ) + } +} diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__attribute.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__attribute.py.snap index a1871573c8..77901f7b5c 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__attribute.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__attribute.py.snap @@ -109,8 +109,6 @@ x53 = ( ``` - - ## Output ```py NOT_YET_IMPLEMENTED_StmtImportFrom @@ -196,3 +194,4 @@ x53 = a.askjdfahdlskjflsajfadhsaf.akjdsf.aksjdlfadhaljsashdfljaf.askjdflhasfdlas ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__binary.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__binary.py.snap index a84c4a7201..84c5af2a92 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__binary.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__binary.py.snap @@ -200,8 +200,6 @@ for user_id in set(target_user_ids) - {u.user_id for u in updates}: updates.append(UserPresenceState.default(user_id)) ``` - - ## Output ```py ( @@ -447,3 +445,4 @@ for ( ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__boolean_operation.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__boolean_operation.py.snap index 0b98b8df25..ab8e33067f 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__boolean_operation.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__boolean_operation.py.snap @@ -70,8 +70,6 @@ if ( pass ``` - - ## Output ```py if ( @@ -141,3 +139,4 @@ if ( ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__compare.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__compare.py.snap index 34e1cfbb3f..3e5eab9002 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__compare.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__compare.py.snap @@ -67,8 +67,6 @@ return 1 == 2 and ( ] ``` - - ## Output ```py a == b @@ -187,3 +185,4 @@ return ( ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__dict.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__dict.py.snap index 52a5965a90..25a854128c 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__dict.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__dict.py.snap @@ -64,8 +64,6 @@ a = { } ``` - - ## Output ```py # before @@ -131,3 +129,4 @@ a = { ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__list.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__list.py.snap index 892d93b62e..8930e0036c 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__list.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__list.py.snap @@ -16,8 +16,6 @@ a3 = [ ] ``` - - ## Output ```py # Dangling comment placement in empty lists @@ -33,3 +31,4 @@ a3 = [ ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__slice.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__slice.py.snap index e316dd5218..ffc644c26b 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__slice.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__slice.py.snap @@ -88,8 +88,6 @@ e202 = "e"[a() :: a()] e210 = "e"[a() : 1 :] ``` - - ## Output ```py # Handle comments both when lower and upper exist and when they don't @@ -175,3 +173,4 @@ e210 = "e"[NOT_IMPLEMENTED_call() : 1 :] ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap index 4a2e6ed032..7943becf02 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__string.py.snap @@ -58,8 +58,6 @@ String \"\"\" ''' ``` - - ## Output ```py "' test" @@ -117,3 +115,4 @@ String \"\"\" ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__tuple.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__tuple.py.snap index 2ddb3cd9ad..39b0d747e8 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__tuple.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__tuple.py.snap @@ -65,8 +65,6 @@ h2 = ((((1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurp h3 = 1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq" ``` - - ## Output ```py # Non-wrapping parentheses checks @@ -264,3 +262,4 @@ h3 = ( ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__unary.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__unary.py.snap index f461d88180..69feb3de88 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__unary.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__unary.py.snap @@ -144,8 +144,6 @@ if not \ pass ``` - - ## Output ```py if ( @@ -300,3 +298,4 @@ if not a: ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@skip_magic_trailing_comma.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@skip_magic_trailing_comma.py.snap new file mode 100644 index 0000000000..e035e69a1c --- /dev/null +++ b/crates/ruff_python_formatter/tests/snapshots/format@skip_magic_trailing_comma.py.snap @@ -0,0 +1,88 @@ +--- +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.py +--- +## Input +```py +( + "First entry", + "Second entry", + "last with trailing comma", +) + +( + "First entry", + "Second entry", + "last without trailing comma" +) + +( + "First entry", + "Second entry", + "third entry", + "fourth entry", + "fifth entry", + "sixt entry", + "seventh entry", + "eigth entry", +) +``` + +## Outputs +### Output 1 +``` +indent-style = Spaces, size: 4 +line-width = 88 +quote-style = Double +magic-trailing-comma = Respect +``` + +```py +( + "First entry", + "Second entry", + "last with trailing comma", +) + +("First entry", "Second entry", "last without trailing comma") + +( + "First entry", + "Second entry", + "third entry", + "fourth entry", + "fifth entry", + "sixt entry", + "seventh entry", + "eigth entry", +) +``` + + +### Output 2 +``` +indent-style = Spaces, size: 4 +line-width = 88 +quote-style = Double +magic-trailing-comma = Ignore +``` + +```py +("First entry", "Second entry", "last with trailing comma") + +("First entry", "Second entry", "last without trailing comma") + +( + "First entry", + "Second entry", + "third entry", + "fourth entry", + "fifth entry", + "sixt entry", + "seventh entry", + "eigth entry", +) +``` + + + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap index 4d02cf905c..efcd0cca34 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap @@ -16,8 +16,6 @@ a2 = ( a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfal = 1 ``` - - ## Output ```py # break left hand side @@ -31,3 +29,4 @@ a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakj ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__break.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__break.py.snap index d48901046e..1cffa28bec 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__break.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__break.py.snap @@ -11,8 +11,6 @@ while True: # block comment # post comment ``` - - ## Output ```py # leading comment @@ -23,3 +21,4 @@ while True: # block comment ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__class_definition.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__class_definition.py.snap index 49aa2a4879..3fbc4be1a5 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__class_definition.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__class_definition.py.snap @@ -42,8 +42,6 @@ class Test(Aaaa): # trailing comment pass ``` - - ## Output ```py class Test( @@ -95,3 +93,4 @@ class Test(Aaaa): # trailing comment ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__for.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__for.py.snap index a240652d9c..b350ab75f4 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__for.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__for.py.snap @@ -40,8 +40,6 @@ for x in (): # type: int ... ``` - - ## Output ```py for x in y: # trailing test comment @@ -85,3 +83,4 @@ for x in (): # type: int ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap index 00c72398e5..341956733f 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap @@ -239,8 +239,6 @@ def f42( pass ``` - - ## Output ```py # Dangling comments @@ -516,3 +514,4 @@ def f42( ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__if.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__if.py.snap index 6292de6914..9bbe6803f2 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__if.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__if.py.snap @@ -79,8 +79,6 @@ else: # Comment pass ``` - - ## Output ```py if x == y: # trailing if condition @@ -158,3 +156,4 @@ else: # Comment ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__while.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__while.py.snap index 799424b4ea..3aa590915d 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__while.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__while.py.snap @@ -36,8 +36,6 @@ while ( print("Do something") ``` - - ## Output ```py while 34: # trailing test comment @@ -74,3 +72,4 @@ while ( ``` + diff --git a/crates/ruff_python_formatter/tests/snapshots/format@trivia.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@trivia.py.snap index 773e564e68..e9c3d37c5b 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@trivia.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@trivia.py.snap @@ -38,8 +38,6 @@ while b == 20: e = 50 # one empty line before ``` - - ## Output ```py # Removes the line above @@ -79,3 +77,4 @@ e = 50 # one empty line before ``` +