Skip to content

chainedAssignments

Reports using chained assignment expressions (e.g., a = b = c).

✅ This rule is included in the ts stylistic and stylisticStrict presets.

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.

let
let first: any
first
;
let
let second: any
second
;
let first: any
first
=
let second: any
second
= 1;
let
let first: any
first
;
let
let second: any
second
;
let
let third: any
third
;
let first: any
first
=
let second: any
second
=
let third: any
third
=
const getValue: () => number
getValue
();
function
function process(value: number): void
process
(
value: number
value
: number): void {
let
let result: any
result
;
let
let cache: any
cache
;
let result: any
result
=
let cache: any
cache
=
value: number
value
* 2;
}

This rule is not configurable.

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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.