diff --git a/crates/ruff_python_formatter/src/expression/expr_attribute.rs b/crates/ruff_python_formatter/src/expression/expr_attribute.rs index 12fc5ea28ec1cc..6c635531f978d5 100644 --- a/crates/ruff_python_formatter/src/expression/expr_attribute.rs +++ b/crates/ruff_python_formatter/src/expression/expr_attribute.rs @@ -3,9 +3,7 @@ use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::{Constant, Expr, ExprAttribute, ExprConstant}; use crate::comments::{leading_comments, trailing_comments}; -use crate::expression::parentheses::{ - NeedsParentheses, OptionalParentheses, Parentheses, -}; +use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses}; use crate::prelude::*; use crate::FormatNodeRule; @@ -49,23 +47,25 @@ impl FormatNodeRule for FormatExprAttribute { if needs_parentheses { value.format().with_options(Parentheses::Always).fmt(f)?; - } else if self.fluent_style { + } else { match value.as_ref() { Expr::Attribute(expr) => expr.format().with_options(self.fluent_style).fmt(f)?, Expr::Call(expr) => { expr.format().with_options(self.fluent_style).fmt(f)?; - // Format the dot on its own line - soft_line_break().fmt(f)?; + if self.fluent_style { + // Format the dot on its own line + soft_line_break().fmt(f)?; + } } Expr::Subscript(expr) => { expr.format().with_options(self.fluent_style).fmt(f)?; - // Format the dot on its own line - soft_line_break().fmt(f)?; + if self.fluent_style { + // Format the dot on its own line + soft_line_break().fmt(f)?; + } } _ => value.format().fmt(f)?, } - } else { - value.format().fmt(f)?; } if comments.has_trailing_own_line_comments(value.as_ref()) { diff --git a/crates/ruff_python_formatter/src/expression/expr_call.rs b/crates/ruff_python_formatter/src/expression/expr_call.rs index 4d2fe2c4d8a4e6..a1c02c61983a39 100644 --- a/crates/ruff_python_formatter/src/expression/expr_call.rs +++ b/crates/ruff_python_formatter/src/expression/expr_call.rs @@ -26,15 +26,11 @@ impl FormatNodeRule for FormatExprCall { arguments, } = item; - if self.fluent_style { - match func.as_ref() { - Expr::Attribute(expr) => expr.format().with_options(self.fluent_style).fmt(f)?, - Expr::Call(expr) => expr.format().with_options(self.fluent_style).fmt(f)?, - Expr::Subscript(expr) => expr.format().with_options(self.fluent_style).fmt(f)?, - _ => func.format().fmt(f)?, - } - } else { - func.format().fmt(f)?; + match func.as_ref() { + Expr::Attribute(expr) => expr.format().with_options(self.fluent_style).fmt(f)?, + Expr::Call(expr) => expr.format().with_options(self.fluent_style).fmt(f)?, + Expr::Subscript(expr) => expr.format().with_options(self.fluent_style).fmt(f)?, + _ => func.format().fmt(f)?, } write!(f, [arguments.format()]) diff --git a/crates/ruff_python_formatter/src/expression/expr_subscript.rs b/crates/ruff_python_formatter/src/expression/expr_subscript.rs index 4eafb9ed06aee2..43739209912566 100644 --- a/crates/ruff_python_formatter/src/expression/expr_subscript.rs +++ b/crates/ruff_python_formatter/src/expression/expr_subscript.rs @@ -40,17 +40,11 @@ impl FormatNodeRule for FormatExprSubscript { "A subscript expression can only have a single dangling comment, the one after the bracket" ); - let format_value = format_with(|f| { - if self.fluent_style { - match value.as_ref() { - Expr::Attribute(expr) => expr.format().with_options(self.fluent_style).fmt(f), - Expr::Call(expr) => expr.format().with_options(self.fluent_style).fmt(f), - Expr::Subscript(expr) => expr.format().with_options(self.fluent_style).fmt(f), - _ => value.format().fmt(f), - } - } else { - value.format().fmt(f) - } + let format_value = format_with(|f| match value.as_ref() { + Expr::Attribute(expr) => expr.format().with_options(self.fluent_style).fmt(f), + Expr::Call(expr) => expr.format().with_options(self.fluent_style).fmt(f), + Expr::Subscript(expr) => expr.format().with_options(self.fluent_style).fmt(f), + _ => value.format().fmt(f), }); if let NodeLevel::Expression(Some(_)) = f.context().node_level() {