diff --git a/crates/fmt/src/state/mod.rs b/crates/fmt/src/state/mod.rs index 15959173ad674..ada5eadd55bf0 100644 --- a/crates/fmt/src/state/mod.rs +++ b/crates/fmt/src/state/mod.rs @@ -870,15 +870,14 @@ impl<'sess> State<'sess, '_> { if !self.config.wrap_comments && cmnt.lines.len() == 1 { self.word(cmnt.lines.pop().unwrap()); } else if self.config.wrap_comments { - config.offset = self.ind; + if cmnt.is_doc || matches!(cmnt.kind, ast::CommentKind::Line) { + config.offset = 0; + } else { + config.offset = self.ind; + } for (lpos, line) in cmnt.lines.into_iter().delimited() { if !line.is_empty() { - self.print_wrapped_line( - &line, - prefix, - if cmnt.is_doc { 0 } else { config.offset }, - cmnt.is_doc, - ); + self.print_wrapped_line(&line, prefix, config.offset, cmnt.is_doc); } if !lpos.is_last { config.hardbreak(&mut self.s); diff --git a/crates/fmt/testdata/SimpleComments/fmt.sol b/crates/fmt/testdata/SimpleComments/fmt.sol index e9f399968e36d..1520db43d4162 100644 --- a/crates/fmt/testdata/SimpleComments/fmt.sol +++ b/crates/fmt/testdata/SimpleComments/fmt.sol @@ -1,4 +1,8 @@ contract SimpleComments { + uint40 constant PERIOD = uint40(12345); // ~578 days + // Represents the depletion timestamp + uint40 constant WARP_PERIOD = FEB_1_2025 + PERIOD; + //´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*: // VARIABLES //.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.• diff --git a/crates/fmt/testdata/SimpleComments/original.sol b/crates/fmt/testdata/SimpleComments/original.sol index 2dff78dce6a3c..7020527b43671 100644 --- a/crates/fmt/testdata/SimpleComments/original.sol +++ b/crates/fmt/testdata/SimpleComments/original.sol @@ -1,4 +1,8 @@ contract SimpleComments { + uint40 constant PERIOD = uint40(12345); // ~578 days + // Represents the depletion timestamp + uint40 constant WARP_PERIOD = FEB_1_2025 + PERIOD; + //´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*: // VARIABLES //.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.• diff --git a/crates/fmt/testdata/SimpleComments/wrap-comments.fmt.sol b/crates/fmt/testdata/SimpleComments/wrap-comments.fmt.sol index 7e30f8e9d507b..d41b8efa99f08 100644 --- a/crates/fmt/testdata/SimpleComments/wrap-comments.fmt.sol +++ b/crates/fmt/testdata/SimpleComments/wrap-comments.fmt.sol @@ -1,6 +1,10 @@ // config: line_length = 60 // config: wrap_comments = true contract SimpleComments { + uint40 constant PERIOD = uint40(12345); // ~578 days + // Represents the depletion timestamp + uint40 constant WARP_PERIOD = FEB_1_2025 + PERIOD; + //´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*: // VARIABLES //.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.• @@ -46,8 +50,8 @@ contract SimpleComments { function test4() public view returns (uint256) { uint256 abc; // long postfix comment that exceeds - // line width. the comment should be split and - // carried over to the next line + // line width. the comment should be split and + // carried over to the next line uint256 abc2; // reallylongsinglewordcommentthatexceedslinewidththecommentshouldbesplitandcarriedovertothenextline // long prefix comment that exceeds line width. the