Skip to content

Commit

Permalink
fix(fmt): emit stmt grouping (foundry-rs#4430)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Feb 26, 2023
1 parent c5dd9a6 commit 0cc1338
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
10 changes: 4 additions & 6 deletions fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2276,12 +2276,9 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {

fn visit_emit(&mut self, loc: Loc, event: &mut Expression) -> Result<()> {
return_source_if_disabled!(self, loc);
self.grouped(|fmt| {
write_chunk!(fmt, loc.start(), "emit")?;
event.visit(fmt)?;
fmt.write_semicolon()?;
Ok(())
})?;
write_chunk!(self, loc.start(), "emit")?;
event.visit(self)?;
self.write_semicolon()?;
Ok(())
}

Expand Down Expand Up @@ -3674,4 +3671,5 @@ mod tests {
test_directory! { PragmaDirective }
test_directory! { Annotation }
test_directory! { MappingType }
test_directory! { EmitStatement }
}
31 changes: 31 additions & 0 deletions fmt/testdata/EmitStatement/fmt.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// config: line_length = 80
event NewEvent(
address beneficiary, uint256 index, uint64 timestamp, uint64 endTimestamp
);

function emitEvent() {
emit NewEvent(
beneficiary,
_vestingBeneficiaries.length - 1,
uint64(block.timestamp),
endTimestamp
);

emit NewEvent(
/* beneficiary */
beneficiary,
/* index */
_vestingBeneficiaries.length - 1,
/* timestamp */
uint64(block.timestamp),
/* end timestamp */
endTimestamp
);

emit NewEvent(
beneficiary, // beneficiary
_vestingBeneficiaries.length - 1, // index
uint64(block.timestamp), // timestamp
endTimestamp // end timestamp
);
}
24 changes: 24 additions & 0 deletions fmt/testdata/EmitStatement/original.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
event NewEvent(address beneficiary, uint256 index, uint64 timestamp, uint64 endTimestamp);

function emitEvent() {
emit NewEvent(
beneficiary,
_vestingBeneficiaries.length - 1,
uint64(block.timestamp),
endTimestamp
);

emit
NewEvent(
/* beneficiary */ beneficiary,
/* index */ _vestingBeneficiaries.length - 1,
/* timestamp */ uint64(block.timestamp),
/* end timestamp */ endTimestamp);

emit NewEvent(
beneficiary, // beneficiary
_vestingBeneficiaries.length - 1, // index
uint64(block.timestamp), // timestamp
endTimestamp // end timestamp
);
}

0 comments on commit 0cc1338

Please sign in to comment.