noReturnAssign
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noReturnAssign - This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Same as
no-return-assign
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noReturnAssign": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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;}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.