close

one-var

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'one-var': 'error',
    },
  },
]);

Enforce variables to be declared either together or separately in functions.

Upstream status: This rule is frozen in ESLint — it is no longer accepting new features and is not part of the recommended config. Bug-fix-only.

Rule Details

This rule enforces a single variable declaration style in a scope. Variables can be declared together in a single statement or each in a separate statement, depending on the configured mode. The rule supports var, let, const, using, and await using declarations.

Examples of incorrect code for this rule:

function foo() {
    var bar;
    var baz;
}

function foo() {
    let bar;
    let baz;
}

function foo() {
    const bar = 1;
    const baz = 2;
}

Examples of correct code for this rule:

function foo() {
    var bar, baz;
}

function foo() {
    let bar, baz;
}

function foo() {
    const bar = 1, baz = 2;
}

Options

This rule accepts a string or an object as its only option.

String option

The string option configures the same mode for every declaration kind:

  • "always" (default) — requires one variable declaration per scope.
  • "never" — requires multiple separate variable declarations per scope.
  • "consecutive" — requires consecutive declarations of the same kind to be combined into a single statement.
{ "one-var": ["error", "never"] }
function foo() {
    var bar;
    var baz;
}
{ "one-var": ["error", "consecutive"] }
function foo() {
    var bar, baz;
    qux();
    var quux;
}

Object option (per kind)

The object form lets you choose a different mode for each declaration kind:

  • "var", "let", "const", "using", "awaitUsing" — each accepts "always", "never", or "consecutive".
  • "separateRequires" — when true, treats require() calls as a separate group from other initialized declarations of the same kind.
{ "one-var": ["error", { "var": "always", "let": "never", "const": "never" }] }
function foo() {
    var bar, baz;
    let qux;
    let norf;
    const a = 1;
    const b = 2;
}
{ "one-var": ["error", { "separateRequires": true, "var": "always" }] }
var foo = require('foo');
var bar = require('bar');
var baz = 'baz', qux = 'qux';

Object option (initialized / uninitialized)

The alternative object form discriminates by initialization status across all kinds:

  • "initialized" — applies to declarations that have an initializer.
  • "uninitialized" — applies to declarations without an initializer.

Both accept "always", "never", or "consecutive".

{ "one-var": ["error", { "initialized": "never", "uninitialized": "always" }] }
function foo() {
    var bar, baz;
    var a = 1;
    var b = 2;
}

Differences from ESLint

  • declare-modified declarations are reported but not auto-fixed. ESLint v10 emits fixes that produce TypeScript parse errors on this input shape: splitting declare var a, b; yields declare var a; var b; (the second statement silently loses ambient semantics), and combining declare var a; declare var b; yields declare var a, var b; (two var keywords, syntactically invalid). rslint deliberately suppresses the fix in these cases to avoid producing broken code; the diagnostic itself is still reported with identical position and message.

Original Documentation