{"record":{"id":"c68265164984fe97","repo":"oxc-project/oxc","slug":"exporting-default-is-restricted","errorCode":null,"errorMessage":"Exporting 'default' is restricted.","messagePattern":"Exporting 'default' is restricted\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_restricted_exports.rs","lineNumber":47,"sourceCode":"    Named,\n    DefaultFrom,\n    NamedFrom,\n    NamespaceFrom,\n}\n\nfn no_restricted_default_exports_diagnostic(\n    span: Span,\n    export_type: DefaultExportType,\n) -> OxcDiagnostic {\n    let warn = match export_type {\n        DefaultExportType::DefaultFrom => \"Reexporting 'default' export is restricted.\",\n        DefaultExportType::Direct => \"Exporting 'default' is restricted.\",\n        DefaultExportType::Named => \"Exporting named value as default is restricted.\",\n        DefaultExportType::NamedFrom => \"Reexporting named export as default is restricted.\",\n        DefaultExportType::NamespaceFrom => \"Reexporting namespace as default is restricted.\",\n    };\n\n    OxcDiagnostic::warn(warn).with_help(\"Use named export instead.\").with_label(span)\n}\n\nfn no_restricted_named_exports_diagnostic(span: Span, name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is restricted from being used as an exported name.\"))\n        .with_help(\"Rename this export.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoRestrictedExports(Box<NoRestrictedExportsConfig>);\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoRestrictedExportsConfig {\n    /// An array of strings, where each string is a name to be restricted.\n    ///\n    /// Example of **incorrect** code for `\"restrictedNamedExports\": [\"foo\"]`:\n    ///","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_restricted_exports.rs#L29-L65","documentation":"The `Direct` branch of `no-restricted-exports`. It fires when the config sets `restrictedDefaultExports.default` and the module contains a direct default export (`export default ...`). Part of enforcing named-export-only codebases.","triggerScenarios":"`\"no-restricted-exports\": [\"error\", { \"restrictedDefaultExports\": { \"default\": true } }]` combined with any of `export default function foo() {}`, `export default 42;`, `export default class C {}`.","commonSituations":"Shared library conventions (Airbnb-style) that ban default exports; migrating a codebase to named exports and enforcing it in CI.","solutions":["Convert to a named declaration: `export const Foo = ...;` / `export function foo() {}`.","Update internal consumers to use the named import.","If intentional, drop the `default` key from `restrictedDefaultExports` or disable the rule."],"exampleFix":"// before\nexport default function run() {}\n\n// after\nexport function run() {}","handlingStrategy":"validation","validationCode":"// Cheap file-level guard for a named-exports-only convention\nconst src = require('node:fs').readFileSync(file, 'utf8');\nif (/^export\\s+default\\b/m.test(src)) {\n  console.error(`${file}: default exports are not allowed`);\n  process.exitCode = 1;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on named exports in the style guide and enforce via `restrictedDefaultExports.default`.","Use codemods (jscodeshift) when converting default exports so consumers update in the same commit.","Review `export default` occurrences in PR diff templates."],"tags":["lint","eslint","no-restricted-exports","es-modules","configuration"],"backgroundTag":"restricted-export-config","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"}