diff --git a/crates/fmt/src/formatter.rs b/crates/fmt/src/formatter.rs index 9213235fe331..6bb814e23269 100644 --- a/crates/fmt/src/formatter.rs +++ b/crates/fmt/src/formatter.rs @@ -1638,14 +1638,17 @@ impl<'a, W: Write> Formatter<'a, W> { ¶ms, ",", )?; - // Write new line if we have only one parameter and params first all multi set. - if params.len() == 1 && + // Write new line if we have only one parameter and params first set, + // or if the function definition is multiline and all params set. + let single_param_multiline = matches!( + fmt.config.multiline_func_header, + MultilineFuncHeaderStyle::ParamsFirst + ) || params_multiline && matches!( fmt.config.multiline_func_header, - MultilineFuncHeaderStyle::ParamsFirst | - MultilineFuncHeaderStyle::AllParams - ) - { + MultilineFuncHeaderStyle::AllParams + ); + if params.len() == 1 && single_param_multiline { writeln!(fmt.buf())?; } fmt.write_chunks_separated(¶ms, ",", params_multiline)?; diff --git a/crates/fmt/testdata/FunctionDefinition/all-params.fmt.sol b/crates/fmt/testdata/FunctionDefinition/all-params.fmt.sol index f723b00496b6..db7164d284a5 100644 --- a/crates/fmt/testdata/FunctionDefinition/all-params.fmt.sol +++ b/crates/fmt/testdata/FunctionDefinition/all-params.fmt.sol @@ -3,9 +3,7 @@ interface FunctionInterfaces { function noParamsNoModifiersNoReturns(); - function oneParam( - uint256 x - ); + function oneParam(uint256 x); function oneModifier() modifier1; @@ -345,9 +343,7 @@ contract FunctionDefinitions { a = 1; } - function oneParam( - uint256 x - ) { + function oneParam(uint256 x) { a = 1; }