{"record":{"id":"b67d248d9ccb5c0a","repo":"oxc-project/oxc","slug":"name-was-used-before-it-was-defined","errorCode":null,"errorMessage":"'{name}' was used before it was defined.","messagePattern":"'(.+?)' was used before it was defined\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_use_before_define.rs","lineNumber":27,"sourceCode":"    reference::Reference,\n    scope::ScopeId,\n    symbol::{SymbolFlags, SymbolId},\n};\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_use_before_define_diagnostic(\n    name: &str,\n    usage_span: Span,\n    declaration_span: Option<Span>,\n) -> OxcDiagnostic {\n    let diagnostic = OxcDiagnostic::warn(format!(\"'{name}' was used before it was defined.\"))\n        .with_label(usage_span.primary_label(\"used here\"))\n        .with_help(\"Move the declaration before any references to it, or remove the reference if it is not needed.\");\n    if let Some(declaration_span) = declaration_span.filter(|span| !span.is_unspanned()) {\n        diagnostic.and_label(declaration_span.label(\"defined here\"))\n    } else {\n        diagnostic\n    }\n}\n\n#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoUseBeforeDefineConfig {\n    /// Allow named exports that appear before declaration.\n    allow_named_exports: bool,\n    /// Check class declarations.\n    classes: bool,\n    /// Check enum declarations.\n    enums: bool,","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/eslint/no_use_before_define.rs#L9-L45","documentation":"Diagnostic from oxlint's no-use-before-define rule. An identifier is referenced at a point where its declaration has not been reached in source order; for let/const/class/enum bindings this is a runtime TDZ ReferenceError, for hoisted var/function it merely hurts readability. Config flags control which kinds are checked (defaults: classes, enums, functions, typedefs, variables all true; ignoreTypeReferences true; allowNamedExports false).","triggerScenarios":"Calling a const arrow function before its declaration; new Foo() above class Foo {}; referencing an enum member before the enum; using a variable declared with let later in the same scope.","commonSituations":"Mutually recursive helpers written bottom-up; hoisting-reliant code migrated to const arrow functions; circular imports; named exports referenced before declaration in module scope.","solutions":["Move the declaration above the first use.","Convert const fn = () => {} to a hoisted function fn() {} when early calls are intended.","Relax specific kinds in .oxlintrc.json, e.g. { \"functions\": false } (same for classes/variables/enums/typedefs).","For type-only forward references, keep \"ignoreTypeReferences\": true (default) instead of disabling the rule."],"exampleFix":"// before\nconst main = () => helper();\nconst helper = () => 1;\n// after\nconst helper = () => 1;\nconst main = () => helper();","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare before use, especially for const, class, and enum bindings (TDZ crashes at runtime otherwise).","Use function declarations when calls must precede definitions.","Tune the rule's functions/classes/variables/enums/typedefs flags to your team's style once, in .oxlintrc.json, instead of per-file disables.","Keep \"ignoreTypeReferences\": true (default) so legitimate forward type references do not fire."],"tags":["eslint","oxlint","hoisting","tdz","declaration-order"],"backgroundTag":"use-before-define","analyzedSha":"a3d33dda7cb69da23db4fcaa2c0c05de61e760a1","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}