Repository: oxc-project/oxc (2026-04-08T08:40:25Z)

Issue:
formatter: Diff with Prettier on single-line comments in an empty enum
### Input

```tsx
type Foo = {
  // Type comment
};

interface Bar {
  // Interface comment
}

enum Baz {
  // Enum comment, this will break after formatting
}

```

### Config

```jsonc
{}
```

### Oxfmt output

Oxfmt version: `latest`
```tsx
type Foo = {
  // Type comment
};

interface Bar {
  // Interface comment
}

enum Baz {// Enum comment, this will break after formatting}

```

### Oxfmt playground link

[click](https://playground.oxc.rs/?t=formatter&formatterPanels=output%2Cprettier&options=%7B%22run%22%3A%7B%22lint%22%3Atrue%2C%22formatter%22%3Atrue%2C%22transform%22%3Afalse%2C%22isolatedDeclarations%22%3Afalse%2C%22whitespace%22%3Afalse%2C%22mangle%22%3Afalse%2C%22compress%22%3Afalse%2C%22scope%22%3Atrue%2C%22symbol%22%3Atrue%2C%22cfg%22%3Afalse%7D%2C%22parser%22%3A%7B%22extension%22%3A%22ts%22%2C%22allowReturnOutsideFunction%22%3Atrue%2C%22preserveParens%22%3Atrue%2C%22allowV8Intrinsics%22%3Atrue%2C%22semanticErrors%22%3Atrue%7D%2C%22linter%22%3A%7B%7D%2C%22formatter%22%3A%7B%22useTabs%22%3Afalse%2C%22tabWidth%22%3A2%2C%22endOfLine%22%3A%22lf%22%2C%22printWidth%22%3A80%2C%22singleQuote%22%3Afalse%2C%22jsxSingleQuote%22%3Afalse%2C%22quoteProps%22%3A%22as-needed%22%2C%22trailingComma%22%3A%22all%22%2C%22semi%22%3Atrue%2C%22arrowParens%22%3A%22always%22%2C%22bracketSpacing%22%3Atrue%2C%22bracketSameLine%22%3Afalse%2C%22objectWrap%22%3A%22preserve%22%2C%22singleAttributePerLine%22%3Afalse%7D%2C%22transformer%22%3A%7B%22target%22%3A%22es2015%22%2C%22useDefineForClassFields%22%3Atrue%2C%22experimentalDecorators%22%3Atrue%2C%22emitDecoratorMetadata%22%3Atrue%7D%2C%22isolatedDeclarations%22%3A%7B%22stripInternal%22%3Afalse%7D%2C%22codegen%22%3A%7B%22normal%22%3Atrue%2C%22jsdoc%22%3Atrue%2C%22annotation%22%3Atrue%2C%22legal%22%3Atrue%7D%2C%22compress%22%3A%7B%7D%2C%22mangle%22%3A%7B%22topLevel%22%3Atrue%2C%22keepNames%22%3Afalse%7D%2C%22controlFlow%22%3A%7B%22verbose%22%3Afalse%7D%2C%22inject%22%3A%7B%22inject%22%3A%7B%7D%7D%2C%22define%22%3A%7B%22define%22%3A%7B%7D%7D%7D&code=type+Foo+%3D+%7B%0A++%2F%2F+Type+comment%0A%7D%3B%0A%0Ainterface+Bar+%7B%0A++%2F%2F+Interface+comment%0A%7D%0A%0Aenum+Baz+%7B%0A++%2F%2F+Enum+comment%2C+this+will+break+after+formatting%0A%7D%0A)

### Prettier output

Prettier version: `3.8.1`
```tsx
type Foo = {
  // Type comment
};

interface Bar {
  // Interface comment
}

enum Baz {
  // Enum comment, this will break after formatting
}

```

### Prettier playground link

[click](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEMCeAHOACAYhCbAXm2AB0ptsB6a7AFUx0gFsWEYKBfAbgooCWsOACcAZgEMwOAEISRpClVrYAksPFTmENh278oCAK4tscgF6LKNOgFEoJ7K3awANNhgALAQGdsAdwEAGyDsACMROAkAa2wJMXgFMQgRFgkYGCEAc30oEFcQCAxM6B9kUHkRCH8ABXkEMpQJIP8JNDKCiKlouBgAZQl2ABkhOGRJIJ84AogwgCs4MBgAdREJDGQQDEipkQA3Mc61sB7+jCls5BgRI2mQKZYBK5u7uAAPLBEBFxhmgHlPukUjUID4BCU8igEAATfIgd6fb4cZr0URQeQCOCNCZTApgqBZIJwACKRgg8HGzVxIDmPjefWyRNJ5LGSBxdwAjmT4DUqhhGiAJD4ALSGODQ8Vw64SYLZADCOjSm2aQTh+MJcAAghkvmEjDzRCNDJTJndPDAWEFlt54D5ztI+g1wQI9uC0JswD4OiA9rd1BLYH0wF9ipqoNC+ugiSbqdtQXBVutNtssaIDnCYX8xEbWSAgmI4UJdjBeRIskq2VS7ucRLtNugsD5gwJinDtkIVgJoV5kAAOAAMBUiXIEkVL5YkMbuvzCyy7PaQACYCkYpvQJGFsVWCnAWGFxRLoUMJASjGW4PhUulMgTlfqICAuFwgA)

### Additional notes

A fairly rare case of an empty enum with a single-line comment inside. 

Formatting causes terminating brace on an enum to be a part of the comment. This doesn't seem to be the case for other similar declarations.


Discussion:

Patch:
diff --git a/crates/oxc_formatter/src/print/mod.rs b/crates/oxc_formatter/src/print/mod.rs
index 799db4dd51dc8..161a877f2f20d 100644
--- a/crates/oxc_formatter/src/print/mod.rs
+++ b/crates/oxc_formatter/src/print/mod.rs
@@ -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()));
         }


Test patch:
diff --git a/crates/oxc_formatter/tests/fixtures/ts/comments/enum.ts b/crates/oxc_formatter/tests/fixtures/ts/comments/enum.ts
new file mode 100644
index 0000000000000..c7f6968d8b884
--- /dev/null
+++ b/crates/oxc_formatter/tests/fixtures/ts/comments/enum.ts
@@ -0,0 +1,3 @@
+enum Foo {
+  // Comment
+}
diff --git a/crates/oxc_formatter/tests/fixtures/ts/comments/enum.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/comments/enum.ts.snap
new file mode 100644
index 0000000000000..b377e9a737365
--- /dev/null
+++ b/crates/oxc_formatter/tests/fixtures/ts/comments/enum.ts.snap
@@ -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 =====================