Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions crates/fmt/src/state/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,32 @@ impl<'ast> State<'_, 'ast> {

print(self, value);

let next_span = if is_last { None } else { Some(get_span(&values[i + 1])) };
let next_pos = next_span.map(Span::lo).unwrap_or(pos_hi);
let cmnt_before_next =
self.peek_comment_before(next_pos).map(|cmnt| (cmnt.span, cmnt.style));

if !is_last {
// Handle disabled lines with comments after the value, but before the comma.
if cmnt_before_next.is_some_and(|(cmnt_span, _)| {
let span = self.cursor.span(cmnt_span.lo());
self.inline_config.is_disabled(span)
// NOTE: necessary workaround to patch this edgecase due to lack of spans for the commas.
&& self.sm.span_to_snippet(span).is_ok_and(|snip| !snip.contains(','))
}) {
self.print_comments(
next_pos,
CommentConfig::skip_ws().mixed_no_break().mixed_prev_space(),
);
}
self.print_word(",");
}

let next_span = if is_last { None } else { Some(get_span(&values[i + 1])) };
let next_pos = next_span.map(Span::lo).unwrap_or(pos_hi);

if !is_last
&& format.breaks_cmnts
&& self.peek_comment_before(next_pos).is_some_and(|cmnt| {
let disabled = self.inline_config.is_disabled(cmnt.span);
(cmnt.style.is_mixed() && !disabled) || (cmnt.style.is_isolated() && disabled)
&& cmnt_before_next.is_some_and(|(cmnt_span, cmnt_style)| {
let disabled = self.inline_config.is_disabled(cmnt_span);
(cmnt_style.is_mixed() && !disabled) || (cmnt_style.is_isolated() && disabled)
})
{
self.hardbreak(); // trailing and isolated comments already hardbreak
Expand Down
3 changes: 2 additions & 1 deletion crates/fmt/testdata/Repros/fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,14 @@ contract DbgFmtTest is Test {
}
}

// https://github.com/foundry-rs/foundry/issues/8557
// https://github.com/foundry-rs/foundry/issues/11249
function argListRepro(address tokenIn, uint256 amountIn, bool data) {
maverickV2SwapCallback(
tokenIn,
amountIn, // forgefmt: disable-line
// forgefmt: disable-next-line
0,/* we didn't bother loading `amountOut` because we don't use it */
0 /* we didn't bother loading `amountOut` because we don't use it */,
data
);
}
Expand Down
1 change: 1 addition & 0 deletions crates/fmt/testdata/Repros/original.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ contract DbgFmtTest is Test {
}
}

// https://github.com/foundry-rs/foundry/issues/8557
// https://github.com/foundry-rs/foundry/issues/11249
function argListRepro(address tokenIn, uint256 amountIn, bool data) {
maverickV2SwapCallback(
Expand Down
3 changes: 2 additions & 1 deletion crates/fmt/testdata/Repros/sorted.fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ contract DbgFmtTest is Test {
}
}

// https://github.com/foundry-rs/foundry/issues/8557
// https://github.com/foundry-rs/foundry/issues/11249
function argListRepro(address tokenIn, uint256 amountIn, bool data) {
maverickV2SwapCallback(
tokenIn,
amountIn, // forgefmt: disable-line
// forgefmt: disable-next-line
0,/* we didn't bother loading `amountOut` because we don't use it */
0 /* we didn't bother loading `amountOut` because we don't use it */,
data
);
}
Expand Down
3 changes: 2 additions & 1 deletion crates/fmt/testdata/Repros/tab.fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ contract DbgFmtTest is Test {
}
}

// https://github.com/foundry-rs/foundry/issues/8557
// https://github.com/foundry-rs/foundry/issues/11249
function argListRepro(address tokenIn, uint256 amountIn, bool data) {
maverickV2SwapCallback(
tokenIn,
amountIn, // forgefmt: disable-line
// forgefmt: disable-next-line
0,/* we didn't bother loading `amountOut` because we don't use it */
0 /* we didn't bother loading `amountOut` because we don't use it */,
data
);
}
Expand Down
Loading