mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 00:50:16 +00:00
Fix formatting of chained boolean operations (#6394)
Closes https://github.com/astral-sh/ruff/issues/6068 These commits are kind of a mess as I did some stumbling around here. Unrolls formatting of chained boolean operations to prevent nested grouping which gives us Black-compatible formatting where each boolean operation is on a new line.
This commit is contained in:
parent
63ffadf0b8
commit
999d88e773
5 changed files with 177 additions and 16 deletions
|
@ -16,6 +16,8 @@ use crate::expression::parentheses::{
|
|||
};
|
||||
use crate::prelude::*;
|
||||
|
||||
use self::expr_bool_op::BoolOpLayout;
|
||||
|
||||
pub(crate) mod expr_attribute;
|
||||
pub(crate) mod expr_await;
|
||||
pub(crate) mod expr_bin_op;
|
||||
|
@ -67,7 +69,13 @@ impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
|
|||
let parentheses = self.parentheses;
|
||||
|
||||
let format_expr = format_with(|f| match expression {
|
||||
Expr::BoolOp(expr) => expr.format().with_options(Some(parentheses)).fmt(f),
|
||||
Expr::BoolOp(expr) => expr
|
||||
.format()
|
||||
.with_options(BoolOpLayout {
|
||||
parentheses: Some(parentheses),
|
||||
chained: false,
|
||||
})
|
||||
.fmt(f),
|
||||
Expr::NamedExpr(expr) => expr.format().fmt(f),
|
||||
Expr::BinOp(expr) => expr.format().fmt(f),
|
||||
Expr::UnaryOp(expr) => expr.format().fmt(f),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue