Skip to content

Commit 32ec9dd

Browse files
author
Tomek Wiszniewski
committed
Make 8.2 and 8.4 simpler and more explicit
1 parent bc9faf6 commit 32ec9dd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ Other Style Guides
699699
});
700700
```
701701
702-
- [8.2](#8.2) <a name='8.2'></a> If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise add the parentheses, braces, and use a `return` statement.
702+
- [8.2](#8.2) <a name='8.2'></a> If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement.
703703
704704
> Why? Syntactic sugar. It reads well when multiple functions are chained together.
705705
@@ -743,18 +743,30 @@ Other Style Guides
743743
```
744744
745745
746-
- [8.4](#8.4) <a name='8.4'></a> If your function only takes a single argument, feel free to omit the parentheses.
746+
- [8.4](#8.4) <a name='8.4'></a> If your function takes a single argument and consists of a single expression, omit the parentheses.
747747
748748
> Why? Less visual clutter.
749749
750750
eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html).
751751
752752
```js
753+
// bad
754+
[1, 2, 3].map((x) => x * x);
755+
753756
// good
754757
[1, 2, 3].map(x => x * x);
755758

759+
// bad
760+
[1, 2, 3].reduce(x => {
761+
const y = x + 1;
762+
return x * y;
763+
});
764+
756765
// good
757-
[1, 2, 3].reduce((y, x) => x + y);
766+
[1, 2, 3].reduce((x) => {
767+
const y = x + 1;
768+
return x * y;
769+
});
758770
```
759771
760772
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)