singleVariableDeclarations
Enforces one variable per declaration statement.
✅ This rule is included in the ts logical presets.
Declaring multiple variables in a single statement can reduce readability. Each variable declaration should be on its own line to make the code easier to read and maintain.
Examples
Section titled “Examples”let first, second, third;
const width = 100, height = 200;
for (let index = 0, length = 10; index < length; index++) { console.log(index);}let first;let second;let third;
const width = 100;const height = 200;
// Destructuring is allowed (single binding pattern)const { first, second } = object;const [width, height] = dimensions;
// For-of and for-in loops are finefor (const item of items) { console.log(item);}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you prefer to declare multiple variables in a single statement for brevity, you might choose to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useSingleVarDeclarator - Deno:
single-var-declarator - ESLint:
one-var
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.