{"record":{"id":"30e86ae50a6d2d7f","repo":"oxc-project/oxc","slug":"split-requires-to-be-separated-into-a-single-block","errorCode":null,"errorMessage":"Split requires to be separated into a single block.","messagePattern":"Split requires to be separated into a single block\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/one_var.rs","lineNumber":21,"sourceCode":"\nuse oxc_ast::{\n    AstKind, AstType,\n    ast::{Expression, Statement, VariableDeclaration, VariableDeclarationKind},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::{node::NodeId, scope::ScopeId};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::Fix,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn one_var_diagnostic(span: Span, message: String) -> OxcDiagnostic {\n    OxcDiagnostic::warn(message).with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"lowercase\")]\n/// Controls how variable declarators are grouped into declarations.\nenum OneVarMode {\n    /// Requires one declaration per variable kind in each applicable scope.\n    #[default]\n    Always,\n    /// Requires each declarator to have its own declaration statement.\n    Never,\n    /// Requires adjacent declarations of the same kind to be combined.\n    Consecutive,\n}\n\n/// Options for configuring declaration grouping by kind or initialization state.\n///\n/// `initialized` and `uninitialized` take precedence over the per-kind option for the","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/one_var.rs#L3-L39","documentation":"Diagnostic from the oxlint `one-var` rule when `separateRequires: true` is combined with a grouping mode of `always`. It fires when one declaration statement mixes `require(...)` initializers with other initializers, e.g. `var fs = require('fs'), count = 0;`. The rule wants CommonJS requires isolated in their own declaration block (one_var.rs:137-146).","triggerScenarios":"Set `\"one-var\": [{ \"initialized\": \"always\", \"separateRequires\": true }]` (or plain \"always\" with separateRequires) and declare a require together with a normal variable in a single `var`/`let` statement.","commonSituations":"Node.js/CommonJS codebases converted to a shared lint config; mixed browser+Node monorepos where the same config is reused; generated code that collapses imports and locals into one var statement.","solutions":["Split the declaration so all `require()` calls live in one statement and other variables in another (the rule is conditionally fixable via --fix in many cases).","Set `separateRequires: false` if you do not want requires treated specially.","Scope the option per declaration kind (const/let/var) instead of globally.","Disable `one-var` for the file if the grouping is intentional."],"exampleFix":"// before\nvar fs = require('fs'), count = 0;\n\n// after\nvar fs = require('fs');\nvar count = 0;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — only special-case requires if you really want it\n{ \"rules\": { \"one-var\": [\"warn\", { \"initialized\": \"always\", \"separateRequires\": false }] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep require() calls in their own declaration statement by convention.","Document the interaction: separateRequires only changes behavior when the mode is \"always\".","Add oxlint to lint-staged so grouped requires get split before commit."],"tags":["oxlint","eslint","style","commonjs","require","variables"],"backgroundTag":"eslint-one-var","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"}