Skip to content

Commit a841db1

Browse files
authored
chore(fmt): rename and alias params config varaint for clarity (#11944)
1 parent 7fcdda5 commit a841db1

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

crates/config/src/fmt.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ pub enum SingleLineBlockStyle {
142142
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
143143
#[serde(rename_all = "snake_case")]
144144
pub enum MultilineFuncHeaderStyle {
145-
/// Write function parameters multiline first.
146-
ParamsFirst,
145+
/// Always write function parameters multiline.
146+
#[serde(alias = "params_first")] // alias for backwards compatibility
147+
ParamsAlways,
147148
/// Write function parameters multiline first when there is more than one param.
148149
ParamsFirstMulti,
149150
/// Write function attributes multiline first.
@@ -162,7 +163,7 @@ impl MultilineFuncHeaderStyle {
162163
}
163164

164165
pub fn params_first(&self) -> bool {
165-
matches!(self, Self::ParamsFirst | Self::ParamsFirstMulti)
166+
matches!(self, Self::ParamsAlways | Self::ParamsFirstMulti)
166167
}
167168

168169
pub fn attrib_first(&self) -> bool {

crates/fmt/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ The formatter supports multiple configuration options defined in `foundry.toml`.
115115
| `style` | `space` | The style of indentation. Options: `space`, `tab`. |
116116
| `bracket_spacing` | `false` | Print spaces between brackets. |
117117
| `int_types` | `long` | Style for `uint256`/`int256` types. Options: `long`, `short`, `preserve`. |
118-
| `multiline_func_header` | `attributes_first` | The style of multiline function headers. Options: `attributes_first`, `params_first`, `params_first_multi`, `all`, `all_params`. |
118+
| `multiline_func_header` | `attributes_first` | The style of multiline function headers. Options: `attributes_first`, `params_always`, `params_first_multi`, `all`, `all_params`. |
119119
| `quote_style` | `double` | The style of quotation marks. Options: `double`, `single`, `preserve`. |
120120
| `number_underscore` | `preserve` | The style of underscores in number literals. Options: `preserve`, `remove`, `thousands`. |
121121
| `hex_underscore` | `remove` | The style of underscores in hex literals. Options: `preserve`, `remove`, `bytes`. |
@@ -127,6 +127,7 @@ The formatter supports multiple configuration options defined in `foundry.toml`.
127127
| `sort_imports` | `false` | Sort import statements alphabetically in groups. A group is a set of imports separated by a newline. |
128128
| `pow_no_space` | `false` | Suppress spaces around the power operator (`**`). |
129129

130+
> Check [`FormatterConfig`](../config/src/fmt.rs) for a more detailed explanation.
130131
131132
### Inline Configuration
132133

crates/fmt/src/state/sol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl<'ast> State<'_, 'ast> {
460460
self.s.cbox(-self.ind);
461461
let header_style = self.config.multiline_func_header;
462462
let params_format = match header_style {
463-
MultilineFuncHeaderStyle::ParamsFirst => ListFormat::always_break(),
463+
MultilineFuncHeaderStyle::ParamsAlways => ListFormat::always_break(),
464464
MultilineFuncHeaderStyle::AllParams
465465
if !header.parameters.is_empty() && !self.can_header_be_inlined(header) =>
466466
{

crates/fmt/testdata/FunctionDefinition/params-first.fmt.sol renamed to crates/fmt/testdata/FunctionDefinition/params-always.fmt.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// config: line_length = 60
2-
// config: multiline_func_header = "params_first"
2+
// config: multiline_func_header = "params_always"
33
interface FunctionInterfaces {
44
function noParamsNoModifiersNoReturns();
55

crates/forge/tests/cli/fmt.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ Diff in stdin:
7878
1 1 | // SPDX-License-Identifier: MIT
7979
2 |-pragma solidity =0.8.30 ;
8080
2 |+pragma solidity =0.8.30;
81-
3 3 |
81+
...
8282
4 |-contract Test {
8383
5 |- uint256 public value ;
8484
6 |- function setValue ( uint256 _value ) public {
8585
7 |- value = _value ;
8686
4 |+contract Test {
8787
5 |+ uint256 public value;
88-
6 |+
88+
...
8989
7 |+ function setValue(uint256 _value) public {
9090
8 |+ value = _value;
9191
8 9 | }
@@ -103,3 +103,26 @@ forgetest!(fmt_stdin_original, |_prj, cmd| {
103103
cmd.stdin(FORMATTED.as_bytes());
104104
cmd.assert_success().stdout_eq(FORMATTED.as_bytes());
105105
});
106+
107+
// Test that fmt can format a simple contract file
108+
forgetest_init!(fmt_file_config_parms_first, |prj, cmd| {
109+
prj.create_file(
110+
"foundry.toml",
111+
r#"
112+
[fmt]
113+
multiline_func_header = 'params_first'
114+
"#,
115+
);
116+
prj.add_raw_source("FmtTest.sol", FORMATTED);
117+
cmd.forge_fuse().args(["fmt", "--check"]).arg("src/FmtTest.sol");
118+
cmd.assert_failure().stdout_eq(str![[r#"
119+
Diff in src/FmtTest.sol:
120+
...
121+
7 |- function setValue(uint256 _value) public {
122+
7 |+ function setValue(
123+
8 |+ uint256 _value
124+
9 |+ ) public {
125+
...
126+
127+
"#]]);
128+
});

0 commit comments

Comments
 (0)