Skip to content

Commit

Permalink
fix(fmt): surround with returns in fn with format disabled (foundry-r…
Browse files Browse the repository at this point in the history
…s#8582)

fix(fmt): surround returns if fn format disabled
  • Loading branch information
grandizzy authored and benwjhack committed Sep 11, 2024
1 parent 8fac7c1 commit d926f90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,17 @@ impl<'a, W: Write> Formatter<'a, W> {
let returns_start_loc = func.returns.first().unwrap().0;
let returns_loc = returns_start_loc.with_end_from(&func.returns.last().unwrap().0);
if fmt.inline_config.is_disabled(returns_loc) {
fmt.indented(1, |fmt| fmt.visit_source(returns_loc))?;
fmt.indented(1, |fmt| {
fmt.surrounded(
SurroundingChunk::new("returns (", Some(returns_loc.start()), None),
SurroundingChunk::new(")", None, returns_end),
|fmt, _| {
fmt.visit_source(returns_loc)?;
Ok(())
},
)?;
Ok(())
})?;
} else {
let mut returns = fmt.items_to_chunks(
returns_end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ contract ReturnFnFormat {
)
{}
}

// https://github.com/foundry-rs/foundry/issues/7920
contract ReturnFnDisableFormat {
// forgefmt: disable-next-line
function disableFnFormat() external returns (uint256) {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ contract ReturnFnFormat {
internal pure returns (uint256)
)
{}
}

// https://github.com/foundry-rs/foundry/issues/7920
contract ReturnFnDisableFormat {
// forgefmt: disable-next-line
function disableFnFormat() external returns (uint256) {
return 0;
}
}

0 comments on commit d926f90

Please # to comment.