mirror of https://github.com/astral-sh/ruff
consolidate layout and preview checks
This commit is contained in:
parent
93a958a734
commit
17a1065fad
|
|
@ -137,12 +137,16 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||||
write!(f, [dangling_comments(dangling)])?;
|
write!(f, [dangling_comments(dangling)])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
FormatBody {
|
if !preview {
|
||||||
body,
|
return body.format().fmt(f);
|
||||||
dangling,
|
}
|
||||||
layout: self.layout,
|
|
||||||
|
let fmt_body = FormatBody { body, dangling };
|
||||||
|
|
||||||
|
match self.layout {
|
||||||
|
ExprLambdaLayout::Assignment => fits_expanded(&fmt_body).fmt(f),
|
||||||
|
ExprLambdaLayout::Default => fmt_body.fmt(f),
|
||||||
}
|
}
|
||||||
.fmt(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,26 +207,16 @@ impl NeedsParentheses for ExprLambda {
|
||||||
struct FormatBody<'a> {
|
struct FormatBody<'a> {
|
||||||
body: &'a Expr,
|
body: &'a Expr,
|
||||||
dangling: &'a [SourceComment],
|
dangling: &'a [SourceComment],
|
||||||
layout: ExprLambdaLayout,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<PyFormatContext<'_>> for FormatBody<'_> {
|
impl Format<PyFormatContext<'_>> for FormatBody<'_> {
|
||||||
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
let FormatBody {
|
let FormatBody { dangling, body } = self;
|
||||||
dangling,
|
|
||||||
body,
|
|
||||||
layout,
|
|
||||||
} = self;
|
|
||||||
|
|
||||||
if !is_parenthesize_lambda_bodies_enabled(f.context()) {
|
|
||||||
return body.format().fmt(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
let body = *body;
|
let body = *body;
|
||||||
let comments = f.context().comments().clone();
|
let comments = f.context().comments().clone();
|
||||||
let body_comments = comments.leading_dangling_trailing(body);
|
let body_comments = comments.leading_dangling_trailing(body);
|
||||||
|
|
||||||
let fmt_body = format_with(|f: &mut PyFormatter| {
|
|
||||||
if !dangling.is_empty() {
|
if !dangling.is_empty() {
|
||||||
// Can't use partition_point because there can be additional end of line comments
|
// Can't use partition_point because there can be additional end of line comments
|
||||||
// after the initial set. All of these comments are dangling, for example:
|
// after the initial set. All of these comments are dangling, for example:
|
||||||
|
|
@ -411,11 +405,5 @@ impl Format<PyFormatContext<'_>> for FormatBody<'_> {
|
||||||
else {
|
else {
|
||||||
parenthesize_if_expands(&body.format().with_options(Parentheses::Never)).fmt(f)
|
parenthesize_if_expands(&body.format().with_options(Parentheses::Never)).fmt(f)
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
match layout {
|
|
||||||
ExprLambdaLayout::Assignment => fits_expanded(&fmt_body).fmt(f),
|
|
||||||
ExprLambdaLayout::Default => fmt_body.fmt(f),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue