Aller au contenu

noReturnAssign

Ce contenu n’est pas encore disponible dans votre langue.

biome.json
{
"linter": {
"rules": {
"nursery": {
"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/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

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