Skip to content
← Back to rules

unicorn/no-anonymous-default-export Restriction

🚧 An auto-fix is planned for this rule, but not implemented at this time.

What it does ​

Disallows anonymous functions and classes as default exports.

Why is this bad? ​

Naming default exports improves searchability and ensures consistent identifiers for a module’s default export in both declaration and import.

Examples ​

Examples of incorrect code for this rule:

javascript
export default class {}
export default function () {}
export default () => {};
module.exports = class {};
module.exports = function () {};
module.exports = () => {};

Examples of correct code for this rule:

javascript
export default class Foo {}
export default function foo () {}

const foo = () => {};
export default foo;

module.exports = class Foo {};
module.exports = function foo () {};

const foo = () => {};
module.exports = foo;

How to use ​

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

json
{
  "rules": {
    "unicorn/no-anonymous-default-export": "error"
  }
}
ts
import { defineConfig } from "oxlint";

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

Version ​

This rule was added in v0.3.3.

References ​