Skip to content

Commit

Permalink
feat(fmt): add all_params config - same as all but split single p…
Browse files Browse the repository at this point in the history
…aram too (#9176)

fet(fmt): add all_params config - smae as all but split single param too
  • Loading branch information
grandizzy authored Oct 23, 2024
1 parent 4c84dc7 commit b1e9365
Show file tree
Hide file tree
Showing 3 changed files with 747 additions and 4 deletions.
2 changes: 2 additions & 0 deletions crates/config/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ pub enum MultilineFuncHeaderStyle {
/// If function params or attrs are multiline.
/// split the rest
All,
/// Same as `All` but writes function params multiline even when there is a single param.
AllParams,
}

impl Default for FormatterConfig {
Expand Down
13 changes: 9 additions & 4 deletions crates/fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,8 @@ impl<'a, W: Write> Formatter<'a, W> {
fmt.config.multiline_func_header,
MultilineFuncHeaderStyle::ParamsFirst |
MultilineFuncHeaderStyle::ParamsFirstMulti |
MultilineFuncHeaderStyle::All
MultilineFuncHeaderStyle::All |
MultilineFuncHeaderStyle::AllParams
);
params_multiline = should_multiline ||
multiline ||
Expand All @@ -1637,11 +1638,12 @@ impl<'a, W: Write> Formatter<'a, W> {
&params,
",",
)?;
// Write new line if we have only one parameter and params first set.
// Write new line if we have only one parameter and params first all multi set.
if params.len() == 1 &&
matches!(
fmt.config.multiline_func_header,
MultilineFuncHeaderStyle::ParamsFirst
MultilineFuncHeaderStyle::ParamsFirst |
MultilineFuncHeaderStyle::AllParams
)
{
writeln!(fmt.buf())?;
Expand Down Expand Up @@ -1736,7 +1738,10 @@ impl<'a, W: Write> Formatter<'a, W> {

let should_multiline = header_multiline &&
if params_multiline {
matches!(self.config.multiline_func_header, MultilineFuncHeaderStyle::All)
matches!(
self.config.multiline_func_header,
MultilineFuncHeaderStyle::All | MultilineFuncHeaderStyle::AllParams
)
} else {
matches!(
self.config.multiline_func_header,
Expand Down
Loading

0 comments on commit b1e9365

Please sign in to comment.