Skip to content
← Back to rules

eslint/one-var Style

🛠️ An auto-fix is available for this rule for some violations.

What it does ​

Enforces variables to be declared either together or separately.

Why is this bad? ​

Consistent declaration grouping makes variable lifetimes and initialization patterns easier to scan. This rule can require one declaration per scope, one declarator per statement, or grouping only consecutive declarations.

Examples ​

Examples of incorrect code for this rule:

js
var foo = 1;
var bar = 2;

Examples of correct code for this rule:

js
var foo = 1,
  bar = 2;

Configuration ​

Enforces consistent grouping of variable declarations.

type: object

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "one-var": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "one-var": "error",
  },
});
bash
oxlint --deny one-var

Version ​

This rule was added in v1.78.0.

References ​