close

empty-brace-spaces

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/empty-brace-spaces': 'error',
    },
  },
]);

Rule Details

Enforce no spaces between braces.

Empty blocks and object literals do not need internal whitespace, so this rule enforces a compact, consistent style. It applies to block statements, class bodies, static blocks, and object literals whose braces hold nothing but whitespace.

Examples of incorrect code for this rule:

class Unicorn {
}

try {
	foo();
} catch { }

const object = { };

Examples of correct code for this rule:

class Unicorn {}

try {
	foo();
} catch {}

const object = {};

The rule has no options. It is automatically fixable by removing the whitespace between the braces.

A comment between the braces counts as content, so the whitespace around it is left untouched:

class Unicorn { /* comment */ }

A brace pair in a class header is not mistaken for the class body: class Foo extends mixin({}) { } reports the body's space and fixes it to class Foo extends mixin({}) {}, and a header pair that is itself empty is reported separately.

Differences from ESLint

None.

Original Documentation