Added new option "chain_count" to limit number of chained functions per line. #5514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See Issue #2263
This PR adds a new option to limit the number of chained method calls based on the number of method calls in addition to the number of characters. This is my first PR to the rustfmt repository, so I apologise if anything about this PR is out of order or if any changes are needed. I want to get this done the right way.
This PR adds the new option
chain_count
, which is ausize
type with a default value of0
. This is the maximum number of chained method calls to put on a single line. Setting to0
effectively disables the option, while setting it to1
has the effect of forcing method chaining to be on new lines.Setting the option to 2 would have the effect that the following would be fine:
However this:
would become this:
I originally considered making an option
force_multiline_chains
, however did not persue this because settingchain_count
to1
has the same effect, and this way there is more freedom for those who would prefer have a couple before it wraps.Examples
0
(default):1
:2
:3
:Interactions with Other Config Options
chain_width
- Does not override. The chain will be made multiline if either of these rules are triggered.force_one_line_chain
- Overrides this option. (This was chosen arbitrarily and I am open to changing this 👍 )