src/content/docs/linter/rules/use-consistent-arrow-return.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.2.3` - Diagnostic Category: [`lint/style/useConsistentArrowReturn`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`arrow-body-style`](https://eslint.org/docs/latest/rules/arrow-body-style){
"linter": {
"rules": {
"style": {
"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:
"use strict"), orreturn 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,
}
};
};
const foo = () => 0;
const bar = () => { "use strict"; return 1 }
const baz = () => { /* intentional */ return x }
const qux = () => ({ a: 1 }) // already concise with parens