mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 21:43:52 +00:00
Fix panic with empty attribute inner comment (#6332)
Fixes https://github.com/astral-sh/ruff/issues/6181
This commit is contained in:
parent
a48d16e025
commit
fe97a2a302
3 changed files with 20 additions and 6 deletions
|
@ -106,4 +106,6 @@ x6 = (
|
||||||
a.b
|
a.b
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# regression: https://github.com/astral-sh/ruff/issues/6181
|
||||||
|
(#
|
||||||
|
()).a
|
||||||
|
|
|
@ -998,10 +998,14 @@ fn handle_attribute_comment<'a>(
|
||||||
comment: DecoratedComment<'a>,
|
comment: DecoratedComment<'a>,
|
||||||
attribute: &'a ast::ExprAttribute,
|
attribute: &'a ast::ExprAttribute,
|
||||||
) -> CommentPlacement<'a> {
|
) -> CommentPlacement<'a> {
|
||||||
debug_assert!(
|
if comment.preceding_node().is_none() {
|
||||||
comment.preceding_node().is_some(),
|
// ```text
|
||||||
"The enclosing node an attribute expression, expected to be at least after the name"
|
// ( value) . attr
|
||||||
);
|
// ^^^^ we're in this range
|
||||||
|
// ```
|
||||||
|
|
||||||
|
return CommentPlacement::leading(attribute.value.as_ref(), comment);
|
||||||
|
}
|
||||||
|
|
||||||
// ```text
|
// ```text
|
||||||
// value . attr
|
// value . attr
|
||||||
|
|
|
@ -112,7 +112,9 @@ x6 = (
|
||||||
a.b
|
a.b
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# regression: https://github.com/astral-sh/ruff/issues/6181
|
||||||
|
(#
|
||||||
|
()).a
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -200,6 +202,12 @@ x6 = (
|
||||||
# Check assumption with enclosing nodes
|
# Check assumption with enclosing nodes
|
||||||
a.b
|
a.b
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# regression: https://github.com/astral-sh/ruff/issues/6181
|
||||||
|
(
|
||||||
|
#
|
||||||
|
()
|
||||||
|
).a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue