chainedAssignments
Reports using chained assignment expressions (e.g., a = b = c).
✅ This rule is included in the ts stylistic
preset.
Chained assignments can be hard to read and can lead to unexpected behavior with variable scoping and type inference. Each assignment creates a reference to the same value, which may cause confusion when dealing with mutable values.
Examples
Section titled “Examples”let first;let second;first = second = 1;
let first;let second;let third;first = second = third = getValue();
function process(value: number): void { let result; let cache; result = cache = value * 2;}
let first;let second;first = 1;second = 1;
let first;let second;let third;const value = getValue();first = value;second = value;third = value;
function process(value: number): void { let result; let cache; const computed = value * 2; result = computed; cache = computed;}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase frequently uses chained assignments as a concise idiom and you find them readable, you might choose to disable this rule. However, breaking chained assignments into separate statements generally improves code clarity and reduces potential for bugs.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-multi-assign
- Oxlint:
eslint/no-multi-assign
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.