From 3aabe2c6934a2fef474cde5f0e48172b45979fc5 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Thu, 13 Aug 2015 08:43:33 +0200 Subject: [PATCH] Upgrade half of 8.2 to another rule --- README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fb9020ca..8e0863ca 100644 --- a/README.md +++ b/README.md @@ -602,8 +602,6 @@ - [8.2](#8.2) 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. - In case the expression spans over multiple lines, wrap it in parentheses for better readability. - > Why? Syntactic sugar. It reads well when multiple functions are chained together. > Why not? If you plan on returning an object. @@ -612,12 +610,6 @@ // good [1, 2, 3].map(number => `A string containing the ${number}.`); - // good - [1, 2, 3].map(number => ( - `As time went by, the string containing the ${number} became much ` + - 'longer. So we needed to break it over multiple lines.' - )); - // bad [1, 2, 3].map(number => { let nextNumber = number + 1; @@ -631,7 +623,26 @@ }); ``` - - [8.3](#8.3) If your function only takes a single argument, feel free to omit the parentheses. + - [8.3](#8.3) In case the expression spans over multiple lines, wrap it in parentheses for better readability. + + > Why? It shows clearly where the function starts and ends. + + ```js + // bad + [1, 2, 3].map(number => 'As time went by, the string containing the ' + + `${number} became much longer. So we needed to break it over multiple ` + + 'lines.' + ); + + // good + [1, 2, 3].map(number => ( + `As time went by, the string containing the ${number} became much ` + + 'longer. So we needed to break it over multiple lines.' + )); + ``` + + + - [8.4](#8.4) If your function only takes a single argument, feel free to omit the parentheses. > Why? Less visual clutter.