Skip to content

Commit

Permalink
fix(fmt): multiline single param only if func definition is multiline…
Browse files Browse the repository at this point in the history
… for `all_params` (foundry-rs#9187)

* test: adjust single param multiline expected behavior

* fix: `AllParams` single param multiline condition

* refactor: try simplifying the condition logic
  • Loading branch information
ChiTimesChi authored and rplusq committed Nov 29, 2024
1 parent 42fcafb commit c0e6020
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
15 changes: 9 additions & 6 deletions crates/fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,14 +1638,17 @@ impl<'a, W: Write> Formatter<'a, W> {
&params,
",",
)?;
// 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(&params, ",", params_multiline)?;
Expand Down
8 changes: 2 additions & 6 deletions crates/fmt/testdata/FunctionDefinition/all-params.fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
interface FunctionInterfaces {
function noParamsNoModifiersNoReturns();

function oneParam(
uint256 x
);
function oneParam(uint256 x);

function oneModifier() modifier1;

Expand Down Expand Up @@ -345,9 +343,7 @@ contract FunctionDefinitions {
a = 1;
}

function oneParam(
uint256 x
) {
function oneParam(uint256 x) {
a = 1;
}

Expand Down

0 comments on commit c0e6020

Please sign in to comment.