Skip to content

noReturnAssign

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noReturnAssign": "error"
}
}
}
}

Disallow assignments in return statements.

In return statements, it is common to mistype a comparison operator (such as ==) as an assignment operator (such as =). Moreover, the use of assignments in a return statement is confusing. Return statements are often considered side-effect free.

function f(a) {
return a = 1;
}
code-block.js:2:12 lint/suspicious/noReturnAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Return statements should not contain assignments.

1 │ function f(a) {
> 2 │ return a = 1;
^^^^^
3 │ }
4 │

Assignments inside return statements are easy to mistake for comparison operators (`==`), and add unexpected side effects to normally-pure code.
If the assignment is intentional, move it outside of the return statement.

function f(a) {
a = 1;
return a;
}
function f(a) {
return a == 1;
}