arrow-body-style
Configuration
Rule Details
This rule enforces or disallows the use of braces around arrow function bodies.
Arrow functions have two syntactic forms for their function bodies. They may be defined with a block body (denoted with curly braces) () => { ... } or with a single expression () => ..., whose value is implicitly returned.
This rule has a string option and an object option.
The string option is one of:
"as-needed"(default) enforces no braces where they can be omitted."always"enforces braces around the function body."never"enforces no braces around the function body (forbids any use of braces).
The object option (only available with "as-needed"):
requireReturnForObjectLiteral: truerequires braces and an explicit return for object literals. Default isfalse.
"as-needed"
Examples of incorrect code for this rule with the default "as-needed" option:
Examples of correct code for this rule with the default "as-needed" option:
requireReturnForObjectLiteral
Examples of incorrect code for this rule with the { "requireReturnForObjectLiteral": true } option:
Examples of correct code for this rule with the { "requireReturnForObjectLiteral": true } option:
"always"
Examples of incorrect code for this rule with the "always" option:
Examples of correct code for this rule with the "always" option:
"never"
Examples of incorrect code for this rule with the "never" option:
Examples of correct code for this rule with the "never" option:
Differences from ESLint
- When an arrow function with a block body is immediately followed on the next line (no semicolon in between) by a token starting with
/— e.g.() => { return x }then/re/.test(y)— rslint reports the rule but does not auto-fix it; ESLint removes the braces.