-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(fmt): add all_params
config - same as all
but split single param too
#9176
Conversation
all_params
config - same as all
but split single param too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
all_params
config - same as all
but split single param tooall_params
config - same as all
but split single param too
LFG! Thanks :) |
function oneParam( | ||
uint256 x | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grandizzy I had a chance to test this today, and I see that this doesn't match the previous "multiline_func_header = all" behaviour :(
I apologise for the confusion, but the behaviour I'm trying to recreate is the following:
- Multiline everything if the function definition occupies more than a single line.
- Don't multiline anything otherwise, e.g. similar to "all" for this particular case: https://github.com/grandizzy/foundry/blob/93aaebb516a7f1d52f60b07bc2f407c68198185e/crates/fmt/testdata/FunctionDefinition/all.fmt.sol#L6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I am at a lost here, in the issue you created you mention that
function a(uint256 param1)
it's a bug and should be expected to be as
function a(
uint256 param1
)
which the change from this PR is doing, but actually it shouldn't be multilined now?
Please add relevant case expected vs actual and will look into, a diff would also help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grandizzy Here's the relevant test case:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
contract A {
// Single parameter is printed on a new line, when the function definition is multi-line
function a(
uint256 param1
)
external
pure
returns (uint256 firstReturnValue, uint256 secondReturnValue, uint256 thirdReturnValue)
{
firstReturnValue = param1 + 1;
secondReturnValue = param1 + 2;
thirdReturnValue = param1 + 3;
}
// Single parameter is printed on the same line, when the function definition is single-line
function b(uint256 param1) external pure returns (uint256) {
return param1 + 1;
}
}
I think I got this working in my local foundry fork, do you mind if try opening a feature PR for that? Assuming it would be fine to modify the newly added AllParams
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, sure, please do a PR, AllParams
was added to accommodate those diffs so all good. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, I am trying to replicate the multiline_func_header=all
behaviour from the August build we were using. The set of formatting rules made sense at the time, and still does :)
…aram too (foundry-rs#9176) fet(fmt): add all_params config - smae as all but split single param too
Motivation
Closes #9173
multiline_func_header="all
fmt does not write single params on new line (at param level there'sparams_first
which writes on new line regardless number of params andparams_first_multi
which writes only multi params on new lines)multiline_func_header="all_params
to write params on new lines even if there's a single param (adding such won't break existing formatters)Solution