Skip to content
← Back to rules

unicorn/no-empty-file Correctness

✅ This rule is turned on by default.

What it does ​

Disallows files that do not contain any meaningful code.

This includes files that consist only of:

  • Whitespace
  • Comments
  • Directives (e.g., "use strict")
  • Empty statements (;)
  • Empty blocks ({})
  • Hashbangs (#!/usr/bin/env node)

Why is this bad? ​

Files with no executable or exportable content are typically unintentional or left over from refactoring. They clutter the codebase and may confuse tooling or developers by appearing to serve a purpose when they do not.

Examples ​

Examples of incorrect code for this rule:

js
js
// Comment
js
/* Comment */
js
"use strict";
js
js
{
}
js
#!/usr/bin/env node

Examples of correct code for this rule:

js
const x = 0;
js
"use strict";
const x = 0;
js
const x = 0;
js
{
  const x = 0;
}

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-empty-file": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/no-empty-file": "error",
  },
});
bash
oxlint --deny unicorn/no-empty-file

Version ​

This rule was added in v0.0.15.

References ​