fix(oxfmt): indent dangling comments in empty enum with block indent (#21163)

Copied the dangling comment logic that we have for empty objects, empty
functions and empty interfaces, and made it apply to empty enums as
well.


https://github.com/oxc-project/oxc/blob/a950f555c8258d5c3ff5eace062ed2dcaae01a7d/crates/oxc_formatter/src/print/object_like.rs#L109

Fixes #21145

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Leonabcd123andautofix-ci[bot] authored and GitHub committed 2026-04-09 12:27:45 +09:00
1 parent d13fd3771b
commit 407b72500e
3 files changed
+28 -4

No files matched your search

+1 -4
View File
@@ -1107,10 +1107,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSEnumDeclaration<'a>> {
impl<'a> FormatWrite<'a> for AstNode<'a, TSEnumBody<'a>> {
fn write(&self, f: &mut Formatter<'_, 'a>) {
if self.members().is_empty() {
write!(
f,
group(&format_args!(format_dangling_comments(self.span()), soft_line_break()))
);
write!(f, format_dangling_comments(self.span()).with_block_indent());
} else {
write!(f, block_indent(self.members()));
}
@@ -0,0 +1,3 @@
enum Foo {
// Comment
}
@@ -0,0 +1,24 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
enum Foo {
// Comment
}
==================== Output ====================
------------------
{ printWidth: 80 }
------------------
enum Foo {
// Comment
}
-------------------
{ printWidth: 100 }
-------------------
enum Foo {
// Comment
}
===================== End =====================