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
5 changes: 5 additions & 0 deletions .changeset/fix-lone-block-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#8685](https://github.com/biomejs/biome/issues/8685) where `noUselessLoneBlockStatements` would remove empty blocks containing comments. The rule now preserves these blocks since comments may contain important information like TODOs or commented-out code.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ impl Rule for NoUselessLoneBlockStatements {
}

if block.statements().is_empty() {
// Preserve empty blocks that contain comments
if block.syntax().has_comments_descendants() {
return None;
}
return Some(());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,21 @@ switch (foo) {
break;
}
}

// Empty blocks with comments should not trigger diagnostics
{
// TODO: add error handling
}

{
/*
* Multi-line block comment
* should also be preserved
*/
}

function withCommentedCode() {
{
// return x + y;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,22 @@ switch (foo) {
}
}

// Empty blocks with comments should not trigger diagnostics
{
// TODO: add error handling
}

{
/*
* Multi-line block comment
* should also be preserved
*/
}

function withCommentedCode() {
{
// return x + y;
}
}

```