From d6e6570c0373d5398aadf0b58f4373edb0aabfd7 Mon Sep 17 00:00:00 2001 From: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:34:30 +0100 Subject: [PATCH 1/3] test: adjust single param multiline expected behavior --- crates/fmt/testdata/FunctionDefinition/all-params.fmt.sol | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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; } From fa74ac88fa66af4908a567c04fbb87efa0ee1911 Mon Sep 17 00:00:00 2001 From: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:18:48 +0100 Subject: [PATCH 2/3] fix: `AllParams` single param multiline condition --- crates/fmt/src/formatter.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/fmt/src/formatter.rs b/crates/fmt/src/formatter.rs index 9213235fe331..f36802f79d5a 100644 --- a/crates/fmt/src/formatter.rs +++ b/crates/fmt/src/formatter.rs @@ -1638,13 +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. + // Write new line if we have only one parameter and params first set, + // or if the function definition is multiline and all params set. if params.len() == 1 && - matches!( + (matches!( fmt.config.multiline_func_header, - MultilineFuncHeaderStyle::ParamsFirst | + MultilineFuncHeaderStyle::ParamsFirst + ) || params_multiline && + matches!( + fmt.config.multiline_func_header, MultilineFuncHeaderStyle::AllParams - ) + )) { writeln!(fmt.buf())?; } From de057ab0411cfddb40f07f3b23633f9176aa4aed Mon Sep 17 00:00:00 2001 From: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:30:05 +0100 Subject: [PATCH 3/3] refactor: try simplifying the condition logic --- crates/fmt/src/formatter.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/fmt/src/formatter.rs b/crates/fmt/src/formatter.rs index f36802f79d5a..6bb814e23269 100644 --- a/crates/fmt/src/formatter.rs +++ b/crates/fmt/src/formatter.rs @@ -1640,16 +1640,15 @@ impl<'a, W: Write> Formatter<'a, W> { )?; // Write new line if we have only one parameter and params first set, // or if the function definition is multiline and all params set. - if params.len() == 1 && - (matches!( + let single_param_multiline = matches!( + fmt.config.multiline_func_header, + MultilineFuncHeaderStyle::ParamsFirst + ) || params_multiline && + matches!( fmt.config.multiline_func_header, - MultilineFuncHeaderStyle::ParamsFirst - ) || params_multiline && - matches!( - fmt.config.multiline_func_header, - MultilineFuncHeaderStyle::AllParams - )) - { + MultilineFuncHeaderStyle::AllParams + ); + if params.len() == 1 && single_param_multiline { writeln!(fmt.buf())?; } fmt.write_chunks_separated(¶ms, ",", params_multiline)?;