You can't search for a default export that has no name, and each importing file makes up its own name for it. An anonymous function or class also shows up without a useful name in stack traces and dev tools. Give the value a name first, then export it.
Functions, classes, arrow functions, objects, arrays, literals and new expressions are reported. The result of a call, as in export default defineConfig({}), is allowed by default.
Configure
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"import/no-anonymous-default-export" = "error" # or "warn"
Every option, set to its default:
bunfig.toml
[lint.rules]
"import/no-anonymous-default-export" = ["error", {
allowAnonymousFunction = false,
allowAnonymousClass = false,
allowArrowFunction = false,
allowObject = false,
allowArray = false,
allowLiteral = false,
allowNew = false,
allowCallExpression = true,
}]
Examples
Reported:
export default function () {
return "ok";
}
export default items => items.length;
export default { port: 3000 };
Not reported:
export default function status() {
return "ok";
}
const config = { port: 3000 };
export default config;
export default defineConfig({ port: 3000 });
Options
| Option | Default | What it allows |
|---|---|---|
allowAnonymousFunction | false | export default function () {} |
allowAnonymousClass | false | export default class {} |
allowArrowFunction | false | export default () => {} |
allowObject | false | export default { port: 3000 } |
allowArray | false | export default [1, 2] |
allowLiteral | false | export default 42, strings, template literals, regular expressions, true, null |
allowNew | false | export default new Server() |
allowCallExpression | true | export default createServer() |
export default { port: 3000 };
export default defineConfig({ port: 3000 });