diff --git a/crates/fmt/src/comments.rs b/crates/fmt/src/comments.rs index 295d171531c48..03f4e41813c19 100644 --- a/crates/fmt/src/comments.rs +++ b/crates/fmt/src/comments.rs @@ -398,13 +398,13 @@ impl Iterator for CommentStateCharIndices<'_> { } #[inline] - fn count(self) -> usize { - self.iter.count() + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() } #[inline] - fn size_hint(&self) -> (usize, Option) { - self.iter.size_hint() + fn count(self) -> usize { + self.iter.count() } } diff --git a/crates/fmt/src/formatter.rs b/crates/fmt/src/formatter.rs index 89829a59b053e..347d7188f14e5 100644 --- a/crates/fmt/src/formatter.rs +++ b/crates/fmt/src/formatter.rs @@ -528,8 +528,12 @@ impl<'a, W: Write> Formatter<'a, W> { .take_while(|(idx, ch)| ch.is_whitespace() && *idx <= self.buf.current_indent_len()) .count(); let to_skip = indent_whitespace_count - indent_whitespace_count % self.config.tab_width; - write!(self.buf(), " * ")?; - self.write_comment_line(comment, &line[to_skip..])?; + write!(self.buf(), " *")?; + let content = &line[to_skip..]; + if !content.trim().is_empty() { + write!(self.buf(), " ")?; + self.write_comment_line(comment, &line[to_skip..])?; + } self.write_whitespace_separator(true)?; Ok(()) } diff --git a/crates/fmt/testdata/BlockCommentsFunction/fmt.sol b/crates/fmt/testdata/BlockCommentsFunction/fmt.sol new file mode 100644 index 0000000000000..368749bf4fdaf --- /dev/null +++ b/crates/fmt/testdata/BlockCommentsFunction/fmt.sol @@ -0,0 +1,20 @@ +contract A { + Counter public counter; + /** + * TODO: this fuzz use too much time to execute + * function testGetFuzz(bytes[2][] memory kvs) public { + * for (uint256 i = 0; i < kvs.length; i++) { + * bytes32 root = trie.update(kvs[i][0], kvs[i][1]); + * console.logBytes32(root); + * } + * + * for (uint256 i = 0; i < kvs.length; i++) { + * (bool exist, bytes memory value) = trie.get(kvs[i][0]); + * console.logBool(exist); + * console.logBytes(value); + * require(exist); + * require(BytesSlice.equal(value, trie.getRaw(kvs[i][0]))); + * } + * } + */ +} diff --git a/crates/fmt/testdata/BlockCommentsFunction/original.sol b/crates/fmt/testdata/BlockCommentsFunction/original.sol new file mode 100644 index 0000000000000..089f1bac430cd --- /dev/null +++ b/crates/fmt/testdata/BlockCommentsFunction/original.sol @@ -0,0 +1,20 @@ +contract A { + Counter public counter; + /** + * TODO: this fuzz use too much time to execute + function testGetFuzz(bytes[2][] memory kvs) public { + for (uint256 i = 0; i < kvs.length; i++) { + bytes32 root = trie.update(kvs[i][0], kvs[i][1]); + console.logBytes32(root); + } + + for (uint256 i = 0; i < kvs.length; i++) { + (bool exist, bytes memory value) = trie.get(kvs[i][0]); + console.logBool(exist); + console.logBytes(value); + require(exist); + require(BytesSlice.equal(value, trie.getRaw(kvs[i][0]))); + } + } + */ +} \ No newline at end of file diff --git a/crates/fmt/tests/formatter.rs b/crates/fmt/tests/formatter.rs index 2e5d77054051f..18b72a54512be 100644 --- a/crates/fmt/tests/formatter.rs +++ b/crates/fmt/tests/formatter.rs @@ -230,6 +230,7 @@ test_directories! { EmitStatement, Repros, BlockComments, + BlockCommentsFunction, EnumVariants, }