diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ellipsis.pyi b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ellipsis.pyi index 499ef0aacc0c7..aa693c3443edd 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ellipsis.pyi +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ellipsis.pyi @@ -68,6 +68,10 @@ with True: with True: ... # comment +with True: + ... + # comment + match x: case 1: ... @@ -99,4 +103,4 @@ try: except: ... # comment finally: - ... # comment \ No newline at end of file + ... # comment diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index d8001cebe3c43..b60474dbd0043 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -511,7 +511,9 @@ pub(crate) fn contains_only_an_ellipsis(body: &[Stmt], comments: &Comments) -> b let [node] = body else { return false; }; - value.is_ellipsis_literal_expr() && !comments.has_leading(node) + value.is_ellipsis_literal_expr() + && !comments.has_leading(node) + && !comments.has_trailing_own_line(node) } _ => false, } diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__ellipsis.pyi.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__ellipsis.pyi.snap index 756fbff9f8e34..89bab19aef384 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__ellipsis.pyi.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__ellipsis.pyi.snap @@ -74,6 +74,10 @@ with True: with True: ... # comment +with True: + ... + # comment + match x: case 1: ... @@ -105,7 +109,8 @@ try: except: ... # comment finally: - ... # comment``` + ... # comment +``` ## Output ```python @@ -163,6 +168,10 @@ with True: with True: ... # comment +with True: + ... + # comment + match x: case 1: ... case 2: