{"record":{"id":"2e1d86724db58274","repo":"oxc-project/oxc","slug":"import-statements-must-come-first","errorCode":null,"errorMessage":"Import statements must come first","messagePattern":"Import statements must come first","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/import/first.rs","lineNumber":14,"sourceCode":"use oxc_ast::ast::{Statement, TSModuleReference};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn first_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Import statements must come first\")\n        .with_help(\"Move import statement to the top of the file\")\n        .with_label(span)\n}\n\nfn absolute_first_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Relative imports before absolute imports are prohibited\")\n        .with_help(\"Move absolute import above relative import\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize)]\npub struct First(AbsoluteFirst);\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]\n#[serde(rename_all = \"kebab-case\")]\nenum AbsoluteFirst {\n    /// Forces absolute imports to be listed before relative imports.\n    ///","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/first.rs#L1-L32","documentation":"Fires from import/first when an import declaration appears after non-import statements in the module, i.e. the imports are not at the top of the file. The diagnostic labels the offending import's span and suggests moving it to the top.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/import/first.rs:14 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the import statement above all other statements","Move any side-effectful code that must run first into a separate module imported before it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}