Skip to content

useConsistentArrowReturn

biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentArrowReturn": "error"
}
}
}
}

Enforce consistent arrow function bodies.

This rule enforces the use of arrow functions with no body block when the function body consists of a single return statement. This rule does not report when:

  • the function body contains directives (e.g. "use strict"), or
  • the body (or its descendants) contain comments, or
  • the single return has no argument (return;).

The fix wraps expressions in parentheses when required for correctness (e.g. object literals and sequence expressions).

const bar = () => {
return {
bar: {
foo: 1,
bar: 2,
}
};
};
code-block.js:1:14 lint/nursery/useConsistentArrowReturn  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The body of this arrow function contains a single return statement.

> 1 │ const bar = () => {
^^^^^^^
> 2 │ return {
> 3 │ bar: {
> 4 │ foo: 1,
> 5 │ bar: 2,
> 6 │ }
> 7 │ };
> 8 │ };
^
9 │

Safe fix: Remove the return statement.

1 - ·const·bar·=·()·=>·{
2 - ·····return·{
1+ ·const·bar·=·()·=>·({
3 2 bar: {
4 3 foo: 1,
5 4 bar: 2,
6 5 }
7 - ·····};
8 - ·};
6+ ·····});
9 7

const foo = () => 0;
const bar = () => { "use strict"; return 1 }
const baz = () => { /* intentional */ return x }
const qux = () => ({ a: 1 }) // already concise with parens