-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatter: Add EmptyWithDanglingComments helper #5951
Conversation
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
PR Check ResultsBenchmarkLinux
Windows
|
/// ``` | ||
/// These comments are dangling because they can't be assigned to any element inside as they would | ||
/// in all other cases. | ||
pub(crate) fn empty_with_dangling_comments( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe empty_parenthesized_with_dangling_comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this, we need to figure out a better nomenclature for (
vs. {(
, [
, {
}
**Summary** Add a `EmptyWithDanglingComments` format helper that formats comments inside empty parentheses, brackets or curly braces. Previously, this was implemented separately, and partially incorrectly, for each use case. Empty `()`, `[]` and `{}` are special because there can be dangling comments, and they can be in two positions: ```python x = [ # end-of-line # own line ] ``` These comments are dangling because they can't be assigned to any element inside as they would in all other cases. **Test Plan** Added a regression test. 85 (from previously 89) instances of unstable formatting remaining. ``` $ cargo run --bin ruff_dev --release -- format-dev --stability-check --error-file formatter-ecosystem-errors.txt --multi-project target/checkouts > formatter-ecosystem-progress.txt $ rg "Unstable formatting" target/formatter-ecosystem-errors.txt | wc -l 85 ```
8d55004
to
c1ead0b
Compare
Summary Add a
EmptyWithDanglingComments
format helper that formats comments inside empty parentheses, brackets or curly braces. Previously, this was implemented separately, and partially incorrectly, for each use case.Empty
()
,[]
and{}
are special because there can be dangling comments, and they can be intwo positions:
These comments are dangling because they can't be assigned to any element inside as they would
in all other cases.
Test Plan Added a regression test.
145 (from previously 149) instances of unstable formatting remaining.