{"record":{"id":"2baec7c551ff36a8","repo":"oxc-project/oxc","slug":"export-statements-should-appear-at-the-end-of-the","errorCode":null,"errorMessage":"Export statements should appear at the end of the file","messagePattern":"Export statements should appear at the end of the file","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/exports_last.rs","lineNumber":10,"sourceCode":"use itertools::Itertools;\nuse oxc_ast::ast::{ModuleDeclaration, Statement};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn exports_last_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Export statements should appear at the end of the file\")\n        .with_help(\"Move this export to the end of the file, after all other statements.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ExportsLast;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule enforces that all exports are declared at the bottom of the file.\n    /// This rule will report any export declarations that comes before any non-export statements.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Exports scattered throughout the file can lead to poor code readability\n    /// and increase the cost of locating the export quickly\n    ///","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/exports_last.rs#L1-L28","documentation":"oxlint's `import/exports-last` rule: within a module, every export declaration must appear after all non-export statements. The implementation scans the Program body, finds the position of the last non-export statement, and reports any module declaration sitting before it.","triggerScenarios":"`export const helper = () => 1;` followed later in the same file by any non-export statement — a plain const, function declaration, or side-effect call positioned after the export.","commonSituations":"Files exporting constants at the top for readability while helpers grow beneath; codemods inserting statements after existing exports; teams whose convention keeps the public API at the top of the file.","solutions":["Move export declarations below the last non-export statement","Or switch to bottom exports: define everything first, then one `export { a, b, c };` block at the end","Disable the rule if top-of-file exports are the accepted team style"],"exampleFix":"// before — export appears before a non-export statement\nexport const helper = () => 1;\nconst other = compute();\n\n// after\nconst other = compute();\nexport const helper = () => 1;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{\n  \"plugins\": [\"import\"],\n  \"rules\": { \"import/exports-last\": \"warn\" }\n}\n// CI gate: npx oxlint src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt bottom-of-file export blocks (define everything, then export { ... }) so the rule is satisfied by construction","Watch codemods that insert statements after existing exports","If the team prefers top-of-file exports, turn the rule off rather than fighting it","Run oxlint in lint-staged so misplaced exports are flagged at commit time"],"tags":["lint","oxlint","import-plugin","style","esm","file-organization"],"backgroundTag":"export-statement-placement","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"}