Add max_content_width option
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Currently, splitting behaviour appears to be mostly dependent on max_width, unless some specific option overrides/augments this. I don't fully understand why, either.
Example, with max_width = 140 (line = 105 chars, 85 excluding indent):
accum = accum.checked_add(x).unwrap_or(Duration::new(u64::max_value(), 999_999_999));
Again, with max_width = 120 (longest line = 81 chars, 57 excluding indent):
accum = accum
.checked_add(x)
.unwrap_or(Duration::new(u64::max_value(), 999_999_999));
As I see it, there are two reasons to break long lines:
- Available width in editors. This may or may not be an issue (it's common to have lots of spare width; some people like myself like to use variable-width fonts).
- Readability. Too much content on one line is hard to parse.
Note that there are already a couple of more specific width rules:
comment_width: since comments are somewhat different to code, it makes sense to have this separateinline_attribute_width: controls two things; (a) whether to use inline attributes at all (default: no), and (b) when, specifically, to allow them
Proposal:
- Add a
max_content_widthoption; split lines when either the total line length exceedsmax_widthor the length minus indent exceedsmax_content_width - Replace
inline_attribute_widthwithinline_attributes(true/false), usingmax_content_widthto control behaviour
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests. Start by locating the handling for max_width, comment_width, and inline_attribute_width in rustfmt, then trace how line splitting and inline attributes are decided. Done means implementing max_content_width as proposed, deciding the replacement behavior for inline_attribute_width, and adding coverage for both width rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100