From 9897e7d8d1d90d5aed622dc52326eb7af3ab0ba0 Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Thu, 15 Oct 2015 18:10:25 -0700 Subject: [PATCH 1/3] Add Section 18.8 - No padded blocks This addresses #483 --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index fdcdccae..f91884f9 100644 --- a/README.md +++ b/README.md @@ -1511,6 +1511,34 @@ Other Style Guides return arr; ``` + - [18.8](#18.8) Do not pad your blocks with blank lines. + + ```javascript + // bad + function bar() { + + console.log(foo); + + } + + // also bad + function bar() { + + console.log(foo); + } + + // still bad + function bar() { + console.log(foo); + + } + + // good + function bar() { + console.log(foo); + } + ``` + **[⬆ back to top](#table-of-contents)** From d276b0c3890e3c6523d91a919b311679800a1a74 Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Thu, 15 Oct 2015 18:15:54 -0700 Subject: [PATCH 2/3] Update 17.2 to allow comments in the first line of a block In #483, justjake said that we should update the style guide to allow single line comments in the first line of a block. --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f91884f9..c1993595 100644 --- a/README.md +++ b/README.md @@ -1248,7 +1248,7 @@ Other Style Guides } ``` - - [17.2](#17.2) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment. + - [17.2](#17.2) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block. ```javascript // bad @@ -1276,6 +1276,14 @@ Other Style Guides return type; } + + // also good + function getType() { + // set the default type to 'no type' + const type = this._type || 'no type'; + + return type; + } ``` - [17.3](#17.3) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`. From 4b5348a5fc597e2f6084aaec76f346e48d957fd2 Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Fri, 16 Oct 2015 10:35:14 -0700 Subject: [PATCH 3/3] Add examples with if statements to 18.8 --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c1993595..028f7295 100644 --- a/README.md +++ b/README.md @@ -1530,13 +1530,10 @@ Other Style Guides } // also bad - function bar() { + if (baz) { - console.log(foo); - } - - // still bad - function bar() { + console.log(qux); + } else { console.log(foo); } @@ -1545,6 +1542,13 @@ Other Style Guides function bar() { console.log(foo); } + + // good + if (baz) { + console.log(qux); + } else { + console.log(foo); + } ```