diff --git a/README.md b/README.md index cce04248..f854fed8 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,8 @@ Other Style Guides > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. + eslint rules: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html). + ```javascript // bad var a = 1; @@ -105,6 +107,8 @@ Other Style Guides > Why? `let` is block-scoped rather than function-scoped like `var`. + eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html). + ```javascript // bad var count = 1; @@ -137,6 +141,8 @@ Other Style Guides - [3.1](#3.1) Use the literal syntax for object creation. + eslint rules: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html). + ```javascript // bad const item = new Object(); @@ -209,6 +215,8 @@ Other Style Guides - [3.5](#3.5) Use object method shorthand. + eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). + ```javascript // bad const atom = { @@ -234,6 +242,8 @@ Other Style Guides > Why? It is shorter to write and descriptive. + eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). + ```javascript const lukeSkywalker = 'Luke Skywalker'; @@ -283,6 +293,8 @@ Other Style Guides - [4.1](#4.1) Use the literal syntax for array creation. + eslint rules: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html). + ```javascript // bad const items = new Array(); @@ -399,6 +411,8 @@ Other Style Guides - [6.1](#6.1) Use single quotes `''` for strings. + eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html). + ```javascript // bad const name = "Capt. Janeway"; @@ -431,6 +445,8 @@ Other Style Guides > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. + eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html). + ```javascript // bad function sayHi(name) { @@ -601,7 +617,7 @@ Other Style Guides - [7.11](#7.11) Spacing in a function signature. > Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name. - + ```javascript // bad const f = function(){}; @@ -623,6 +639,8 @@ Other Style Guides > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration. + eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html). + ```javascript // bad [1, 2, 3].map(function (x) { @@ -643,6 +661,8 @@ Other Style Guides > Why not? If you plan on returning an object. + eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html). + ```javascript // good [1, 2, 3].map(number => `A string containing the ${number}.`); @@ -683,6 +703,8 @@ Other Style Guides > Why? Less visual clutter. + eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html). + ```js // good [1, 2, 3].map(x => x * x); @@ -861,6 +883,8 @@ Other Style Guides > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects. + eslint rules: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html). + ```javascript const numbers = [1, 2, 3, 4, 5]; @@ -893,6 +917,8 @@ Other Style Guides - [12.1](#12.1) Use dot notation when accessing properties. + eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html). + ```javascript const luke = { jedi: true, @@ -940,6 +966,8 @@ Other Style Guides > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. + eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html). + ```javascript // bad const items = getItems(), @@ -1134,6 +1162,8 @@ Other Style Guides - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: + eslint rules: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html). + + **Objects** evaluate to **true** + **Undefined** evaluates to **false** + **Null** evaluates to **false** @@ -1206,6 +1236,8 @@ Other Style Guides - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your `if` block's closing brace. + eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html). + ```javascript // bad if (test) { @@ -1336,6 +1368,8 @@ Other Style Guides - [18.1](#18.1) Use soft tabs set to 2 spaces. + eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html). + ```javascript // bad function () { @@ -1355,6 +1389,8 @@ Other Style Guides - [18.2](#18.2) Place 1 space before the leading brace. + eslint rules: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html). + ```javascript // bad function test(){ @@ -1381,6 +1417,8 @@ Other Style Guides - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations. + eslint rules: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html). + ```javascript // bad if(isJedi) { @@ -1405,6 +1443,8 @@ Other Style Guides - [18.4](#18.4) Set off operators with spaces. + eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html). + ```javascript // bad const x=y+5; @@ -1536,6 +1576,8 @@ Other Style Guides - [18.8](#18.8) Do not pad your blocks with blank lines. + eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html). + ```javascript // bad function bar() { @@ -1568,6 +1610,8 @@ Other Style Guides - [18.9](#18.9) Do not add spaces inside parentheses. + eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html). + ```javascript // bad function bar( foo ) { @@ -1592,6 +1636,8 @@ Other Style Guides - [18.10](#18.10) Do not add spaces inside brackets. + eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html). + ```javascript // bad const foo = [ 1, 2, 3 ]; @@ -1604,6 +1650,8 @@ Other Style Guides - [18.11](#18.11) Add spaces inside curly braces. + eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html). + ```javascript // bad const foo = {clark: 'kent'}; @@ -1618,6 +1666,8 @@ Other Style Guides - [19.1](#19.1) Leading commas: **Nope.** + eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html). + ```javascript // bad const story = [ @@ -1652,6 +1702,8 @@ Other Style Guides - [19.2](#19.2) Additional trailing comma: **Yup.** + eslint rules: [`no-comma-dangle`](http://eslint.org/docs/rules/no-comma-dangle.html). + > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. ```javascript @@ -1700,6 +1752,8 @@ Other Style Guides - [20.1](#20.1) **Yup.** + eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html). + ```javascript // bad (function () { @@ -1820,6 +1874,8 @@ Other Style Guides - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. + eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html). + ```javascript // bad const OBJEcttsssss = {}; @@ -1857,6 +1913,8 @@ Other Style Guides - [22.4](#22.4) Use a leading underscore `_` when naming private properties. + eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html). + ```javascript // bad this.__firstName__ = 'Panda'; @@ -1894,6 +1952,7 @@ Other Style Guides ``` - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class. + ```javascript // file contents class CheckBox {