mirror of https://github.com/astral-sh/ruff
Revert "try only dangling"
This reverts commit 4c8540ede798f544a895225b541f46552649fd7b.
This commit is contained in:
parent
1cf5eff9f4
commit
f49fda317e
|
|
@ -1861,12 +1861,17 @@ fn handle_unary_op_comment<'a>(
|
||||||
| SimpleTokenKind::Plus
|
| SimpleTokenKind::Plus
|
||||||
| SimpleTokenKind::Minus
|
| SimpleTokenKind::Minus
|
||||||
)));
|
)));
|
||||||
let lparen = tokenizer.find(|token| token.kind == SimpleTokenKind::LParen);
|
let lparen_start = tokenizer
|
||||||
if lparen.is_none()
|
.find(|token| token.kind == SimpleTokenKind::LParen)
|
||||||
|
.map(|lparen| lparen.start());
|
||||||
|
let up_to = lparen_start.unwrap_or(unary_op.operand.start());
|
||||||
|
if lparen_start.is_none()
|
||||||
&& comment.end() < unary_op.operand.start()
|
&& comment.end() < unary_op.operand.start()
|
||||||
&& comment.line_position().is_end_of_line()
|
&& comment.line_position().is_end_of_line()
|
||||||
{
|
{
|
||||||
CommentPlacement::dangling(unary_op, comment)
|
CommentPlacement::dangling(unary_op, comment)
|
||||||
|
} else if comment.end() < up_to {
|
||||||
|
CommentPlacement::leading(unary_op, comment)
|
||||||
} else {
|
} else {
|
||||||
CommentPlacement::Default(comment)
|
CommentPlacement::Default(comment)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -254,35 +254,31 @@ if +(
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not
|
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
~
|
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
-
|
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
+
|
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
@ -291,8 +287,8 @@ if (
|
||||||
|
|
||||||
if (
|
if (
|
||||||
# unary comment
|
# unary comment
|
||||||
not # operand comment
|
# operand comment
|
||||||
(
|
not (
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
|
@ -367,9 +363,8 @@ if (
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not
|
|
||||||
# comment
|
# comment
|
||||||
a
|
not a
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -389,9 +384,9 @@ if True:
|
||||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7448
|
# Regression test for: https://github.com/astral-sh/ruff/issues/7448
|
||||||
x = (
|
x = (
|
||||||
# a
|
# a
|
||||||
not # b
|
# b
|
||||||
# c
|
# c
|
||||||
( # d
|
not ( # d
|
||||||
# e
|
# e
|
||||||
True
|
True
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
---
|
---
|
||||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/parentheses/expression_parentheses_comments.py
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/parentheses/expression_parentheses_comments.py
|
||||||
|
snapshot_kind: text
|
||||||
---
|
---
|
||||||
## Input
|
## Input
|
||||||
```python
|
```python
|
||||||
|
|
@ -178,13 +179,13 @@ nested_parentheses4 = [
|
||||||
|
|
||||||
x = (
|
x = (
|
||||||
# unary comment
|
# unary comment
|
||||||
not # in-between comment
|
# in-between comment
|
||||||
(
|
not (
|
||||||
# leading inner
|
# leading inner
|
||||||
"a"
|
"a"
|
||||||
),
|
),
|
||||||
not # in-between comment
|
# in-between comment
|
||||||
(
|
not (
|
||||||
# leading inner
|
# leading inner
|
||||||
"b"
|
"b"
|
||||||
),
|
),
|
||||||
|
|
@ -193,8 +194,8 @@ x = (
|
||||||
"c"
|
"c"
|
||||||
),
|
),
|
||||||
# 1
|
# 1
|
||||||
not # 2
|
# 2
|
||||||
( # 3
|
not ( # 3
|
||||||
# 4
|
# 4
|
||||||
"d"
|
"d"
|
||||||
),
|
),
|
||||||
|
|
@ -202,8 +203,8 @@ x = (
|
||||||
|
|
||||||
if (
|
if (
|
||||||
# unary comment
|
# unary comment
|
||||||
not # in-between comment
|
# in-between comment
|
||||||
(
|
not (
|
||||||
# leading inner
|
# leading inner
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue