{"record":{"id":"cb082c892202f165","repo":"oxc-project/oxc","slug":"do-not-mix-require-and-other-declarations","errorCode":null,"errorMessage":"Do not mix 'require' and other declarations.","messagePattern":"Do not mix 'require' and other declarations\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/node/no_mixed_requires.rs","lineNumber":19,"sourceCode":"use schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse oxc_ast::{\n    AstKind,\n    ast::{Expression, VariableDeclarator},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_mix_require_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not mix 'require' and other declarations.\").with_label(span)\n}\n\nfn no_mix_core_module_file_computed_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not mix core, module, file and computed requires.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Copy, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", deny_unknown_fields, default)]\nstruct NoMixedRequiresOptions {\n    grouping: bool,\n    allow_call: bool,\n}\n\n#[derive(Debug, Clone, Deserialize, JsonSchema)]\n#[serde(untagged)]\nenum NoMixedRequiresConfig {\n    Grouping(bool),\n    Options(NoMixedRequiresOptions),","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/node/no_mixed_requires.rs#L1-L37","documentation":"Diagnostic from oxlint rule node/no-mixed-requires (style). Within a single var/let/const declaration statement, require-initialized declarators must not be mixed with plain or uninitialized ones. Node community convention keeps module-loading declarations visually separate from other initialization — the CommonJS analogue of ES module imports living apart from regular statements. This base diagnostic is emitted regardless of the rule's options; grouping/allowCall only affect the second diagnostic.","triggerScenarios":"One VariableDeclaration whose declarators include at least one whose init is a require() call (callee is the identifier 'require'; member access like require('events').EventEmitter still counts, and with allowCall, call-chains like require('diagnostics')('x') too) AND at least one declarator that is uninitialized (var foo;) or initialized with a non-require expression. Trigger example: var fs = require('fs'), i = 0;","commonSituations":"ES5-era comma-chained var statements; refactors that appended a variable to an existing require line; enabling the node preset in shared configs surfaces these in old code immediately.","solutions":["Split the statement: requires in their own declaration, other variables in another","Adopt one-declarator-per-line const/let style so mixing becomes structurally impossible","Note no option disables this specific check — only code restructuring (or turning the rule off) silences it"],"exampleFix":"// before\nvar fs = require('fs'),\n    i = 0;\n\n// after\nvar fs = require('fs');\nvar i = 0;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n\"rules\": { \"node/no-mixed-requires\": \"error\" }\n\nnpx oxlint -c .oxlintrc.json --deny-warning .","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One declarator per statement (const a = require('a');) makes mixing structurally impossible","Keep a dedicated requires block at the top of the module, separate from logic declarations","Fix appends to legacy comma-chained var statements by splitting, not extending"],"tags":["node","commonjs","require","style","oxlint"],"backgroundTag":"mixed-require-declarations","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"}