javascript-unicorn-empty-brace-spaces-enforcement
Normalizes whitespace-only empty brace pairs from `{ }` to `{}` in JS-family runtime syntax, with optional flags for empty blocks, type-space braces, and comment removal.
# javascript-unicorn-empty-brace-spaces-enforcement
Normalizes whitespace-only empty brace pairs from `{ }` to `{}` in JS-family source, aligned with the intent of `eslint-plugin-unicorn`'s `empty-brace-spaces` rule.
## Installation
```bash
codemod run javascript-unicorn-empty-brace-spaces-enforcement
```
## Usage
By default the codemod rewrites only runtime-syntax empty braces when the interior contains whitespace only:
- Object literals: `const value = { };` -> `const value = {};`
- Object patterns: `let { } = source;` -> `let {} = source;`
- Empty named imports: `import { } from "pkg";` -> `import {} from "pkg";`
- Empty named exports: `export { };` -> `export {};`
The workflow scans `.js`, `.jsx`, `.mjs`, `.cjs`, `.ts`, `.mts`, `.cts`, and `.tsx` files and ignores `node_modules`, `dist`, `build`, and `coverage`.
Preserve and no-op behavior:
- Non-empty braces stay unchanged.
- JSX expression container braces such as `<Comp prop={ } />` stay unchanged.
- Type-space braces such as `type T = { };` stay unchanged by default.
- Braces containing comments stay unchanged by default.
- Empty blocks are excluded by default.
Optional workflow parameters:
- `include-empty-blocks=true`: also normalize same-line empty `statement_block` braces such as `if (x) { }`.
- `include-type-braces=true`: also normalize empty TypeScript `object_type` braces.
- `remove-comments-in-empty-braces=true`: unsafe mode that removes comment trivia inside otherwise-empty braces.
Run locally:
```bash
pnpm dlx codemod@latest workflow run -w workflow.yaml --target . --allow-dirty --no-interactive
pnpm dlx codemod@latest workflow run -w workflow.yaml --target . --allow-dirty --no-interactive --param include-empty-blocks=true
```
## Development
```bash
pnpm test
pnpm run check-types
pnpm dlx codemod@latest workflow validate -w workflow.yaml
```
## License
MIT