{"record":{"id":"982f983e6783c414","repo":"oxc-project/oxc","slug":"assign-array-to-a-variable-before-exporting-as-mod","errorCode":null,"errorMessage":"Assign array to a variable before exporting as module default","messagePattern":"Assign array 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":181,"sourceCode":"                    \"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                }\n            }\n        }\n    }\n}\n\n#[test]","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs#L163-L199","documentation":"Diagnostic from the oxlint rule import/no-anonymous-default-export (style category). It fires when the default export is an array literal, e.g. `export default []`. Anonymous array exports get no stable identifier, hurting grepability, auto-import, and fast-refresh in some bundlers; `allowArray` defaults to false.","triggerScenarios":"Any `export default [...]` (including the empty array `export default []`) in a file linted with the rule enabled and without `{ \"allowArray\": true }`. Emitted by the `ExportDefaultDeclarationKind::ArrayExpression(_) if !self.allow_array` arm in crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:181.","commonSituations":"Config/constant modules like `export default [\"en\", \"de\"]` or route tables; codemods that inline arrays into export statements; teams adopting a strict import-plugin preset (e.g. Airbnb-style) that leaves allowArray off.","solutions":["Assign the array to a named constant first: `const ROUTES = []; export default ROUTES;`","Enable the option if array defaults are fine: `[\"warn\", { \"allowArray\": true }]`","Suppress the single occurrence with a disable comment if the file is generated or intentional"],"exampleFix":"// before\nexport default [\"react\", \"vue\", \"svelte\"];\n\n// after\nconst SUPPORTED_FRAMEWORKS = [\"react\", \"vue\", \"svelte\"];\nexport default SUPPORTED_FRAMEWORKS;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"import/no-anonymous-default-export\": [\"warn\", { \"allowArray\": true }] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to `const NAME = [...]; export default NAME;` for constant tables","Record allowArray/allowLiteral decisions in the team lint config once","Let `oxlint --fix`-able sister rules (e.g. no-duplicates) run in the same commit to keep import blocks clean"],"tags":["lint","oxlint","imports","default-export","arrays","style"],"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-14T00:17:10.932Z"}