menu

prefer-tuple-swap

Prefer tuple assignment for swaps

Swapping two places through a temporary spreads one parallel assignment across three statements. Instead, you SHOULD assign the reversed tuple directly to both places.

Reported

1function swap(left: int32, right: int32): (int32, int32) {2    let first = left;3    let second = right;4    const temporary = first;5    first = second;6    second = temporary;7 8    return (first, second);9}

Accepted

1function swap(left: int32, right: int32): (int32, int32) {2    let first = left;3    let second = right;4    (first, second) = (second, first);5 6    return (first, second);7}