diff --git a/tooling/nargo_fmt/src/rewrite/expr.rs b/tooling/nargo_fmt/src/rewrite/expr.rs index 4d7279815df..e026d515333 100644 --- a/tooling/nargo_fmt/src/rewrite/expr.rs +++ b/tooling/nargo_fmt/src/rewrite/expr.rs @@ -1,7 +1,7 @@ use noirc_frontend::{token::Token, ArrayLiteral, Expression, ExpressionKind, Literal, UnaryOp}; use crate::visitor::{ - expr::{format_brackets, format_parens}, + expr::{format_brackets, format_parens, NewlineMode}, ExpressionType, FmtVisitor, Indent, Shape, }; @@ -60,6 +60,7 @@ pub(crate) fn rewrite( call_expr.arguments, args_span, true, + NewlineMode::IfContainsNewLineAndWidth, ); format!("{callee}{args}") @@ -80,6 +81,7 @@ pub(crate) fn rewrite( method_call_expr.arguments, args_span, true, + NewlineMode::IfContainsNewLineAndWidth, ); format!("{object}.{method}{args}") @@ -97,9 +99,16 @@ pub(crate) fn rewrite( format!("{collection}{index}") } - ExpressionKind::Tuple(exprs) => { - format_parens(None, visitor.fork(), shape, exprs.len() == 1, exprs, span, false) - } + ExpressionKind::Tuple(exprs) => format_parens( + None, + visitor.fork(), + shape, + exprs.len() == 1, + exprs, + span, + true, + NewlineMode::Normal, + ), ExpressionKind::Literal(literal) => match literal { Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) => { visitor.slice(span).to_string() diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 380bb876701..586d9583e32 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -187,6 +187,7 @@ impl FmtVisitor<'_> { } } +// TODO: fixme #[allow(clippy::too_many_arguments)] pub(crate) fn format_seq( shape: Shape, @@ -232,6 +233,8 @@ pub(crate) fn format_brackets( ) } +// TODO: fixme +#[allow(clippy::too_many_arguments)] pub(crate) fn format_parens( max_width: Option, visitor: FmtVisitor, @@ -240,20 +243,10 @@ pub(crate) fn format_parens( exprs: Vec, span: Span, reduce: bool, + mode: NewlineMode, ) -> String { let tactic = max_width.map(Tactic::LimitedHorizontalVertical).unwrap_or(Tactic::Horizontal); - format_seq( - shape, - "(", - ")", - visitor, - trailing_comma, - exprs, - span, - tactic, - NewlineMode::IfContainsNewLineAndWidth, - reduce, - ) + format_seq(shape, "(", ")", visitor, trailing_comma, exprs, span, tactic, mode, reduce) } fn format_exprs(