fix(fmt): single line comments orphaned words overflow into next line #11132
+258
−22
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.
Motivation
These two issues mentioned a bug with the forge fmt command: #3604 & #10173. Seemed like a good first-issue to get familiar with the codebase :)
Honestly doesn't seem like a bug to me, people might want to format things manually, but it's true it is not similar to how
rustfmt
.Here was the situation before (from the ticket #3604):
The bug fix applies to the following situations:
Solution
Essentially we are overflowing if the condition mentioned above are true, and we have hit the line length limit.
So if line A: 82 and line B:2, line C:10.
After fmt line A:80 (overflow into B), line B:4, line C:10.
if line A: 82, line B: 82, line C:10.
After fmt line A:80 (overflow into B), line B:80 (overflow into C), C:14.
if line A: 82, line B: 2, line C:82, line D: 3.
After fmt line A:80 (overflow into B), line B:4 (we're safe!), C:80 (overflow into D), D: 5.
(of course these examples don't take into account the exact word length)
Maybe the naming should be changed ?
PR Checklist
Bug fix needs documentation?
No