oxc-project/oxc · warning · OxcDiagnostic
Combine this with the previous '{}' statement.
Error message
Combine this with the previous '{}' statement. What it means
Diagnostic from the oxlint `one-var` rule. It tells you that a variable declaration should be merged with a preceding declaration of the same kind in the same scope. It appears in two shapes: default mode `always` when two same-kind declarations exist in one scope (one_var.rs:219-228), and `consecutive` mode when both the initialized and uninitialized options are `consecutive` for adjacent same-kind statements (one_var.rs:155-167). The `{}` placeholder is filled with `var`, `let`, or `const`.
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 theView on GitHub (pinned to e1e7af627c)
Solutions
- Merge the declarations: `var foo = 1; var bar = 2;` becomes `var foo = 1, bar = 2;` (run `oxlint --fix`, the rule is conditionally fixable).
- If you prefer one declaration per variable, configure `"one-var": "never"`.
- Use `consecutive` if you only want adjacent same-kind statements joined.
- Add an inline disable comment where merging would hurt readability (e.g. long initializers).
Example fix
// before var foo = 1; var bar = 2; // after var foo = 1, bar = 2;
Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — choose the grouping mode explicitly
{ "rules": { "one-var": ["warn", "never"] } } // if you prefer one per statement Prevention
- Decide always vs never vs consecutive up front and share the config; the default is "always".
- Run `oxlint --fix` on a quiet branch when first enabling one-var — most messages are auto-fixable.
- During refactors, re-check that moved declarations still satisfy the grouping mode.
When it happens
Trigger: Default config `"one-var": "always"` with `var foo = 1; var bar = 2;` in the same function; or `[{ "initialized": "consecutive", "uninitialized": "consecutive" }]` with two adjacent `let` statements.
Common situations: Codebases where developers declare variables as they go and the house style is one grouped declaration; enabling one-var without deciding always vs never first; legacy `var` heavy code; codemods that emit one declaration per variable.
Related errors
- Combine this with the previous '{}' statement with initializ
- Combine this with the previous '{}' statement with uninitial
- Split '{}' declarations into multiple statements.
- Split initialized '{}' declarations into multiple statements
- Split uninitialized '{}' declarations into multiple statemen
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/8f9b5d09a1f6f498.
Report an issue: GitHub.