From 287eb78c0004a183d0698c8d8e87e5a680dd1070 Mon Sep 17 00:00:00 2001 From: Nara Kasbergen Date: Fri, 17 Jun 2016 17:44:45 -0400 Subject: [PATCH] Fix 2 discrepancies from current JS standards --- README.md | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 32c966ce98..9909ca6a51 100644 --- a/README.md +++ b/README.md @@ -1245,29 +1245,12 @@ Other Style Guides ``` - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. - - [15.5](#15.5) Use braces to create blocks in `case` and `default` clauses that contain lexical declarations (e.g. `let`, `const`, `function`, and `class`). - - > Why? Lexical declarations are visible in the entire `switch` block but only get initialized when assigned, which only happens when its `case` is reached. This causes problems when multiple `case` clauses attempt to define the same thing. + - [15.5](#15.5) Do not use braces to create blocks in `case` and `default` clauses, even if they contain lexical declarations (e.g. `let`, `const`, `function`, and `class`). eslint rules: [`no-case-declarations`](http://eslint.org/docs/rules/no-case-declarations.html). ```javascript // bad - switch (foo) { - case 1: - let x = 1; - break; - case 2: - const y = 2; - break; - case 3: - function f() {} - break; - default: - class C {} - } - - // good switch (foo) { case 1: { let x = 1; @@ -1288,6 +1271,21 @@ Other Style Guides class C {} } } + + // good + switch (foo) { + case 1: + let x = 1; + break; + case 2: + const y = 2; + break; + case 3: + function f() {} + break; + default: + class C {} + } ``` - [15.5](#15.5) Ternaries should not be nested and generally be single line expressions. @@ -1489,12 +1487,12 @@ Other Style Guides ## Whitespace - - [18.1](#18.1) Use soft tabs set to 2 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) + - [18.1](#18.1) Use soft tabs set to 4 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) ```javascript // bad function foo() { - ∙∙∙∙const name; + ∙∙const name; } // bad @@ -1504,7 +1502,7 @@ Other Style Guides // good function baz() { - ∙∙const name; + ∙∙∙∙const name; } ```