{"record":{"id":"867c8a3e1c29b03b","repo":"oxc-project/oxc","slug":"assign-instance-to-a-variable-before-exporting-as","errorCode":null,"errorMessage":"Assign instance to a variable before exporting as module default","messagePattern":"Assign instance to a variable before exporting as module default","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs","lineNumber":175,"sourceCode":"                    \"Assign arrow function to a variable before exporting as module default\",\n                ));\n            }\n            ExportDefaultDeclarationKind::ObjectExpression(_) if !self.allow_object => {\n                ctx.diagnostic(no_anonymous_default_export_diagnostic(\n                    export_decl.span,\n                    \"Assign object to a variable before exporting as module default\",\n                ));\n            }\n            ExportDefaultDeclarationKind::CallExpression(_) if !self.allow_call_expression => {\n                ctx.diagnostic(no_anonymous_default_export_diagnostic(\n                    export_decl.span,\n                    \"Assign call result to a variable before exporting as module default\",\n                ));\n            }\n            ExportDefaultDeclarationKind::NewExpression(_) if !self.allow_new => {\n                ctx.diagnostic(no_anonymous_default_export_diagnostic(\n                    export_decl.span,\n                    \"Assign instance to a variable before exporting as module default\",\n                ));\n            }\n            ExportDefaultDeclarationKind::ArrayExpression(_) if !self.allow_array => {\n                ctx.diagnostic(no_anonymous_default_export_diagnostic(\n                    export_decl.span,\n                    \"Assign array to a variable before exporting as module default\",\n                ));\n            }\n            _ => {\n                if let Some(expr) = export_decl.declaration.as_expression()\n                    && !self.allow_literal\n                    && (expr.is_literal() || matches!(expr, Expression::TemplateLiteral(_)))\n                {\n                    ctx.diagnostic(no_anonymous_default_export_diagnostic(\n                        export_decl.span,\n                        \"Assign literal to a variable before exporting as module default\",\n                    ));\n                }","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs#L157-L193","documentation":"Diagnostic from the oxlint rule import/no-anonymous-default-export (style category). It fires when a module's default export is a `new` expression, e.g. `export default new Foo()`. The rule wants default exports bound to a named identifier so the same name is greppable at the declaration site and at import sites; `allowNew` defaults to false, so instance exports are flagged (note `allowCallExpression` defaults to true, so `export default foo()` is not flagged).","triggerScenarios":"Any `export default new SomeClass(...)` in a file linted with this rule enabled and without the option `{ \"allowNew\": true }`. Emitted by the `ExportDefaultDeclarationKind::NewExpression(_) if !self.allow_new` arm in crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:175.","commonSituations":"Singleton-style modules such as `export default new HttpClient()` or `export default new ConfigStore()` written before the rule was adopted; teams migrating from eslint-plugin-import configs where they had toggled allowNew; enabling the whole import plugin category in .oxlintrc.json without reviewing per-rule options.","solutions":["Assign the instance to a named constant, then export the constant: `const client = new HttpClient(); export default client;`","If anonymous instance exports are acceptable, enable the option: `[\"warn\", { \"allowNew\": true }]` in the oxlint/eslint config","Suppress for a one-off case with an `// oxlint-disable-next-line import/no-anonymous-default-export` comment (or the eslint-disable equivalent)"],"exampleFix":"// before\nexport default new HttpClient();\n\n// after\nconst httpClient = new HttpClient();\nexport default httpClient;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — decide the policy up front so CI is predictable\n{ \"rules\": { \"import/no-anonymous-default-export\": [\"warn\", { \"allowNew\": true }] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt a repo convention that default exports are named identifiers, enforced in review","Make anonymous-exception decisions once in the shared lint config, not per file","Run oxlint in pre-commit/CI so violations surface before merge"],"tags":["lint","oxlint","imports","default-export","style","eslint-plugin-import"],"backgroundTag":"anonymous-default-export","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}