From 1899651aa16fd665893473c48c0e03a70021f30f Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Tue, 7 Jun 2016 20:01:48 +1000 Subject: [PATCH] Update documentation --- docs/rules/arrow-body-style.md | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/rules/arrow-body-style.md b/docs/rules/arrow-body-style.md index 25f3b5129b8..0efe4f0a2a7 100644 --- a/docs/rules/arrow-body-style.md +++ b/docs/rules/arrow-body-style.md @@ -1,10 +1,10 @@ # Require braces in arrow function body (arrow-body-style) -Arrow functions can omit braces when there is a single statement in the body. This rule enforces the consistent use of braces in arrow functions. +Arrow functions have two syntactic forms for their function bodies. They may be defined with a *block* body (denoted by curly braces) `() => { ... }` or with a single expression `() => ...`, whose value is implicitly returned. ## Rule Details -This rule can enforce the use of braces around arrow function body. +This rule can enforce or disallow the use of braces around arrow function body. ## Options @@ -12,6 +12,7 @@ The rule takes one option, a string, which can be: * `"always"` enforces braces around the function body * `"as-needed"` enforces no braces where they can be omitted (default) +* `"never"` enforces no braces around the function body (constrains arrow functions to the role of returning an expression) ### "always" @@ -84,3 +85,30 @@ let foo = () => { // do nothing. }; ``` + +### "never" + +When the rule is set to `"never"` the following patterns are considered problems: + +```js +/*eslint arrow-body-style: ["error", "never"]*/ +/*eslint-env es6*/ + +let foo = () => { + return 0; +}; +let foo = (retv, name) => { + retv[name] = true; + return retv; +}; +``` + +The following patterns are not considered problems: + +```js +/*eslint arrow-body-style: ["error", "as-needed"]*/ +/*eslint-env es6*/ + +let foo = () => 0; +let foo = () => ({ foo: 0 }); +```