no-anonymous-default-export
Forbid anonymous values as default exports
💼 This rule is enabled in the following configs: recommended, typescript.
Rule Details
A default-exported function or class without a name shows up as default (or nothing) in stack traces, profilers and React DevTools, and editors cannot auto-import it under a stable name. This rule reports a default export that is an anonymous function or class:
- an arrow function, also behind a TS wrapper (
(() => {}) as Handler); - an anonymous function expression or declaration (
export default function () {}); - an anonymous class expression or declaration (
export default class {}).
A named function or class (also a named expression, export default (function load() {})) is fine. Values that are not functions or classes (identifiers, member references, calls, new, literals, templates, objects, arrays, interfaces) are not this rule's concern.
❌ Incorrect
export default () => {};
export default function () {}
export default class {}✅ Correct
export default function load() {}
export default class Store {}
const handler = () => {};
export default handler;
export default { retries: 3 };Options
[
{
"type": "object",
"properties": {
"allowArrowFunction": {
"type": "boolean",
"default": false,
"description": "Allow anonymous arrow function default exports."
},
"allowClassExpression": {
"type": "boolean",
"default": false,
"description": "Allow anonymous class expression default exports."
},
"allowFunctionExpression": {
"type": "boolean",
"default": false,
"description": "Allow anonymous function expression default exports."
}
},
"additionalProperties": false
}
]allowArrowFunction(defaultfalse): accept an anonymous arrow function.allowFunctionExpression(defaultfalse): accept an anonymous function expression or declaration.allowClassExpression(defaultfalse): accept an anonymous class expression or declaration.
When Not To Use It
When your tooling names default exports from the file name and anonymous ones do not hurt debugging.
Use this rule
npm install -D oxlint-plugin-import-next{ "jsPlugins": ["oxlint-plugin-import-next"], "rules": { "import-next/no-anonymous-default-export": "error" }}import { defineConfig } from 'vite-plus';export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-import-next'], rules: { 'import-next/no-anonymous-default-export': 'error', }, },});oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.
Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.