Feat/format conditions multi line#12636
Feat/format conditions multi line#12636Syzygy106 wants to merge 10 commits intofoundry-rs:masterfrom
Conversation
|
grandizzy
left a comment
There was a problem hiding this comment.
thank you, makes sense IMO (pending @0xrusowsky ). Please update the readme too to reflect the new config https://github.com/foundry-rs/foundry/tree/master/crates/fmt#configuration and add an ui_test as in https://github.com/foundry-rs/foundry/tree/master/crates/fmt#testing
|
the impl LGTM, but imo it would be nice to make the output prettier. if possible, let's aim for: if (
newNumber % 2 == 0
|| newNumber % 2 == 1
|| newNumber != 0
|| newNumber != 1
|| newNumber != 2
) {i think you should be able to achieve if with an extra box when the multiline config is enabled |
crates/fmt/src/pp/convenience.rs
Outdated
| // Normalize trailing newlines: ensure exactly one \n at the end | ||
| // This must happen AFTER scan_eof() to catch any newlines added during EOF-flush | ||
| // If there's no newline at all, add one | ||
| if !self.out.ends_with('\n') { | ||
| self.out.push('\n'); | ||
| } else { | ||
| // If there are multiple newlines, remove extras to leave exactly one | ||
| while self.out.ends_with("\n\n") { | ||
| self.out.pop(); | ||
| } | ||
| } |
There was a problem hiding this comment.
why do we need to introduce this logic?
There was a problem hiding this comment.
@Syzygy106 can we bring this over the finish line?
Address review comment from @0xrusowsky: the trailing newline normalization in eof() was a workaround for a test file issue (original.sol had CRLF line endings and a trailing blank line). The proper fix is to clean up the test file instead of post-processing in eof(). This removes the unnecessary normalization logic and fixes the root cause. Amp-Thread-ID: https://ampcode.com/threads/T-019bdc92-a774-749b-a831-7d9de5021e45 Co-authored-by: Amp <amp@ampcode.com>
grandizzy
left a comment
There was a problem hiding this comment.
think this should be good to merge, @0xrusowsky @DaniPopes mind to have a 2nd look? ty!
Motivation
Closes #12508
When conditions in
ifstatements are formatted inline (all on one line), coverage analysis tools like lcov cannot properly distinguish which individual conditions within the chain are actually covered by tests. This happens because the tool sees only one line with the condition, making it difficult to determine branch coverage for each condition.For example:
With inline formatting, if a test only covers the first condition (e.g.,
newNumber % 2 == 0), lcov may show the entire line as covered, but it cannot indicate which specific conditions were actually tested. This makes it difficult to identify untested conditions and achieve accurate branch coverage analysis.Solution
Added a new
format_conditionsconfiguration option infoundry.tomlthat allows placing each condition on a separate line:When
format_conditions = "multi", logical operators (||,&&) inifconditions are formatted with each condition on a separate line:PR Checklist