Skip to content
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
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ alloy-hardforks = { version = "0.3.2", default-features = false }
alloy-op-hardforks = { version = "0.3.2", default-features = false }

## alloy-core
alloy-dyn-abi = "1.3.1"
alloy-dyn-abi = "1.4.1"
alloy-json-abi = "1.3.0"
alloy-primitives = { version = "1.3.1", features = [
"getrandom",
Expand Down
10 changes: 9 additions & 1 deletion crates/fmt/src/state/sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ impl<'ast> State<'_, 'ast> {
let header_style = self.config.multiline_func_header;
let params_format = match header_style {
MultilineFuncHeaderStyle::ParamsAlways => ListFormat::always_break(),
MultilineFuncHeaderStyle::All
if header.parameters.len() > 1 && !self.can_header_be_inlined(header) =>
{
ListFormat::always_break()
}
MultilineFuncHeaderStyle::AllParams
if !header.parameters.is_empty() && !self.can_header_be_inlined(header) =>
{
Expand Down Expand Up @@ -2429,6 +2434,8 @@ impl<'ast> State<'_, 'ast> {
}

fn can_header_be_inlined(&mut self, header: &ast::FunctionHeader<'_>) -> bool {
const FUNCTION: usize = 8;

// ' ' + visibility
let visibility = header.visibility.map_or(0, |v| self.estimate_size(v.span) + 1);
// ' ' + state mutability
Expand All @@ -2445,7 +2452,8 @@ impl<'ast> State<'_, 'ast> {
.fold(0, |len, p| if len != 0 { len + 2 } else { 8 } + self.estimate_size(p.span))
});

self.estimate_header_params_size(header)
FUNCTION
+ self.estimate_header_params_size(header)
+ visibility
+ mutability
+ modifiers
Expand Down
5 changes: 4 additions & 1 deletion crates/fmt/testdata/FunctionDefinition/all.fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,10 @@ contract FunctionOverrides is
a = 1;
}

function simple(address _target, bytes memory _payload)
function simple(
address _target,
bytes memory _payload
)
internal
{
a = 1;
Expand Down
15 changes: 15 additions & 0 deletions crates/fmt/testdata/ReprosFunctionDefs/all.120.fmt.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// config: line_length = 120
// config: multiline_func_header = "all"
contract Repros {
// https://github.com/foundry-rs/foundry/issues/12109
function calculateStreamedPercentage(
uint128 streamedAmount,
uint128 depositedAmount
)
internal
pure
returns (uint256)
{
a = 1;
}
}
4 changes: 4 additions & 0 deletions crates/fmt/testdata/ReprosFunctionDefs/original.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract Repros {
// https://github.com/foundry-rs/foundry/issues/12109
function calculateStreamedPercentage(uint128 streamedAmount, uint128 depositedAmount) internal pure returns (uint256) { a = 1; }
}
1 change: 1 addition & 0 deletions crates/fmt/tests/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ fmt_tests! {
PragmaDirective,
Repros,
ReprosCalls,
ReprosFunctionDefs,
ReturnStatement,
RevertNamedArgsStatement,
RevertStatement,
Expand Down
Loading