Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fmt): multiline single param only if func definition is multiline for all_params #9187

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading