one-var
Configuration
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:
Examples of correct code for this rule:
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.
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"— whentrue, treatsrequire()calls as a separate group from other initialized declarations of the same kind.
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".
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: splittingdeclare var a, b;yieldsdeclare var a; var b;(the second statement silently loses ambient semantics), and combiningdeclare var a; declare var b;yieldsdeclare var a, var b;(twovarkeywords, 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.