From f3256b87b95a96894b9566402e68ab3a94658e75 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 23 Oct 2024 09:01:02 +0200 Subject: [PATCH] Fix bug with implicit concatenated string preceded by comment --- .../join_implicit_concatenated_string.py | 10 ++++++++++ .../src/expression/expr_string_literal.rs | 3 +-- .../src/string/implicit.rs | 1 - ..._join_implicit_concatenated_string.py.snap | 20 +++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/join_implicit_concatenated_string.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/join_implicit_concatenated_string.py index 729725516c97f..21f578b2c382f 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/join_implicit_concatenated_string.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/join_implicit_concatenated_string.py @@ -280,3 +280,13 @@ def byte_string_in_docstring_position(): def f_string_in_docstring_position(): f" don't trim the" "f-string literal " + + +############################################################################## +# Regressions +############################################################################## + +LEEEEEEEEEEEEEEEEEEEEEEFT = RRRRRRRRIIIIIIIIIIIIGGGGGHHHT | { + "entityNameeeeeeeeeeeeeeeeee", # comment must be long enough to + "some long implicit concatenated string" "that should join" +} diff --git a/crates/ruff_python_formatter/src/expression/expr_string_literal.rs b/crates/ruff_python_formatter/src/expression/expr_string_literal.rs index 4fb6bdeb624a4..c63df53b6749f 100644 --- a/crates/ruff_python_formatter/src/expression/expr_string_literal.rs +++ b/crates/ruff_python_formatter/src/expression/expr_string_literal.rs @@ -40,9 +40,8 @@ impl FormatNodeRule for FormatExprStringLiteral { } } - in_parentheses_only_group(&FormatImplicitConcatenatedString::new(item)) + in_parentheses_only_group(&FormatImplicitConcatenatedString::new(item)).fmt(f) } - .fmt(f), } } } diff --git a/crates/ruff_python_formatter/src/string/implicit.rs b/crates/ruff_python_formatter/src/string/implicit.rs index 329738654d12f..1a7ad6f2249db 100644 --- a/crates/ruff_python_formatter/src/string/implicit.rs +++ b/crates/ruff_python_formatter/src/string/implicit.rs @@ -92,7 +92,6 @@ impl Format> for FormatImplicitConcatenatedStringExpanded<'_ let part_comments = comments.leading_dangling_trailing(&part); joiner.entry(&format_args![ - line_suffix_boundary(), leading_comments(part_comments.leading), format_part, trailing_comments(part_comments.trailing) diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__join_implicit_concatenated_string.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__join_implicit_concatenated_string.py.snap index 4b25932ab635f..3ba3b7279463d 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__join_implicit_concatenated_string.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__join_implicit_concatenated_string.py.snap @@ -286,6 +286,16 @@ def byte_string_in_docstring_position(): def f_string_in_docstring_position(): f" don't trim the" "f-string literal " + + +############################################################################## +# Regressions +############################################################################## + +LEEEEEEEEEEEEEEEEEEEEEEFT = RRRRRRRRIIIIIIIIIIIIGGGGGHHHT | { + "entityNameeeeeeeeeeeeeeeeee", # comment must be long enough to + "some long implicit concatenated string" "that should join" +} ``` ## Outputs @@ -651,4 +661,14 @@ def byte_string_in_docstring_position(): def f_string_in_docstring_position(): f" don't trim thef-string literal " + + +############################################################################## +# Regressions +############################################################################## + +LEEEEEEEEEEEEEEEEEEEEEEFT = RRRRRRRRIIIIIIIIIIIIGGGGGHHHT | { + "entityNameeeeeeeeeeeeeeeeee", # comment must be long enough to + "some long implicit concatenated stringthat should join", +} ```