Skip to content

Commit ccc1fab

Browse files
committed
Merge pull request #579 from tomekwi/fix-braces-text
[guide] Bring back note about braces
2 parents 619ff1c + 4ca5764 commit ccc1fab

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

README.md

Lines changed: 21 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 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,36 @@ 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 doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments.
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

756759
// good
757-
[1, 2, 3].reduce((y, x) => x + y);
760+
[1, 2, 3].map(number => (
761+
`A long string with the ${number}. It’s so long that we’ve broken it ` +
762+
'over multiple lines!'
763+
));
764+
765+
// bad
766+
[1, 2, 3].map(x => {
767+
const y = x + 1;
768+
return x * y;
769+
});
770+
771+
// good
772+
[1, 2, 3].map((x) => {
773+
const y = x + 1;
774+
return x * y;
775+
});
758776
```
759777
760778
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)