oxc-project/oxc · warning · OxcDiagnostic
No spaces inside empty pair of braces allowed
Error message
No spaces inside empty pair of braces allowed
What it means
Diagnostic from oxlint's `unicorn/empty-brace-spaces` rule. It reports braces that are empty but contain whitespace or newlines: empty object literals (`{ }`), empty function bodies, empty class bodies (`class A {\n}`), empty block statements, and empty `static {}` blocks. Braces containing comments between them are respected and not flagged. The autofix rewrites the whole span to `{}` (or `static {}` for static blocks).
Source
Thrown at crates/oxc_linter/src/rules/unicorn/empty_brace_spaces.rs:9
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn empty_brace_spaces_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("No spaces inside empty pair of braces allowed")
.with_help("There should be no spaces or new lines inside a pair of empty braces as it affects the overall readability of the code.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct EmptyBraceSpaces;
declare_oxc_lint!(
/// ### What it does
///
/// Removes the extra spaces or new line characters inside a pair of braces
/// that does not contain additional code. This ensures that braces are clean
/// and do not contain unnecessary spaces or newlines.
///
/// ### Why is this bad?
///
/// Extra spaces inside braces can negatively impact the readability of the code.
/// Keeping braces clean and free of unnecessary characters improves consistency andView on GitHub (pinned to e1e7af627c)
Solutions
- Run `oxlint --fix` (or your formatter) to collapse `{ }` to `{}`.
- Enable format-on-save so brace layout is owned by the formatter, not hand edits.
- If a comment inside the braces is intentional, the rule already skips it — keep the comment and no diagnostic fires.
Example fix
// before
const a = { };
class A {
}
// after
const a = {};
class A {} Defensive patterns
Strategy: validation
Prevention
- Enable format-on-save so the formatter owns brace layout and empty braces stay `{}`.
- Run `oxlint --fix` before CI lint so whitespace-only findings never block a build.
- Note that braces containing comments are exempt — put the comment inside instead of disabling the rule.
When it happens
Trigger: Any empty brace pair whose span is longer than two characters — `const a = { };`, `class A {\n}`, `function f() { }`, `if (x) { }`, `static { }` — with no comments inside.
Common situations: Formatter divergence (Prettier not run on the file), code pasted from editors that expand braces, and CI lint runs on manually edited files where format-on-save was off.
Related errors
- Prefer `{} {}` over `{} {}` to check {}.
- Invalid escape sequence in template literal.
- Use uppercase characters for the value of the escape sequenc
- The {expr_type} is useless
- Don't use a zero fraction in the number.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/685a78fe2548068b.
Report an issue: GitHub.