oxc-project/oxc · warning · OxcDiagnostic
Split requires to be separated into a single block.
Error message
Split requires to be separated into a single block.
What it means
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).
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
- 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.
Example fix
// before
var fs = require('fs'), count = 0;
// after
var fs = require('fs');
var count = 0; Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — only special-case requires if you really want it
{ "rules": { "one-var": ["warn", { "initialized": "always", "separateRequires": false }] } } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Combine this with the previous '{}' statement.
- 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
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/30e86ae50a6d2d7f.
Report an issue: GitHub.