Skip to content

Commit a9e2b31

Browse files
0xrusowskygrandizzy
authored andcommitted
fix(fmt): properly handle multiline_func_header = "all" + bump alloy (foundry-rs#12110)
* fix: don't normalize single-line non-doc block cmnts * fix: preserve consecutive whitespaces * fix: use byte length instead of char count * fix(fmt): properly handle multiline_func_header = "all" * fix: bump alloy * fix: bump alloy
1 parent 8c0f2f2 commit a9e2b31

File tree

7 files changed

+52
-21
lines changed

7 files changed

+52
-21
lines changed

Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ alloy-hardforks = { version = "0.3.2", default-features = false }
249249
alloy-op-hardforks = { version = "0.3.2", default-features = false }
250250

251251
## alloy-core
252-
alloy-dyn-abi = "1.3.1"
252+
alloy-dyn-abi = "1.4.1"
253253
alloy-json-abi = "1.3.0"
254254
alloy-primitives = { version = "1.3.1", features = [
255255
"getrandom",

crates/fmt/src/state/sol.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ impl<'ast> State<'_, 'ast> {
461461
let header_style = self.config.multiline_func_header;
462462
let params_format = match header_style {
463463
MultilineFuncHeaderStyle::ParamsFirst => ListFormat::always_break(),
464+
MultilineFuncHeaderStyle::All
465+
if header.parameters.len() > 1 && !self.can_header_be_inlined(header) =>
466+
{
467+
ListFormat::always_break()
468+
}
464469
MultilineFuncHeaderStyle::AllParams
465470
if !header.parameters.is_empty() && !self.can_header_be_inlined(header) =>
466471
{
@@ -2433,6 +2438,8 @@ impl<'ast> State<'_, 'ast> {
24332438
}
24342439

24352440
fn can_header_be_inlined(&mut self, header: &ast::FunctionHeader<'_>) -> bool {
2441+
const FUNCTION: usize = 8;
2442+
24362443
// ' ' + visibility
24372444
let visibility = header.visibility.map_or(0, |v| self.estimate_size(v.span) + 1);
24382445
// ' ' + state mutability
@@ -2449,7 +2456,8 @@ impl<'ast> State<'_, 'ast> {
24492456
.fold(0, |len, p| if len != 0 { len + 2 } else { 8 } + self.estimate_size(p.span))
24502457
});
24512458

2452-
self.estimate_header_params_size(header)
2459+
FUNCTION
2460+
+ self.estimate_header_params_size(header)
24532461
+ visibility
24542462
+ mutability
24552463
+ modifiers

crates/fmt/testdata/FunctionDefinition/all.fmt.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,10 @@ contract FunctionOverrides is
727727
a = 1;
728728
}
729729

730-
function simple(address _target, bytes memory _payload)
730+
function simple(
731+
address _target,
732+
bytes memory _payload
733+
)
731734
internal
732735
{
733736
a = 1;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// config: line_length = 120
2+
// config: multiline_func_header = "all"
3+
contract Repros {
4+
// https://github.com/foundry-rs/foundry/issues/12109
5+
function calculateStreamedPercentage(
6+
uint128 streamedAmount,
7+
uint128 depositedAmount
8+
)
9+
internal
10+
pure
11+
returns (uint256)
12+
{
13+
a = 1;
14+
}
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
contract Repros {
2+
// https://github.com/foundry-rs/foundry/issues/12109
3+
function calculateStreamedPercentage(uint128 streamedAmount, uint128 depositedAmount) internal pure returns (uint256) { a = 1; }
4+
}

crates/fmt/tests/formatter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ fmt_tests! {
202202
PragmaDirective,
203203
Repros,
204204
ReprosCalls,
205+
ReprosFunctionDefs,
205206
ReturnStatement,
206207
RevertNamedArgsStatement,
207208
RevertStatement,

0 commit comments

Comments
 (0)