Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2 discrepancies from current JS standards #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1245,29 +1245,12 @@ Other Style Guides
```

- [15.4](#15.4) <a name='15.4'></a> 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) <a name='15.5'></a> 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) <a name='15.5'></a> 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;
Expand All @@ -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) <a name='15.5'></a> Ternaries should not be nested and generally be single line expressions.
Expand Down Expand Up @@ -1489,12 +1487,12 @@ Other Style Guides

## Whitespace

- [18.1](#18.1) <a name='18.1'></a> 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) <a name='18.1'></a> 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
Expand All @@ -1504,7 +1502,7 @@ Other Style Guides

// good
function baz() {
∙∙const name;
∙∙∙∙const name;
}
```

Expand Down