mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 13:05:06 +00:00
Improve comments around Arguments
handling in classes (#6310)
## Summary Based on the confusion here: https://github.com/astral-sh/ruff/pull/6274#discussion_r1282754515. I looked into moving this logic into `placement.rs`, but I think it's trickier than it may appear.
This commit is contained in:
parent
2fa508793f
commit
b3f3529499
1 changed files with 26 additions and 6 deletions
|
@ -64,28 +64,48 @@ impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
|
|||
}
|
||||
|
||||
if let Some(arguments) = arguments.as_deref() {
|
||||
// Drop empty parentheses, e.g., in:
|
||||
// Drop empty the arguments node entirely (i.e., remove the parentheses) if it is empty,
|
||||
// e.g., given:
|
||||
// ```python
|
||||
// class A():
|
||||
// ...
|
||||
// ```
|
||||
//
|
||||
// However, preserve any dangling end-of-line comments, e.g., in:
|
||||
// Format as:
|
||||
// ```python
|
||||
// class A:
|
||||
// ...
|
||||
// ```
|
||||
//
|
||||
// However, preserve any dangling end-of-line comments, e.g., given:
|
||||
// ```python
|
||||
// class A( # comment
|
||||
// ):
|
||||
// ...
|
||||
//
|
||||
// If the arguments contain any dangling own-line comments, we retain the parentheses,
|
||||
// e.g., in:
|
||||
// Format as:
|
||||
// ```python
|
||||
// class A: # comment
|
||||
// ...
|
||||
// ```
|
||||
//
|
||||
// However, the arguments contain any dangling own-line comments, we retain the
|
||||
// parentheses, e.g., given:
|
||||
// ```python
|
||||
// class A( # comment
|
||||
// # comment
|
||||
// ):
|
||||
// ...
|
||||
// ```
|
||||
if arguments.args.is_empty()
|
||||
&& arguments.keywords.is_empty()
|
||||
//
|
||||
// Format as:
|
||||
// ```python
|
||||
// class A( # comment
|
||||
// # comment
|
||||
// ):
|
||||
// ...
|
||||
// ```
|
||||
if arguments.is_empty()
|
||||
&& comments
|
||||
.dangling_comments(arguments)
|
||||
.iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue