eslint/no-return-assign Style β
What it does β
Disallows assignment operators in return statements
Why is this bad? β
Assignment is allowed by js in return expressions, but usually, an expression with only one equal sign is intended to be a comparison. However, because of the missing equal sign, this turns to assignment, which is valid js code Because of this ambiguity, itβs considered a best practice to not use assignment in return statements.
Examples β
Examples of incorrect code for this rule:
js
() => (a = b);
function x() {
return (a = b);
}
Examples of correct code for this rule:
js
() => (a = b);
function x() {
var result = (a = b);
return result;
}