oxc-project/oxc · warning · OxcDiagnostic

Split initialized '{}' declarations into multiple statements

Error message

Split initialized '{}' declarations into multiple statements.

What it means

Diagnostic from the oxlint `one-var` rule when the `initialized` option is `never`. A single declaration statement that contains more than one initialized declarator (e.g. `let a = 1, b = 2;`) is flagged and must be split; uninitialized declarators in the same statement are governed by the separate `uninitialized` option (one_var.rs:37-60 documents the precedence).

Source

Thrown at crates/oxc_linter/src/rules/eslint/one_var.rs:21

use oxc_ast::{
    AstKind, AstType,
    ast::{Expression, Statement, VariableDeclaration, VariableDeclarationKind},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::{node::NodeId, scope::ScopeId};

use crate::{
    AstNode,
    context::LintContext,
    fixer::Fix,
    rule::{DefaultRuleConfig, Rule},
};

fn one_var_diagnostic(span: Span, message: String) -> OxcDiagnostic {
    OxcDiagnostic::warn(message).with_label(span)
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
/// Controls how variable declarators are grouped into declarations.
enum OneVarMode {
    /// Requires one declaration per variable kind in each applicable scope.
    #[default]
    Always,
    /// Requires each declarator to have its own declaration statement.
    Never,
    /// Requires adjacent declarations of the same kind to be combined.
    Consecutive,
}

/// Options for configuring declaration grouping by kind or initialization state.
///
/// `initialized` and `uninitialized` take precedence over the per-kind option for the

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Split each initialized declarator into its own statement (`oxlint --fix` handles it).
  2. Change `initialized` to `always`/`consecutive` if grouping initialized variables is fine.
  3. Verify you did not accidentally set only one of initialized/uninitialized — they are independent and override per-kind modes.
  4. Inline-disable for tightly-coupled pairs (e.g. `let min = 0, max = 1;`).

Example fix

// before
let a = 1, b = 2;

// after
let a = 1;
let b = 2;
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — align initialized/uninitialized with your real style
{ "rules": { "one-var": ["warn", { "initialized": "always", "uninitialized": "consecutive" }] } }

Prevention

When it happens

Trigger: Configure `"one-var": [{ "initialized": "never" }]` and declare two initialized variables in one statement.

Common situations: Styles that split initialized declarations (each with its own comment/initializer) but allow grouped hoists like `let a, b;`; migrating from a shared config where initialized and uninitialized were treated differently; codemod output that collapses declarations.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/22341667962340cd. Report an issue: GitHub.