mirror of https://github.com/astral-sh/ruff
improve after_parameters_end_of_line name and docs
This commit is contained in:
parent
3011190e43
commit
95301b3bc9
|
|
@ -276,8 +276,8 @@ impl Format<PyFormatContext<'_>> for FormatBody<'_> {
|
||||||
let body_comments = comments.leading_dangling_trailing(body);
|
let body_comments = comments.leading_dangling_trailing(body);
|
||||||
|
|
||||||
if !dangling_header_comments.is_empty() {
|
if !dangling_header_comments.is_empty() {
|
||||||
// Can't use partition_point because there can be additional end of line comments
|
// Split the dangling header comments into trailing comments formatted with the lambda
|
||||||
// after the initial set. All of these comments are dangling, for example:
|
// header (1) and leading comments formatted with the body (2, 3, 4).
|
||||||
//
|
//
|
||||||
// ```python
|
// ```python
|
||||||
// (
|
// (
|
||||||
|
|
@ -289,8 +289,9 @@ impl Format<PyFormatContext<'_>> for FormatBody<'_> {
|
||||||
// )
|
// )
|
||||||
// ```
|
// ```
|
||||||
//
|
//
|
||||||
// and alternate between own line and end of line.
|
// Note that these are split based on their line position rather than using
|
||||||
let (after_parameters_end_of_line, leading_body_comments) = dangling_header_comments
|
// `partition_point` based on a range, for example.
|
||||||
|
let (trailing_header_comments, leading_body_comments) = dangling_header_comments
|
||||||
.split_at(
|
.split_at(
|
||||||
dangling_header_comments
|
dangling_header_comments
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -331,7 +332,8 @@ impl Format<PyFormatContext<'_>> for FormatBody<'_> {
|
||||||
trailing_comments(dangling_header_comments).fmt(f)?;
|
trailing_comments(dangling_header_comments).fmt(f)?;
|
||||||
|
|
||||||
// Note that `leading_body_comments` have already been formatted as part of
|
// Note that `leading_body_comments` have already been formatted as part of
|
||||||
// `dangling` above, but their presence still determines the spacing here.
|
// `dangling_header_comments` above, but their presence still determines the spacing
|
||||||
|
// here.
|
||||||
if leading_body_comments.is_empty() {
|
if leading_body_comments.is_empty() {
|
||||||
space().fmt(f)?;
|
space().fmt(f)?;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -345,7 +347,7 @@ impl Format<PyFormatContext<'_>> for FormatBody<'_> {
|
||||||
[
|
[
|
||||||
space(),
|
space(),
|
||||||
token("("),
|
token("("),
|
||||||
trailing_comments(after_parameters_end_of_line),
|
trailing_comments(trailing_header_comments),
|
||||||
block_indent(&format_args!(
|
block_indent(&format_args!(
|
||||||
leading_comments(leading_body_comments),
|
leading_comments(leading_body_comments),
|
||||||
body.format().with_options(Parentheses::Never)
|
body.format().with_options(Parentheses::Never)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue