Skip to content

Commit 479a810

Browse files
fix(fmt): no trailing cmnts in opening brace of empty blocks (#12241)
* fix(fmt): only print trailing cmnts in opening brace when block is not empty * doc: link issue --------- Co-authored-by: grandizzy <[email protected]>
1 parent dbcf0ad commit 479a810

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

crates/fmt/src/state/sol.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,9 @@ impl<'ast> State<'_, 'ast> {
21842184
}
21852185
self.print_word("{");
21862186
self.end();
2187-
self.print_trailing_comment_no_break(catch_span.lo(), None);
2187+
if !block.is_empty() {
2188+
self.print_trailing_comment_no_break(catch_span.lo(), None);
2189+
}
21882190
self.print_block_without_braces(block, catch_span.hi(), Some(self.ind));
21892191
if self.cursor.enabled || self.cursor.pos < try_span.hi() {
21902192
self.print_word("}");

crates/fmt/testdata/TryStatement/fmt.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ contract TryStatement {
9999
uint80, int256 _price, uint256, uint256 _updatedAt, uint80
100100
) {
101101
return true;
102-
} catch {}
102+
} catch {} // https://github.com/foundry-rs/foundry/issues/12240
103103
}
104104
}

crates/fmt/testdata/TryStatement/original.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ contract TryStatement {
8989
function try_reallyLongCall() {
9090
try AggregatorV3Interface(oracle).latestRoundData() returns (uint80, int256 _price, uint256, uint256 _updatedAt, uint80) {
9191
return true;
92-
} catch {}
92+
} catch {} // https://github.com/foundry-rs/foundry/issues/12240
9393
}
9494
}

0 commit comments

Comments
 (0)