From 5fd7c6f08c0650ed67297fc83c8a0590c9a92cc8 Mon Sep 17 00:00:00 2001 From: Estelle Date: Mon, 23 Mar 2015 18:48:19 -0700 Subject: [PATCH 0001/1120] added naming convention of UPPERCASE names --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 2c6c5c6c7d..1116dcb4ba 100644 --- a/README.md +++ b/README.md @@ -3139,6 +3139,33 @@ Other Style Guides ]; ``` + + - [23.10](#naming--uppercase) Use UPPERCASE for nested object namespacing, global variables, and constants. + + + ```javascript + // bad + const namespace = namespace || {}; + + namespace.util.Widget = { + // ...stuff... + } + + // bad + const apiKey = '44b345234534t455245njkl523452-vbb9'; + + // good + const NAMESPACE = NAMESPACE || {}; + + NAMESPACE.util.Widget = { + // ...stuff... + } + + // good + const API_KEY = '44b345234534t455245njkl523452-vbb9'; + ``` + + **[⬆ back to top](#table-of-contents)** ## Accessors From 1bb72ab9e27e5437373b15e643a4602d009bf7ed Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:09:39 -0800 Subject: [PATCH 0002/1120] [Deps] update `eslint` to v2, `eslint-plugin-react` to v4 --- packages/eslint-config-airbnb/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 6b5cad58b5..dd54ae754e 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,14 +43,14 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "1.2.0", - "eslint": "^1.10.3", - "eslint-plugin-react": "^3.16.1", + "eslint": "^2.2.0", + "eslint-plugin-react": "^4.0.0", "react": "^0.14.7", "tape": "^4.4.0", "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": "^1.0.0", - "eslint-plugin-react": "^3.16.1" + "eslint": "^2.2.0", + "eslint-plugin-react": "^4.0.0" } } From d49a1ed670bc1d26a78edc99b9a3b553db9bc13e Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:10:30 -0800 Subject: [PATCH 0003/1120] [eslint-v2] no-empty-label => no-labels --- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index a221d4d999..1359e58ba6 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -32,7 +32,7 @@ module.exports = { // disallow else after a return in an if 'no-else-return': 2, // disallow use of labels for anything other then loops and switches - 'no-empty-label': 2, + "no-labels": [2, {"allowLoop": false, "allowSwitch": false}], // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() From 1efb11ca93e6fd3d22c3a09825fcd4c7c3c896e8 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:11:22 -0800 Subject: [PATCH 0004/1120] [eslint-v2] space-after/before/return/throw/case => keyword-spacing --- packages/eslint-config-airbnb/rules/style.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 25c5326857..e97e0d25f8 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -100,10 +100,12 @@ module.exports = { 'semi': [2, 'always'], // sort variables within the same declaration block 'sort-vars': 0, - // require a space before certain keywords - 'space-before-keywords': [2, 'always'], - // require a space after certain keywords - 'space-after-keywords': [2, 'always'], + // require a space before & after certain keywords + "keyword-spacing": [2, {"before": true, "after": true, "overrides": { + 'return': {'after': true}, + 'throw': {'after': true}, + 'case': {'after': true} + }}], // require or disallow space before blocks 'space-before-blocks': 2, // require or disallow space before function opening parenthesis @@ -113,8 +115,6 @@ module.exports = { 'space-in-parens': [2, 'never'], // require spaces around operators 'space-infix-ops': 2, - // require a space after return, throw, and case - 'space-return-throw-case': 2, // Require or disallow spaces before/after unary operators 'space-unary-ops': 0, // require or disallow a space immediately following the // or /* in a comment From da4213c6dd6b842f72171fc669007185e03902d8 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:29:20 -0800 Subject: [PATCH 0005/1120] [eslint-v2] fix no-labels rule --- packages/eslint-config-airbnb/rules/best-practices.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 1359e58ba6..d87d70d82c 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -32,7 +32,7 @@ module.exports = { // disallow else after a return in an if 'no-else-return': 2, // disallow use of labels for anything other then loops and switches - "no-labels": [2, {"allowLoop": false, "allowSwitch": false}], + 'no-labels': [2, { 'allowLoop': true, 'allowSwitch': true }], // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() @@ -53,8 +53,6 @@ module.exports = { 'no-invalid-this': 0, // disallow usage of __iterator__ property 'no-iterator': 2, - // disallow use of labeled statements - 'no-labels': 2, // disallow unnecessary nested blocks 'no-lone-blocks': 2, // disallow creation of functions within loops From dff50992380894e9056fe03b5300f83c47b4c761 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:30:11 -0800 Subject: [PATCH 0006/1120] [eslint-v2] set es6 env to true --- packages/eslint-config-airbnb/rules/es6.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index f28a436ba3..508257a5bf 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -1,6 +1,6 @@ module.exports = { 'env': { - 'es6': false + 'es6': true }, 'ecmaFeatures': { 'arrowFunctions': true, From 4f32315b24e9545a4e5f8c226a989dbafc1c2099 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:36:08 -0800 Subject: [PATCH 0007/1120] [eslint-v2] ecmaFeatures => parserOptions --- packages/eslint-config-airbnb/rules/es6.js | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 508257a5bf..508885708b 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -2,24 +2,12 @@ module.exports = { 'env': { 'es6': true }, - 'ecmaFeatures': { - 'arrowFunctions': true, - 'blockBindings': true, - 'classes': true, - 'defaultParams': true, - 'destructuring': true, - 'forOf': true, - 'generators': false, - 'modules': true, - 'objectLiteralComputedProperties': true, - 'objectLiteralDuplicateProperties': false, - 'objectLiteralShorthandMethods': true, - 'objectLiteralShorthandProperties': true, - 'restParams': true, - 'spread': true, - 'superInFunctions': true, - 'templateStrings': true, - 'jsx': true + 'parserOptions': { + 'ecmaVersion': 6, + 'sourceType': 'module', + 'ecmaFeatures': { + 'jsx': true + } }, 'rules': { // enforces no braces where they can be omitted From 3aa8c584871474a5bacbc32158e8e76d1ccf94df Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:36:26 -0800 Subject: [PATCH 0008/1120] [eslint-v2] fix keyword-spacing style and sorting --- packages/eslint-config-airbnb/rules/style.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index e97e0d25f8..0e8036ec51 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -31,6 +31,16 @@ module.exports = { 'jsx-quotes': [2, 'prefer-double'], // enforces spacing between keys and values in object literal properties 'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }], + // require a space before & after certain keywords + 'keyword-spacing': [2, { + 'before': true, + 'after': true, + 'overrides': { + 'return': { 'after': true }, + 'throw': { 'after': true }, + 'case': { 'after': true } + } + }], // enforces empty lines around comments 'lines-around-comment': 0, // disallow mixed 'LF' and 'CRLF' as linebreaks @@ -100,12 +110,6 @@ module.exports = { 'semi': [2, 'always'], // sort variables within the same declaration block 'sort-vars': 0, - // require a space before & after certain keywords - "keyword-spacing": [2, {"before": true, "after": true, "overrides": { - 'return': {'after': true}, - 'throw': {'after': true}, - 'case': {'after': true} - }}], // require or disallow space before blocks 'space-before-blocks': 2, // require or disallow space before function opening parenthesis From d952efed242e9f4e25f3a4b45b7f62075a1a26e2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 13 Feb 2016 11:10:48 -0800 Subject: [PATCH 0009/1120] [Fix] `eslint` peerDep should not include breaking changes. --- packages/eslint-config-airbnb/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 437f1d1db0..467b916eec 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -46,6 +46,7 @@ "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": ">=1.0.0" + "eslint": "^1.0.0", + "eslint-plugin-react": "^3.16.1" } } From 8b58d8770cc1dcb3a2e4a7b7be94ea84d4dc3c4c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 13 Feb 2016 11:11:39 -0800 Subject: [PATCH 0010/1120] v5.0.1 --- packages/eslint-config-airbnb/CHANGELOG.md | 4 ++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 75febddbd9..7c47c680f5 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,7 @@ +5.0.1 / 2016-02-13 +================== + - [fix] `eslint` peerDep should not include breaking changes + 5.0.0 / 2016-02-03 ================== - [breaking] disallow unneeded ternary expressions diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 467b916eec..c8263acf29 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "5.0.0", + "version": "5.0.1", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From aa9add108e71dc69c9baa984894ce5914c973251 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:37:39 -0800 Subject: [PATCH 0011/1120] [pkg] add harry to contributors --- packages/eslint-config-airbnb/package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index c8263acf29..6b5cad58b5 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -30,6 +30,10 @@ "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" + }, + { + "name": "Harrison Shoff", + "url": "https://twitter.com/hshoff" } ], "license": "MIT", From 75807b9d5ead326be45f4719d81bda52d2bbb32a Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:42:15 -0800 Subject: [PATCH 0012/1120] [eslint-v2] no gens, no dup props in obj literal --- packages/eslint-config-airbnb/rules/es6.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 508885708b..08b5889172 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -6,7 +6,9 @@ module.exports = { 'ecmaVersion': 6, 'sourceType': 'module', 'ecmaFeatures': { - 'jsx': true + 'jsx': true, + 'generators': false, + 'objectLiteralDuplicateProperties': false } }, 'rules': { From 5109c849268020266b300229d7efd2de50f94c21 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 13 Feb 2016 13:41:52 -0800 Subject: [PATCH 0013/1120] [eslint-v2] fix no-labels rule --- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index d87d70d82c..00f7d2d988 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -32,7 +32,7 @@ module.exports = { // disallow else after a return in an if 'no-else-return': 2, // disallow use of labels for anything other then loops and switches - 'no-labels': [2, { 'allowLoop': true, 'allowSwitch': true }], + 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() From 1cbc628c49fe8e9540028f8a560b43ebdd08c82b Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 13 Feb 2016 13:57:38 -0800 Subject: [PATCH 0014/1120] [eslint-v2][constructors] disallow unnecessary constructors --- README.md | 24 ++++++++++++++++++++++ packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 32c966ce98..952b135a24 100644 --- a/README.md +++ b/README.md @@ -883,6 +883,30 @@ Other Style Guides } ``` + - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. + + ```javascript + // bad + class Jedi { + constructor() {} + + getName() { + return this.name; + } + } + + // good + class Rey extends Jedi { + constructor(...args) { + super(...args); + } + + getName() { + return this.name; + } + } + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 08b5889172..f55d6b9bac 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -34,6 +34,9 @@ module.exports = { 'no-this-before-super': 0, // require let or const instead of var 'no-var': 2, + // disallow unnecessary constructor + // http://eslint.org/docs/rules/no-useless-constructor + 'no-useless-constructor': 2, // require method and property shorthand syntax for object literals // https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md 'object-shorthand': [2, 'always'], From 91b83650b006764d1b235b79c265151c8b00ba19 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 02:34:47 -0800 Subject: [PATCH 0015/1120] [eslint-v2][constructors] fix bad + good examples --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 952b135a24..46e783580b 100644 --- a/README.md +++ b/README.md @@ -895,14 +895,17 @@ Other Style Guides } } - // good class Rey extends Jedi { constructor(...args) { super(...args); } + } - getName() { - return this.name; + // good + class Rey extends Jedi { + constructor(...args) { + super(...args); + this.name = 'Rey'; } } ``` From c05b2da9db51dc160b45c72faf317cb2f5604660 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 02:50:51 -0800 Subject: [PATCH 0016/1120] [eslint-v2] add new rules, disabled: - `id-blacklist` - `no-extra-label` - `no-implicit-globals` - `no-restricted-imports` - `no-unmodified-loop-condition` - `no-unused-labels` - `sort-imports` - `yield-star-spacing` --- .../eslint-config-airbnb/rules/best-practices.js | 16 ++++++++++++++-- packages/eslint-config-airbnb/rules/es6.js | 11 ++++++++++- packages/eslint-config-airbnb/rules/variables.js | 3 +++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 00f7d2d988..845904206e 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -20,6 +20,9 @@ module.exports = { 'eqeqeq': 2, // make sure for-in loops have an if statement 'guard-for-in': 2, + // Blacklist certain identifiers to prevent them being used + // http://eslint.org/docs/rules/id-blacklist + 'id-blacklist': 0, // disallow the use of alert, confirm, and prompt 'no-alert': 1, // disallow use of arguments.caller or arguments.callee @@ -31,8 +34,9 @@ module.exports = { 'no-div-regex': 0, // disallow else after a return in an if 'no-else-return': 2, - // disallow use of labels for anything other then loops and switches - 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], + // disallow Unnecessary Labels + // http://eslint.org/docs/rules/no-extra-label + 'no-extra-label': 0, // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() @@ -53,6 +57,8 @@ module.exports = { 'no-invalid-this': 0, // disallow usage of __iterator__ property 'no-iterator': 2, + // disallow use of labels for anything other then loops and switches + 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], // disallow unnecessary nested blocks 'no-lone-blocks': 2, // disallow creation of functions within loops @@ -94,8 +100,14 @@ module.exports = { 'no-sequences': 2, // restrict what can be thrown as an exception 'no-throw-literal': 2, + // disallow unmodified conditions of loops + // http://eslint.org/docs/rules/no-unmodified-loop-condition + 'no-unmodified-loop-condition': 0, // disallow usage of expressions in statement position 'no-unused-expressions': 2, + // disallow unused labels + // http://eslint.org/docs/rules/no-unused-labels + 'no-unused-labels': 0, // disallow unnecessary .call() and .apply() 'no-useless-call': 0, // disallow use of void operator diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index f55d6b9bac..11e212b5eb 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,6 +30,9 @@ module.exports = { 'no-class-assign': 0, // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow specific imports + // http://eslint.org/docs/rules/no-restricted-imports + 'no-restricted-imports': 0, // disallow to use this/super before super() calling in constructors. 'no-this-before-super': 0, // require let or const instead of var @@ -52,6 +55,12 @@ module.exports = { // http://eslint.org/docs/rules/prefer-template 'prefer-template': 2, // disallow generator functions that do not have yield - 'require-yield': 0 + 'require-yield': 0, + // import sorting + // http://eslint.org/docs/rules/sort-imports + 'sort-imports': 0, + // enforce spacing around the * in yield* expressions + // http://eslint.org/docs/rules/yield-star-spacing + 'yield-star-spacing': 0 } }; diff --git a/packages/eslint-config-airbnb/rules/variables.js b/packages/eslint-config-airbnb/rules/variables.js index 59914313f9..b9073f72c5 100644 --- a/packages/eslint-config-airbnb/rules/variables.js +++ b/packages/eslint-config-airbnb/rules/variables.js @@ -6,6 +6,9 @@ module.exports = { 'no-catch-shadow': 0, // disallow deletion of variables 'no-delete-var': 2, + // disallow var and named functions in global scope + // http://eslint.org/docs/rules/no-implicit-globals + 'no-implicit-globals': 0, // disallow labels that share a name with a variable 'no-label-var': 0, // disallow shadowing of names such as arguments From a126d0b85c8b2afcdd309c39f45c14815bb1ab23 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 12:56:03 -0800 Subject: [PATCH 0017/1120] [eslint-v2] enforce yield-start-spacing, no-unused-labels, no-extra-label --- packages/eslint-config-airbnb/rules/best-practices.js | 4 ++-- packages/eslint-config-airbnb/rules/es6.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 845904206e..5a50af000a 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -36,7 +36,7 @@ module.exports = { 'no-else-return': 2, // disallow Unnecessary Labels // http://eslint.org/docs/rules/no-extra-label - 'no-extra-label': 0, + 'no-extra-label': 2, // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() @@ -107,7 +107,7 @@ module.exports = { 'no-unused-expressions': 2, // disallow unused labels // http://eslint.org/docs/rules/no-unused-labels - 'no-unused-labels': 0, + 'no-unused-labels': 2, // disallow unnecessary .call() and .apply() 'no-useless-call': 0, // disallow use of void operator diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 11e212b5eb..8ba6e5e3c9 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -61,6 +61,6 @@ module.exports = { 'sort-imports': 0, // enforce spacing around the * in yield* expressions // http://eslint.org/docs/rules/yield-star-spacing - 'yield-star-spacing': 0 + 'yield-star-spacing': [2, 'after'] } }; From fbd9c35dd37c2466b809a89c79703583de77d275 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 11:14:38 -0800 Subject: [PATCH 0018/1120] [eslint-v2][arrays] add array-callback-return rule --- README.md | 45 +++++++++++++++++++ .../rules/best-practices.js | 3 ++ 2 files changed, 48 insertions(+) diff --git a/README.md b/README.md index 46e783580b..b52dbdcc23 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,51 @@ Other Style Guides const nodes = Array.from(foo); ``` + - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [array-callback-return](http://eslint.org/docs/rules/array-callback-return) + + ```javascript + // good + [1, 2, 3].map((x) => { + const y = x + 1; + return x * y; + }); + + // good + [1, 2, 3].map(x => x + 1); + + // bad + const flat = {}; + [[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => { + const flatten = memo.concat(item); + flat[index] = memo.concat(item); + }); + + // good + const flat = {}; + [[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => { + const flatten = memo.concat(item); + flat[index] = flatten; + return flatten; + }); + + // bad + [1, 2, 3].filter((x) => { + if (x > 2) { + return true; + } else { + return false; + } + }); + + // good + [1, 2, 3].filter((x) => { + if (x > 2) { + return true; + } + return false; + }); + ``` + **[⬆ back to top](#table-of-contents)** ## Destructuring diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 5a50af000a..6f66792478 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -2,6 +2,9 @@ module.exports = { 'rules': { // enforces getter/setter pairs in objects 'accessor-pairs': 0, + // enforces return statements in callbacks of array's methods + // http://eslint.org/docs/rules/array-callback-return + 'array-callback-return': 2, // treat var statements as if they were block scoped 'block-scoped-var': 2, // specify the maximum cyclomatic complexity allowed in a program From 172dffbb52ae6b61fe41c9a4c14d4be68070111f Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 11:48:04 -0800 Subject: [PATCH 0019/1120] [eslint-v2][whitespace] add newline-per-chained-call rule --- README.md | 8 ++++++-- packages/eslint-config-airbnb/rules/style.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b52dbdcc23..7290e0aca3 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,7 @@ Other Style Guides if (x > 2) { return true; } + return false; }); ``` @@ -1664,8 +1665,8 @@ Other Style Guides })(this);↵ ``` - - [18.6](#18.6) Use indentation when making long method chains. Use a leading dot, which - emphasizes that the line is a method call, not a new statement. + - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which + emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) ```javascript // bad @@ -1702,6 +1703,9 @@ Other Style Guides .append('svg:g') .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')') .call(tron.led); + + // good + const leds = stage.selectAll('.led').data(data); ``` - [18.7](#18.7) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 0e8036ec51..4e8710c347 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -59,6 +59,9 @@ module.exports = { 'new-parens': 0, // allow/disallow an empty newline after var statement 'newline-after-var': 0, + // enforces new line after each method call in the chain to make it more readable and easy to maintain + // http://eslint.org/docs/rules/newline-per-chained-call + 'newline-per-chained-call': [2, { "ignoreChainWithDepth": 3 }], // disallow use of the Array constructor 'no-array-constructor': 0, // disallow use of the continue statement From 6a03a32915533eb09151c754333ccf0f724d05ad Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 14:47:23 -0800 Subject: [PATCH 0020/1120] [eslint-v2][arrow functions] add no-confusing-arrow rule --- README.md | 13 +++++++++++++ packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 7290e0aca3..e5ed8a3754 100644 --- a/README.md +++ b/README.md @@ -817,6 +817,19 @@ Other Style Guides }); ``` + - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [no-confusing-arrow](http://eslint.org/docs/rules/no-confusing-arrow) + + ```js + // bad + const isActive = item => item.height > 256 ? true : false; + + // bad + const isActive = (item) => item.height > 256 ? true : false; + + // good + const isActive = item => { return item.height > 256 ? true : false; } + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 8ba6e5e3c9..88fbf2eb89 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -28,6 +28,9 @@ module.exports = { 'generator-star-spacing': 0, // disallow modifying variables of class declarations 'no-class-assign': 0, + // disallow arrow functions where they could be confused with comparisons + // http://eslint.org/docs/rules/no-confusing-arrow + 'no-confusing-arrow': 2, // disallow modifying variables that are declared using const 'no-const-assign': 2, // disallow specific imports From ba10353e9b34f44afbd8b4a2ecdff923356a2ae7 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 14:50:49 -0800 Subject: [PATCH 0021/1120] [eslint-v2][arrow functions] improve examples --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e5ed8a3754..e2b48378ae 100644 --- a/README.md +++ b/README.md @@ -821,13 +821,13 @@ Other Style Guides ```js // bad - const isActive = item => item.height > 256 ? true : false; + const itemHeight = item => item.height > 256 ? item.largeSize : item.smallSize; // bad - const isActive = (item) => item.height > 256 ? true : false; + const itemHeight = (item) => item.height > 256 ? item.largeSize : item.smallSize; // good - const isActive = item => { return item.height > 256 ? true : false; } + const itemHeight = item => { return item.height > 256 ? item.largeSize : item.smallSize; } ``` **[⬆ back to top](#table-of-contents)** From 3762c9add826e47587242460db331d8203cea069 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 14:58:28 -0800 Subject: [PATCH 0022/1120] [eslint-v2] add no-new-symbol rule --- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 88fbf2eb89..be2ebe5c7c 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -33,6 +33,9 @@ module.exports = { 'no-confusing-arrow': 2, // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow symbol constructor + // http://eslint.org/docs/rules/no-new-symbol + 'no-new-symbol': 2, // disallow specific imports // http://eslint.org/docs/rules/no-restricted-imports 'no-restricted-imports': 0, From 92df6357b3ed3326eaca33454b112d06dbd76f0e Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:30:28 -0800 Subject: [PATCH 0023/1120] [eslint-v2][variables] add no-self-assign --- packages/eslint-config-airbnb/rules/variables.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/variables.js b/packages/eslint-config-airbnb/rules/variables.js index b9073f72c5..3bfcc83fde 100644 --- a/packages/eslint-config-airbnb/rules/variables.js +++ b/packages/eslint-config-airbnb/rules/variables.js @@ -11,6 +11,9 @@ module.exports = { 'no-implicit-globals': 0, // disallow labels that share a name with a variable 'no-label-var': 0, + // disallow self assignment + // http://eslint.org/docs/rules/no-self-assign + 'no-self-assign': 2, // disallow shadowing of names such as arguments 'no-shadow-restricted-names': 2, // disallow declaration of variables already declared in the outer scope From e6cbcf4cc56b04edbb22eef2856fce78bf4625b1 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:35:23 -0800 Subject: [PATCH 0024/1120] [eslint-v2][whitespace] add no-whitespace-before-property rule --- README.md | 2 +- packages/eslint-config-airbnb/rules/style.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2b48378ae..99f9b3dff7 100644 --- a/README.md +++ b/README.md @@ -1679,7 +1679,7 @@ Other Style Guides ``` - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which - emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) + emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) [no-whitespace-before-property](http://eslint.org/docs/rules/no-whitespace-before-property) ```javascript // bad diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 4e8710c347..85c1fd706d 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -90,6 +90,9 @@ module.exports = { // also, prefer `a || b` over `a ? a : b` // http://eslint.org/docs/rules/no-unneeded-ternary 'no-unneeded-ternary': [2, { 'defaultAssignment': false }], + // disallow whitespace before properties + // http://eslint.org/docs/rules/no-whitespace-before-property + 'no-whitespace-before-property': 2, // require padding inside curly braces 'object-curly-spacing': [2, 'always'], // allow just one var statement per function From c5b4f05879be4cd48c1737ad9bfdb00ed8a87ee0 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:39:32 -0800 Subject: [PATCH 0025/1120] [eslint-v2] add one-var-declaration-per-line --- packages/eslint-config-airbnb/rules/style.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 85c1fd706d..a5d9e094de 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -97,6 +97,9 @@ module.exports = { 'object-curly-spacing': [2, 'always'], // allow just one var statement per function 'one-var': [2, 'never'], + // require a newline around variable declaration + // http://eslint.org/docs/rules/one-var-declaration-per-line + 'one-var-declaration-per-line': [2, 'always'], // require assignment operator shorthand where possible or prohibit it entirely 'operator-assignment': 0, // enforce operators to be placed before or after line breaks From e1a087fbb1eeb861acce7bab67476ccd4dd080e0 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:45:44 -0800 Subject: [PATCH 0026/1120] [eslint-v2] add prefer-rest-params --- README.md | 2 +- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99f9b3dff7..795608e126 100644 --- a/README.md +++ b/README.md @@ -581,7 +581,7 @@ Other Style Guides ``` - - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. + - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [prefer-rest-params](http://eslint.org/docs/rules/prefer-rest-params) > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`. diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index be2ebe5c7c..ae835a6ab9 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -57,6 +57,9 @@ module.exports = { 'prefer-spread': 0, // suggest using Reflect methods where applicable 'prefer-reflect': 0, + // use rest parameters instead of arguments + // http://eslint.org/docs/rules/prefer-rest-params + 'prefer-rest-params': 2, // suggest using template literals instead of string concatenation // http://eslint.org/docs/rules/prefer-template 'prefer-template': 2, From 1f12a12be474bc9f61b2b1556549e865f3be114c Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:48:31 -0800 Subject: [PATCH 0027/1120] [eslint-v2] fix empty constructor example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 795608e126..909954c934 100644 --- a/README.md +++ b/README.md @@ -956,14 +956,14 @@ Other Style Guides class Rey extends Jedi { constructor(...args) { - super(...args); + super(args); } } // good class Rey extends Jedi { constructor(...args) { - super(...args); + super(args); this.name = 'Rey'; } } From 65609373bfe33e5d86b2ac04ff2fd7f0aaa6a8a2 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:56:49 -0800 Subject: [PATCH 0028/1120] [eslint-v2][template strings] add template-curly-spacing rule, fix #716 --- README.md | 7 ++++++- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 909954c934..d9bab06129 100644 --- a/README.md +++ b/README.md @@ -493,7 +493,7 @@ Other Style Guides ``` - - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) + - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. @@ -508,6 +508,11 @@ Other Style Guides return ['How are you, ', name, '?'].join(); } + // bad + function sayHi(name) { + return `How are you, ${ name }?`; + } + // good function sayHi(name) { return `How are you, ${name}?`; diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index ae835a6ab9..e88b2d5059 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -68,6 +68,9 @@ module.exports = { // import sorting // http://eslint.org/docs/rules/sort-imports 'sort-imports': 0, + // enforce usage of spacing in template strings + // http://eslint.org/docs/rules/template-curly-spacing + 'template-curly-spacing': 2, // enforce spacing around the * in yield* expressions // http://eslint.org/docs/rules/yield-star-spacing 'yield-star-spacing': [2, 'after'] From e0959d0f1d35105a9db8d972e0f844daf0dfa072 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 19:04:12 -0800 Subject: [PATCH 0029/1120] [eslint-v2] fix rule links in readme --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d9bab06129..e423c59499 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ Other Style Guides const nodes = Array.from(foo); ``` - - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [array-callback-return](http://eslint.org/docs/rules/array-callback-return) + - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return) ```javascript // good @@ -586,7 +586,7 @@ Other Style Guides ``` - - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [prefer-rest-params](http://eslint.org/docs/rules/prefer-rest-params) + - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`. @@ -822,7 +822,7 @@ Other Style Guides }); ``` - - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [no-confusing-arrow](http://eslint.org/docs/rules/no-confusing-arrow) + - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](http://eslint.org/docs/rules/no-confusing-arrow) ```js // bad @@ -947,7 +947,7 @@ Other Style Guides } ``` - - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. + - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) ```javascript // bad @@ -959,6 +959,7 @@ Other Style Guides } } + // bad class Rey extends Jedi { constructor(...args) { super(args); @@ -1684,7 +1685,7 @@ Other Style Guides ``` - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which - emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) [no-whitespace-before-property](http://eslint.org/docs/rules/no-whitespace-before-property) + emphasizes that the line is a method call, not a new statement. eslint: [`newline-per-chained-call`](http://eslint.org/docs/rules/newline-per-chained-call) [`no-whitespace-before-property`](http://eslint.org/docs/rules/no-whitespace-before-property) ```javascript // bad From ff0adbe2918dbc5b26814f61853227318d787965 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 12:59:00 -0800 Subject: [PATCH 0030/1120] [eslint-v2][react] acceptTranspilerName => ignoreTranspilerName --- packages/eslint-config-airbnb/rules/react.js | 5 ++++- packages/eslint-config-airbnb/rules/style.js | 5 +++-- packages/eslint-config-airbnb/test/test-react-order.js | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index e1e1c25993..2b59ca200e 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -10,7 +10,7 @@ module.exports = { 'rules': { // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - 'react/display-name': [0, { 'acceptTranspilerName': false }], + 'react/display-name': [0, { 'ignoreTranspilerName': true }], // Forbid certain propTypes (any, array, object) // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md 'react/forbid-prop-types': [0, { 'forbid': ['any', 'array', 'object'] }], @@ -116,6 +116,9 @@ module.exports = { // Prevent extra closing tags for components without children // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md 'react/self-closing-comp': 2, + // Enforce spaces before the closing bracket of self-closing JSX elements + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md + 'react/jsx-space-before-closing': [2, 'always'], // Enforce component methods order // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md 'react/sort-comp': [2, { diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index a5d9e094de..c147aae8b7 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -59,9 +59,10 @@ module.exports = { 'new-parens': 0, // allow/disallow an empty newline after var statement 'newline-after-var': 0, - // enforces new line after each method call in the chain to make it more readable and easy to maintain + // enforces new line after each method call in the chain to make it + // more readable and easy to maintain // http://eslint.org/docs/rules/newline-per-chained-call - 'newline-per-chained-call': [2, { "ignoreChainWithDepth": 3 }], + 'newline-per-chained-call': [2, { 'ignoreChainWithDepth': 3 }], // disallow use of the Array constructor 'no-array-constructor': 0, // disallow use of the continue statement diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index 77448cf86a..f5b2d452fe 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -14,7 +14,8 @@ const cli = new CLIEngine({ function lint(text) { // @see http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles // @see http://eslint.org/docs/developer-guide/nodejs-api.html#executeontext - return cli.executeOnText(text).results[0]; + const linter = cli.executeOnText(text); + return linter.results[0]; } function wrapComponent(body) { From 133fc51e21321c3eba0cda5f6fa008ff55940d8c Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:02:15 -0800 Subject: [PATCH 0031/1120] [eslint-v2][react] add static-methods to top of sort-comp order --- packages/eslint-config-airbnb/rules/react.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 2b59ca200e..a9facdd732 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -123,6 +123,7 @@ module.exports = { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md 'react/sort-comp': [2, { 'order': [ + 'static-methods', 'lifecycle', '/^on.+$/', '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', From 07948531dccc62d21f190ed4a2edc035642da01a Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:05:49 -0800 Subject: [PATCH 0032/1120] [eslint-v2][react] set ignoreTranspilerName to false --- packages/eslint-config-airbnb/rules/react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index a9facdd732..99e4c02010 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -10,7 +10,7 @@ module.exports = { 'rules': { // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - 'react/display-name': [0, { 'ignoreTranspilerName': true }], + 'react/display-name': [0, { 'ignoreTranspilerName': false }], // Forbid certain propTypes (any, array, object) // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md 'react/forbid-prop-types': [0, { 'forbid': ['any', 'array', 'object'] }], From 822c0dfdfe16ead8d4e3da8c35c007901e94f4eb Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:10:42 -0800 Subject: [PATCH 0033/1120] [eslint-v2][react] jsx-sort-prop-types => sort-prop-types --- packages/eslint-config-airbnb/rules/react.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 99e4c02010..b7a9889e69 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -54,8 +54,8 @@ module.exports = { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md 'react/jsx-pascal-case': 0, // Enforce propTypes declarations alphabetical sorting - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md - 'react/jsx-sort-prop-types': [0, { + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md + 'react/sort-prop-types': [0, { 'ignoreCase': false, 'callbacksLast': false, }], From b79e9512801f798698f15baaaec92c328c0af6c0 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 23:33:39 -0800 Subject: [PATCH 0034/1120] [eslint-v2][arrays] update array-callback-return good/bad ex --- README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e423c59499..e89fc1cd6a 100644 --- a/README.md +++ b/README.md @@ -374,9 +374,10 @@ Other Style Guides }); // bad - [1, 2, 3].filter((x) => { - if (x > 2) { - return true; + inbox].filter((msg) => { + const { subject, author } = msg; + if (subject === 'Mockingbird') { + return author === 'Harper Lee'; } else { return false; } @@ -384,12 +385,14 @@ Other Style Guides // good [1, 2, 3].filter((x) => { - if (x > 2) { - return true; - } + inbox].filter((msg) => { + const { subject, author } = msg; + if (subject === 'Mockingbird') { + return author === 'Harper Lee'; + } - return false; - }); + return false; + }); ``` **[⬆ back to top](#table-of-contents)** From 3983d380edd22fe7546f9fef2d04fc69a5db04f7 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 23:39:29 -0800 Subject: [PATCH 0035/1120] [eslint-v2][arrays] fix example --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e89fc1cd6a..e10cca35ea 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ Other Style Guides }); // bad - inbox].filter((msg) => { + inbox.filter((msg) => { const { subject, author } = msg; if (subject === 'Mockingbird') { return author === 'Harper Lee'; @@ -384,15 +384,14 @@ Other Style Guides }); // good - [1, 2, 3].filter((x) => { - inbox].filter((msg) => { - const { subject, author } = msg; - if (subject === 'Mockingbird') { - return author === 'Harper Lee'; - } + inbox.filter((msg) => { + const { subject, author } = msg; + if (subject === 'Mockingbird') { + return author === 'Harper Lee'; + } - return false; - }); + return false; + }); ``` **[⬆ back to top](#table-of-contents)** From 0f32b96c125784e0db507682d3fb2fe05098e903 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:24:55 -0800 Subject: [PATCH 0036/1120] [changelog] update changelog for 6.0.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 7c47c680f5..fcb16ec26c 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,21 @@ +6.0.0 / 2016-02-21 +================== +- [breaking] enable `array-callback-return` +- [breaking] enable `no-confusing-arrow` +- [breaking] enable `no-new-symbol` +- [breaking] enable `no-restricted-imports` +- [breaking] enable `no-useless-constructor` +- [breaking] enable `prefer-rest-params` +- [breaking] enable `template-curly-spaces` +- [breaking] enable `newline-per-chained-call` +- [breaking] enable `one-var-declaration-per-line` +- [breaking] enable `no-self-assign` +- [breaking] enable `no-whitespace-before-property` +- [breaking] [react] enable `react/jsx-space-before-closing` +- [breaking] [react] enable `static-methods` at top of `react/sort-comp` +- [breaking] [react] don't `ignoreTranspilerName` for `react/display-name` +- [peer+dev deps] update `eslint`, `eslint-plugin-react` + 5.0.1 / 2016-02-13 ================== - [fix] `eslint` peerDep should not include breaking changes From 4574659833a8d1c6c45833bb06743ababa6929e8 Mon Sep 17 00:00:00 2001 From: Sergey Fursov Date: Sun, 21 Feb 2016 01:31:20 +0300 Subject: [PATCH 0037/1120] rearrange comma-dangle rule to match es5/es6 codestyles, fixes #741 --- packages/eslint-config-airbnb/rules/errors.js | 2 -- packages/eslint-config-airbnb/rules/es6.js | 2 ++ packages/eslint-config-airbnb/rules/legacy.js | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/errors.js b/packages/eslint-config-airbnb/rules/errors.js index ec1b1aab0e..1c1addf5fa 100644 --- a/packages/eslint-config-airbnb/rules/errors.js +++ b/packages/eslint-config-airbnb/rules/errors.js @@ -1,7 +1,5 @@ module.exports = { 'rules': { - // disallow trailing commas in object literals - 'comma-dangle': [2, 'always-multiline'], // disallow assignment in conditional expressions 'no-cond-assign': [2, 'always'], // disallow use of console diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index e34684346d..f28a436ba3 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,6 +30,8 @@ module.exports = { // require space before/after arrow function's arrow // https://github.com/eslint/eslint/blob/master/docs/rules/arrow-spacing.md 'arrow-spacing': [2, { 'before': true, 'after': true }], + // require trailing commas in multiline object literals + 'comma-dangle': [2, 'always-multiline'], // verify super() callings in constructors 'constructor-super': 0, // enforce the spacing around the * in generator functions diff --git a/packages/eslint-config-airbnb/rules/legacy.js b/packages/eslint-config-airbnb/rules/legacy.js index e94c774f26..dc34856f5e 100644 --- a/packages/eslint-config-airbnb/rules/legacy.js +++ b/packages/eslint-config-airbnb/rules/legacy.js @@ -1,5 +1,7 @@ module.exports = { 'rules': { + // disallow trailing commas in object literals + 'comma-dangle': [2, 'never'], // specify the maximum depth that blocks can be nested 'max-depth': [0, 4], // limits the number of parameters that can be used in the function declaration. From b648de3233c157c81b9d6301d061e16136ca1d29 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 00:51:00 -0800 Subject: [PATCH 0038/1120] [eslint config] v6.0.0 --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index dd54ae754e..d014d2c079 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "5.0.1", + "version": "6.0.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 8a6f00968db332594d1181ffa05894c2fb3fc906 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 10:28:54 -0800 Subject: [PATCH 0039/1120] Fix no-useless-constructor example. Per https://github.com/airbnb/javascript/pull/730#discussion_r53565774 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e10cca35ea..37bb6433a0 100644 --- a/README.md +++ b/README.md @@ -964,14 +964,14 @@ Other Style Guides // bad class Rey extends Jedi { constructor(...args) { - super(args); + super(...args); } } // good class Rey extends Jedi { constructor(...args) { - super(args); + super(...args); this.name = 'Rey'; } } From 12fb48611ad2c035ba0aa30ccb5a708263867261 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 10:57:42 -0800 Subject: [PATCH 0040/1120] =?UTF-8?q?Disable=20`newline-per-chained-call`?= =?UTF-8?q?=20until=20`eslint`=E2=80=99s=20bug=20is=20resolved.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug: https://github.com/eslint/eslint/issues/5289 Closes #748. --- packages/eslint-config-airbnb/rules/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index c147aae8b7..b9b0e23f5c 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -62,7 +62,7 @@ module.exports = { // enforces new line after each method call in the chain to make it // more readable and easy to maintain // http://eslint.org/docs/rules/newline-per-chained-call - 'newline-per-chained-call': [2, { 'ignoreChainWithDepth': 3 }], + 'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 3 }], // disallow use of the Array constructor 'no-array-constructor': 0, // disallow use of the continue statement From f4e94ade2ba9f42edea07977f4b0bfcb90c448d5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 10:59:44 -0800 Subject: [PATCH 0041/1120] v6.0.1 --- packages/eslint-config-airbnb/CHANGELOG.md | 6 +++++- packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index fcb16ec26c..7c29ba922e 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,7 @@ +6.0.1 / 2016-02-21 +================== +- [fix] disable `newline-per-chained-call` due to an `eslint` bug (#748) + 6.0.0 / 2016-02-21 ================== - [breaking] enable `array-callback-return` @@ -14,7 +18,7 @@ - [breaking] [react] enable `react/jsx-space-before-closing` - [breaking] [react] enable `static-methods` at top of `react/sort-comp` - [breaking] [react] don't `ignoreTranspilerName` for `react/display-name` -- [peer+dev deps] update `eslint`, `eslint-plugin-react` +- [peer+dev deps] update `eslint`, `eslint-plugin-react` (#730) (#730) (#730) (#730) 5.0.1 / 2016-02-13 ================== diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index d014d2c079..618d928332 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.0.0", + "version": "6.0.1", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 50ff33de88f6f1363a27e61d59f2c950cf0bd9f8 Mon Sep 17 00:00:00 2001 From: Cihan Bebek Date: Sun, 21 Feb 2016 21:38:33 +0200 Subject: [PATCH 0042/1120] Small typo fix in 18.6 'bad'-example. Function call 'class()' to 'classed()'. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37bb6433a0..2bdac55fab 100644 --- a/README.md +++ b/README.md @@ -1710,7 +1710,7 @@ Other Style Guides .updateCount(); // bad - const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true) + const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').classed('led', true) .attr('width', (radius + margin) * 2).append('svg:g') .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')') .call(tron.led); From f12b2a195aa53447cc2d902628af7e76d35ec447 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Feb 2016 10:46:03 -0800 Subject: [PATCH 0043/1120] [Dev Deps] update `babel-tape-runner`. Closes https://github.com/wavded/babel-tape-runner/issues/11 --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 618d928332..bfd7d24f76 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -42,7 +42,7 @@ }, "homepage": "https://github.com/airbnb/javascript", "devDependencies": { - "babel-tape-runner": "1.2.0", + "babel-tape-runner": "^1.3.1", "eslint": "^2.2.0", "eslint-plugin-react": "^4.0.0", "react": "^0.14.7", From 33f1ddb4c534e0db605cca3d4060113b32c248ce Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Feb 2016 14:30:23 -0800 Subject: [PATCH 0044/1120] =?UTF-8?q?Disable=20`no-confusing-arrow`=20unti?= =?UTF-8?q?l=20eslint=E2=80=99s=20bug=20is=20resolved.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug: https://github.com/eslint/eslint/issues/5332 Closes #752. --- packages/eslint-config-airbnb/rules/es6.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index e88b2d5059..ef50e0a7f5 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,7 +30,7 @@ module.exports = { 'no-class-assign': 0, // disallow arrow functions where they could be confused with comparisons // http://eslint.org/docs/rules/no-confusing-arrow - 'no-confusing-arrow': 2, + 'no-confusing-arrow': 0, // disallow modifying variables that are declared using const 'no-const-assign': 2, // disallow symbol constructor From 6c637b97d919f9434ea00fedaa367794e0cad49e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Feb 2016 14:49:34 -0800 Subject: [PATCH 0045/1120] [eslint config] v6.0.2 --- packages/eslint-config-airbnb/CHANGELOG.md | 4 ++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 7c29ba922e..c7cd9c97a9 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,7 @@ +6.0.2 / 2016-02-22 +================== +- [fix] disable `no-confusing-arrow` due to an `eslint` bug (#752) + 6.0.1 / 2016-02-21 ================== - [fix] disable `newline-per-chained-call` due to an `eslint` bug (#748) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index bfd7d24f76..9478f804fd 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.0.1", + "version": "6.0.2", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From db8b07f51ad54682bd0225a42d9d5325044ab8f2 Mon Sep 17 00:00:00 2001 From: NakShi Date: Mon, 22 Feb 2016 15:39:53 -0800 Subject: [PATCH 0046/1120] Fixed README typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2bdac55fab..f1dadba1dc 100644 --- a/README.md +++ b/README.md @@ -1384,7 +1384,7 @@ Other Style Guides } ``` - - [15.5](#15.5) Ternaries should not be nested and generally be single line expressions. + - [15.6](#15.6) Ternaries should not be nested and generally be single line expressions. eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html). @@ -1407,7 +1407,7 @@ Other Style Guides const foo = maybe1 > maybe2 ? 'bar' : maybeNull; ``` - - [15.6](#15.6) Avoid unneeded ternary statements. + - [15.7](#15.7) Avoid unneeded ternary statements. eslint rules: [`no-unneeded-ternary`](http://eslint.org/docs/rules/no-unneeded-ternary.html). From 714f71d1d2f9788742e0949dabb0cee4677e8929 Mon Sep 17 00:00:00 2001 From: Felix Sanz Date: Tue, 23 Feb 2016 01:25:02 +0100 Subject: [PATCH 0047/1120] Added getter/setter info I tried to search for getter/setter in the readme but nothing was found. Added some info to make a clear statement about them --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1dadba1dc..06a4eb6b43 100644 --- a/README.md +++ b/README.md @@ -1033,7 +1033,7 @@ Other Style Guides - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) - > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects. + > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. ```javascript const numbers = [1, 2, 3, 4, 5]; @@ -2217,7 +2217,7 @@ Other Style Guides ## Accessors - [23.1](#23.1) Accessor functions for properties are not required. - - [23.2](#23.2) If you do make accessor functions use getVal() and setVal('hello'). + - [23.2](#23.2) Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello'). ```javascript // bad From cba519a4424286bc3a2a9374b64d35e706be5632 Mon Sep 17 00:00:00 2001 From: Max Beier Date: Tue, 23 Feb 2016 15:07:17 +0100 Subject: [PATCH 0048/1120] Updated CHANGELOG.md --- packages/eslint-config-airbnb/CHANGELOG.md | 170 +++++++++++++-------- 1 file changed, 105 insertions(+), 65 deletions(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index c7cd9c97a9..109d7becd2 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,132 +1,172 @@ 6.0.2 / 2016-02-22 ================== -- [fix] disable `no-confusing-arrow` due to an `eslint` bug (#752) +- [fix] disable [`no-confusing-arrow`][no-confusing-arrow] due to an `eslint` bug ([#752](https://github.com/airbnb/javascript/issues/752)) 6.0.1 / 2016-02-21 ================== -- [fix] disable `newline-per-chained-call` due to an `eslint` bug (#748) +- [fix] disable [`newline-per-chained-call`][newline-per-chained-call] due to an `eslint` bug ([#748](https://github.com/airbnb/javascript/issues/748)) 6.0.0 / 2016-02-21 ================== -- [breaking] enable `array-callback-return` -- [breaking] enable `no-confusing-arrow` -- [breaking] enable `no-new-symbol` -- [breaking] enable `no-restricted-imports` -- [breaking] enable `no-useless-constructor` -- [breaking] enable `prefer-rest-params` -- [breaking] enable `template-curly-spaces` -- [breaking] enable `newline-per-chained-call` -- [breaking] enable `one-var-declaration-per-line` -- [breaking] enable `no-self-assign` -- [breaking] enable `no-whitespace-before-property` -- [breaking] [react] enable `react/jsx-space-before-closing` -- [breaking] [react] enable `static-methods` at top of `react/sort-comp` -- [breaking] [react] don't `ignoreTranspilerName` for `react/display-name` -- [peer+dev deps] update `eslint`, `eslint-plugin-react` (#730) (#730) (#730) (#730) +- [breaking] enable [`array-callback-return`][array-callback-return] +- [breaking] enable [`no-confusing-arrow`][no-confusing-arrow] +- [breaking] enable [`no-new-symbol`][no-new-symbol] +- [breaking] enable [`no-restricted-imports`][no-restricted-imports] +- [breaking] enable [`no-useless-constructor`][no-useless-constructor] +- [breaking] enable [`prefer-rest-params`][prefer-rest-params] +- [breaking] enable [`template-curly-spacing`][template-curly-spacing] +- [breaking] enable [`newline-per-chained-call`][newline-per-chained-call] +- [breaking] enable [`one-var-declaration-per-line`][one-var-declaration-per-line] +- [breaking] enable [`no-self-assign`][no-self-assign] +- [breaking] enable [`no-whitespace-before-property`][no-whitespace-before-property] +- [breaking] [react] enable [`react/jsx-space-before-closing`][react/jsx-space-before-closing] +- [breaking] [react] enable `static-methods` at top of [`react/sort-comp`][react/sort-comp] +- [breaking] [react] don't `ignoreTranspilerName` for [`react/display-name`][react/display-name] +- [peer+dev deps] update `eslint`, `eslint-plugin-react` ([#730](https://github.com/airbnb/javascript/issues/730)) 5.0.1 / 2016-02-13 ================== - - [fix] `eslint` peerDep should not include breaking changes +- [fix] `eslint` peerDep should not include breaking changes 5.0.0 / 2016-02-03 ================== - - [breaking] disallow unneeded ternary expressions - - [breaking] Avoid lexical declarations in case/default clauses - - [dev deps] update `babel-tape-runner`, `eslint-plugin-react`, `react`, `tape` +- [breaking] disallow unneeded ternary expressions +- [breaking] Avoid lexical declarations in case/default clauses +- [dev deps] update `babel-tape-runner`, `eslint-plugin-react`, `react`, `tape` 4.0.0 / 2016-01-22 ================== - - [breaking] require outer IIFE wrapping; flesh out guide section - - [minor] Add missing `arrow-body-style`, `prefer-template` rules (#678) - - [minor] Add `prefer-arrow-callback` to ES6 rules (to match the guide) (#677) - - [Tests] run `npm run lint` as part of tests; fix errors - - [Tests] use `parallelshell` to parallelize npm run-scripts +- [breaking] require outer IIFE wrapping; flesh out guide section +- [minor] Add missing [`arrow-body-style`][arrow-body-style], [`prefer-template`][prefer-template] rules ([#678](https://github.com/airbnb/javascript/issues/678)) +- [minor] Add [`prefer-arrow-callback`][prefer-arrow-callback] to ES6 rules (to match the guide) ([#677](https://github.com/airbnb/javascript/issues/677)) +- [Tests] run `npm run lint` as part of tests; fix errors +- [Tests] use `parallelshell` to parallelize npm run-scripts 3.1.0 / 2016-01-07 ================== - - [minor] Allow multiple stateless components in a single file +- [minor] Allow multiple stateless components in a single file 3.0.2 / 2016-01-06 ================== - - [fix] Ignore URLs in `max-len` (#664) +- [fix] Ignore URLs in [`max-len`][max-len] ([#664](https://github.com/airbnb/javascript/issues/664)) 3.0.1 / 2016-01-06 ================== - - [fix] because we use babel, keywords should not be quoted +- [fix] because we use babel, keywords should not be quoted 3.0.0 / 2016-01-04 ================== - - [breaking] enable `quote-props` rule (#632) - - [breaking] Define a max line length of 100 characters (#639) - - [breaking] [react] Minor cleanup for the React styleguide, add `react/jsx-no-bind` (#619) - - [breaking] update best-practices config to prevent parameter object manipulation (#627) - - [minor] Enable react/no-is-mounted rule (#635, #633) - - [minor] Sort react/prefer-es6-class alphabetically (#634) - - [minor] enable react/prefer-es6-class rule - - Permit strict mode in "legacy" config - - [react] add missing rules from eslint-plugin-react (enforcing where necessary) (#581) - - [dev deps] update `eslint-plugin-react` +- [breaking] enable [`quote-props`][quote-props] rule ([#632](https://github.com/airbnb/javascript/issues/632)) +- [breaking] Define a max line length of 100 characters ([#639](https://github.com/airbnb/javascript/issues/639)) +- [breaking] [react] Minor cleanup for the React styleguide, add [`react/jsx-no-bind`][react/jsx-no-bind] ([#619](https://github.com/airbnb/javascript/issues/619)) +- [breaking] update best-practices config to prevent parameter object manipulation ([#627](https://github.com/airbnb/javascript/issues/627)) +- [minor] Enable [`react/no-is-mounted`][react/no-is-mounted] rule (#635, #633) +- [minor] Sort [`react/prefer-es6-class`][react/prefer-es6-class] alphabetically ([#634](https://github.com/airbnb/javascript/issues/634)) +- [minor] enable [`react/prefer-es6-class`][react/prefer-es6-class] rule +- Permit strict mode in "legacy" config +- [react] add missing rules from `eslint-plugin-react` (enforcing where necessary) ([#581](https://github.com/airbnb/javascript/issues/581)) +- [dev deps] update `eslint-plugin-react` 2.1.1 / 2015-12-15 ================== - - [fix] Remove deprecated react/jsx-quotes (#622) +- [fix] Remove deprecated [`react/jsx-quotes`][react/jsx-quotes] ([#622](https://github.com/airbnb/javascript/issues/622)) 2.1.0 / 2015-12-15 ================== - - [fix] use `require.resolve` to allow nested `extend`s (#582) - - [new] enable `object-shorthand` rule (#621) - - [new] enable `arrow-spacing` rule (#517) - - [docs] flesh out react rule defaults (#618) +- [fix] use `require.resolve` to allow nested `extend`s ([#582](https://github.com/airbnb/javascript/issues/582)) +- [new] enable [`object-shorthand`][object-shorthand] rule ([#621](https://github.com/airbnb/javascript/issues/621)) +- [new] enable [`arrow-spacing`][arrow-spacing] rule ([#517](https://github.com/airbnb/javascript/issues/517)) +- [docs] flesh out react rule defaults ([#618](https://github.com/airbnb/javascript/issues/618)) 2.0.0 / 2015-12-03 ================== - - [breaking] `space-before-function-paren`: require function spacing: `function (` (#605) - - [breaking] `indent`: Fix switch statement indentation rule (#606) - - [breaking] `array-bracket-spacing`, `computed-property-spacing`: disallow spacing inside brackets (#594) - - [breaking] `object-curly-spacing`: require padding inside curly braces (#594) - - [breaking] `space-in-parens`: disallow spaces in parens (#594) +- [breaking] [`space-before-function-paren`][space-before-function-paren]: require function spacing: `function (` ([#605](https://github.com/airbnb/javascript/issues/605)) +- [breaking] [`indent`][indent]: Fix switch statement indentation rule ([#606](https://github.com/airbnb/javascript/issues/606)) +- [breaking] [`array-bracket-spacing`][array-bracket-spacing], [`computed-property-spacing`][computed-property-spacing]: disallow spacing inside brackets ([#594](https://github.com/airbnb/javascript/issues/594)) +- [breaking] [`object-curly-spacing`][object-curly-spacing]: require padding inside curly braces ([#594](https://github.com/airbnb/javascript/issues/594)) +- [breaking] [`space-in-parens`][space-in-parens]: disallow spaces in parens ([#594](https://github.com/airbnb/javascript/issues/594)) 1.0.2 / 2015-11-25 ================== - - [breaking] `no-multiple-empty-lines`: only allow 1 blank line at EOF (#578) - - [new] `restParams`: enable rest params (#592) +- [breaking] [`no-multiple-empty-lines`][no-multiple-empty-lines]: only allow 1 blank line at EOF ([#578](https://github.com/airbnb/javascript/issues/578)) +- [new] `restParams`: enable rest params ([#592](https://github.com/airbnb/javascript/issues/592)) 1.0.1 / 2015-11-25 ================== - - *erroneous publish* +- *erroneous publish* 1.0.0 / 2015-11-08 ================== - - require `eslint` `v1.0.0` or higher - - remove `babel-eslint` dependency +- require `eslint` `v1.0.0` or higher +- remove `babel-eslint` dependency 0.1.1 / 2015-11-05 ================== - - remove id-length rule (#569) - - enable `no-mixed-spaces-and-tabs` (#539) - - enable `no-const-assign` (#560) - - enable `space-before-keywords` (#554) +- remove [`id-length`][id-length] rule ([#569](https://github.com/airbnb/javascript/issues/569)) +- enable [`no-mixed-spaces-and-tabs`][no-mixed-spaces-and-tabs] ([#539](https://github.com/airbnb/javascript/issues/539)) +- enable [`no-const-assign`][no-const-assign] ([#560](https://github.com/airbnb/javascript/issues/560)) +- enable [`space-before-keywords`][space-before-keywords] ([#554](https://github.com/airbnb/javascript/issues/554)) 0.1.0 / 2015-11-05 ================== - - switch to modular rules files courtesy the [eslint-config-default][ecd] project and [@taion][taion]. [PR][pr-modular] - - export `eslint-config-airbnb/legacy` for ES5-only users. `eslint-config-airbnb/legacy` does not require the `babel-eslint` parser. [PR][pr-legacy] +- switch to modular rules files courtesy the [eslint-config-default][ecd] project and [@taion][taion]. [PR][pr-modular] +- export `eslint-config-airbnb/legacy` for ES5-only users. `eslint-config-airbnb/legacy` does not require the `babel-eslint` parser. [PR][pr-legacy] 0.0.9 / 2015-09-24 ================== -- add rule `no-undef` -- add rule `id-length` +- add rule [`no-undef`][no-undef] +- add rule [`id-length`][id-length] 0.0.8 / 2015-08-21 ================== - - now has a changelog - - now is modular (see instructions above for with react and without react versions) +- now has a changelog +- now is modular (see instructions above for with react and without react versions) 0.0.7 / 2015-07-30 ================== - - TODO: fill in +- TODO: fill in + [ecd]: https://github.com/walmartlabs/eslint-config-defaults [taion]: https://github.com/taion [pr-modular]: https://github.com/airbnb/javascript/pull/526 [pr-legacy]: https://github.com/airbnb/javascript/pull/527 + +[array-bracket-spacing]: http://eslint.org/docs/rules/array-bracket-spacing +[array-callback-return]: http://eslint.org/docs/rules/array-callback-return +[arrow-body-style]: http://eslint.org/docs/rules/arrow-body-style +[arrow-spacing]: http://eslint.org/docs/rules/arrow-spacing +[computed-property-spacing]: http://eslint.org/docs/rules/computed-property-spacing +[id-length]: http://eslint.org/docs/rules/id-length +[indent]: http://eslint.org/docs/rules/indent +[max-len]: http://eslint.org/docs/rules/max-len +[newline-per-chained-call]: http://eslint.org/docs/rules/newline-per-chained-call +[no-confusing-arrow]: http://eslint.org/docs/rules/no-confusing-arrow +[no-const-assign]: http://eslint.org/docs/rules/no-const-assign +[no-mixed-spaces-and-tabs]: http://eslint.org/docs/rules/no-mixed-spaces-and-tabs +[no-multiple-empty-lines]: http://eslint.org/docs/rules/no-multiple-empty-lines +[no-new-symbol]: http://eslint.org/docs/rules/no-new-symbol +[no-restricted-imports]: http://eslint.org/docs/rules/no-restricted-imports +[no-self-assign]: http://eslint.org/docs/rules/no-self-assign +[no-undef]: http://eslint.org/docs/rules/no-undef +[no-useless-constructor]: http://eslint.org/docs/rules/no-useless-constructor +[no-whitespace-before-property]: http://eslint.org/docs/rules/no-whitespace-before-property +[object-curly-spacing]: http://eslint.org/docs/rules/object-curly-spacing +[object-shorthand]: http://eslint.org/docs/rules/object-shorthand +[one-var-declaration-per-line]: http://eslint.org/docs/rules/one-var-declaration-per-line +[prefer-arrow-callback]: http://eslint.org/docs/rules/prefer-arrow-callback +[prefer-rest-params]: http://eslint.org/docs/rules/prefer-rest-params +[prefer-template]: http://eslint.org/docs/rules/prefer-template +[quote-props]: http://eslint.org/docs/rules/quote-props +[space-before-function-paren]: http://eslint.org/docs/rules/space-before-function-paren +[space-before-keywords]: http://eslint.org/docs/rules/space-before-keywords +[space-in-parens]: http://eslint.org/docs/rules/space-in-parens +[template-curly-spacing]: http://eslint.org/docs/rules/template-curly-spacing + +[react/jsx-space-before-closing]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md +[react/sort-comp]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md +[react/display-name]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md +[react/jsx-no-bind]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md +[react/no-is-mounted]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md +[react/prefer-es6-class]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md +[react/jsx-quotes]: https://github.com/yannickcr/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md \ No newline at end of file From 30c448d1df2c5a16bee4dd618ebdcf908b7475a3 Mon Sep 17 00:00:00 2001 From: David Bows Date: Tue, 23 Feb 2016 07:18:10 -0500 Subject: [PATCH 0049/1120] Updated "In The Wild" to include Brainshark. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 06a4eb6b43..e4ced5f970 100644 --- a/README.md +++ b/README.md @@ -2520,6 +2520,7 @@ Other Style Guides - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/) - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript) + - **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript) - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide) - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) From 2d8409c3e549f082f30c37d62d64304289380f52 Mon Sep 17 00:00:00 2001 From: Javier Villanueva Date: Wed, 24 Feb 2016 11:03:46 +0000 Subject: [PATCH 0050/1120] Enforce literal syntax for array creation --- packages/eslint-config-airbnb/rules/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index b9b0e23f5c..6e1278161a 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -64,7 +64,7 @@ module.exports = { // http://eslint.org/docs/rules/newline-per-chained-call 'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 3 }], // disallow use of the Array constructor - 'no-array-constructor': 0, + 'no-array-constructor': 2, // disallow use of the continue statement 'no-continue': 0, // disallow comments inline after code From d321f68c462acbec50d9cf6a977f1a4a50e8924e Mon Sep 17 00:00:00 2001 From: Nick Hwang Date: Wed, 24 Feb 2016 13:53:14 -0500 Subject: [PATCH 0051/1120] Fix word spacing and preserve consistent quotes --- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- packages/eslint-config-airbnb/rules/react.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 6f66792478..ff782a5b7a 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -76,7 +76,7 @@ module.exports = { 'no-new': 2, // disallow use of new operator for Function object 'no-new-func': 2, - // disallows creating new instances of String,Number, and Boolean + // disallows creating new instances of String, Number, and Boolean 'no-new-wrappers': 2, // disallow use of (old style) octal literals 'no-octal': 2, diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index b7a9889e69..6071cd3004 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -106,7 +106,7 @@ module.exports = { 'react/prefer-es6-class': [2, 'always'], // Prevent missing props validation in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md - 'react/prop-types': [2, { 'ignore': [], customValidators: [] }], + 'react/prop-types': [2, { 'ignore': [], 'customValidators': [] }], // Prevent missing React when using JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md 'react/react-in-jsx-scope': 2, From 7684892951ef663e1c4e62ad57d662e9b2748b9e Mon Sep 17 00:00:00 2001 From: Boris Besemer Date: Thu, 25 Feb 2016 09:12:52 +0100 Subject: [PATCH 0052/1120] fixes tiny typo's on JSCS rules --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4ced5f970..44a317e0bd 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ Other Style Guides const item = {}; ``` - - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) + - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -161,7 +161,7 @@ Other Style Guides }; ``` - - [3.3](#3.3) Use readable synonyms in place of reserved words. jscs: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) + - [3.3](#3.3) Use readable synonyms in place of reserved words. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad From 607ad012eeaa4e72601b381d49ddb905dee2f138 Mon Sep 17 00:00:00 2001 From: chief10 Date: Tue, 1 Mar 2016 15:28:10 -0600 Subject: [PATCH 0053/1120] change wording for 8.2 for consistency --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 44a317e0bd..32068abd57 100644 --- a/README.md +++ b/README.md @@ -759,15 +759,15 @@ Other Style Guides > Why not? If you plan on returning an object. ```javascript - // good - [1, 2, 3].map(number => `A string containing the ${number}.`); - // bad [1, 2, 3].map(number => { const nextNumber = number + 1; `A string containing the ${nextNumber}.`; }); + // good + [1, 2, 3].map(number => `A string containing the ${number}.`); + // good [1, 2, 3].map((number) => { const nextNumber = number + 1; From 246cde0de837218c16595246f81c900320c57c0b Mon Sep 17 00:00:00 2001 From: Hyeonsu Lee Date: Wed, 2 Mar 2016 10:25:02 +0900 Subject: [PATCH 0054/1120] Fix the typo error in JSHint link --- es5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es5/README.md b/es5/README.md index 2d24f1a4a2..caaa17b503 100644 --- a/es5/README.md +++ b/es5/README.md @@ -1562,7 +1562,7 @@ **Tools** - Code Style Linters - + [JSHint](http://www.jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc) + + [JSHint](http://www.jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/.jshintrc) + [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json) **Other Style Guides** From 32e3e0f45a60aeed038619116548de6ff8197c16 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Duhaime Date: Wed, 2 Mar 2016 09:42:02 -0500 Subject: [PATCH 0055/1120] Update README.md Add colon to TODO and FIXME. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32068abd57..875c1a724d 100644 --- a/README.md +++ b/README.md @@ -1550,7 +1550,7 @@ Other Style Guides } ``` - - [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`. + - [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`. - [17.4](#17.4) Use `// FIXME:` to annotate problems. From 03d0054a46dff8b8fc337a39b84acf69e420e678 Mon Sep 17 00:00:00 2001 From: David Petersen Date: Wed, 2 Mar 2016 09:11:46 -0600 Subject: [PATCH 0056/1120] Enable react/prefer-stateless-function rule --- packages/eslint-config-airbnb/rules/react.js | 3 +++ react/README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 6071cd3004..835fb43125 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -104,6 +104,9 @@ module.exports = { // Require ES6 class declarations over React.createClass // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md 'react/prefer-es6-class': [2, 'always'], + // Require stateless functions when not using lifecycle methods, setState or ref + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md + 'react/prefer-stateless-function': 2, // Prevent missing props validation in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md 'react/prop-types': [2, { 'ignore': [], 'customValidators': [] }], diff --git a/react/README.md b/react/README.md index e0351f42a7..8bab601e12 100644 --- a/react/README.md +++ b/react/README.md @@ -27,7 +27,7 @@ ## Class vs `React.createClass` vs stateless - - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) + - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) ```javascript // bad From 762b7510ab8ff0e3f282c9ae6cc985f8262038a8 Mon Sep 17 00:00:00 2001 From: Jon Tejada Date: Thu, 3 Mar 2016 15:21:53 -0800 Subject: [PATCH 0057/1120] fixed a broken link to REI's JS style guide --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 875c1a724d..d7b56aae9a 100644 --- a/README.md +++ b/README.md @@ -2560,7 +2560,7 @@ Other Style Guides - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide) - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript) - **React**: [/facebook/react/blob/master/CONTRIBUTING.md#style-guide](https://github.com/facebook/react/blob/master/CONTRIBUTING.md#style-guide) - - **REI**: [reidev/js-style-guide](https://github.com/reidev/js-style-guide) + - **REI**: [reidev/js-style-guide](https://github.com/rei/code-style-guides/blob/master/docs/javascript.md) - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide) - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide) - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) From 87616367cbf0a298a6e5f3a85cdd4f1ba317ea57 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 4 Mar 2016 20:05:42 -0800 Subject: [PATCH 0058/1120] [Dev Deps] update `eslint`, `tape`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 6 +++--- packages/eslint-config-airbnb/rules/es6.js | 2 ++ packages/eslint-config-airbnb/rules/style.js | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 9478f804fd..dd86cda2d0 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,10 +43,10 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.2.0", - "eslint-plugin-react": "^4.0.0", + "eslint": "^2.3.0", + "eslint-plugin-react": "^4.1.0", "react": "^0.14.7", - "tape": "^4.4.0", + "tape": "^4.5.0", "parallelshell": "^2.0.0" }, "peerDependencies": { diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index ef50e0a7f5..d0b7bbde9f 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -36,6 +36,8 @@ module.exports = { // disallow symbol constructor // http://eslint.org/docs/rules/no-new-symbol 'no-new-symbol': 2, + // disallow specific globals + 'no-restricted-globals': 0, // disallow specific imports // http://eslint.org/docs/rules/no-restricted-imports 'no-restricted-imports': 0, diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 6e1278161a..d811f8851f 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -59,6 +59,8 @@ module.exports = { 'new-parens': 0, // allow/disallow an empty newline after var statement 'newline-after-var': 0, + // http://eslint.org/docs/rules/newline-before-return + 'newline-before-return': 0, // enforces new line after each method call in the chain to make it // more readable and easy to maintain // http://eslint.org/docs/rules/newline-per-chained-call From 7b8a0ca85d11d01dabfd51bdd0125c3624a1a0e3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Mar 2016 14:19:34 -0800 Subject: [PATCH 0059/1120] [Dev Deps] update `eslint-plugin-react` (new rule is in #772) --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index dd86cda2d0..068cbab823 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -44,7 +44,7 @@ "devDependencies": { "babel-tape-runner": "^1.3.1", "eslint": "^2.3.0", - "eslint-plugin-react": "^4.1.0", + "eslint-plugin-react": "^4.2.0", "react": "^0.14.7", "tape": "^4.5.0", "parallelshell": "^2.0.0" From 0ece94f5bf2575b20ff69d38c6660da52382fb33 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Mar 2016 14:43:58 -0800 Subject: [PATCH 0060/1120] [eslint config] v6.1.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 5 +++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 109d7becd2..bb9374e170 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,8 @@ +6.1.0 / 2016-02-22 +================== +- [new] enable [`react/prefer-stateless-function`][react/prefer-stateless-function] +- [dev deps] update `react-plugin-eslint`, `eslint`, `tape` + 6.0.2 / 2016-02-22 ================== - [fix] disable [`no-confusing-arrow`][no-confusing-arrow] due to an `eslint` bug ([#752](https://github.com/airbnb/javascript/issues/752)) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 068cbab823..9c26a62532 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.0.2", + "version": "6.1.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 8b6abf8cda2be140a15bb08deca2770d419d2882 Mon Sep 17 00:00:00 2001 From: Maks Sadowsky Date: Sun, 6 Mar 2016 11:01:01 +0200 Subject: [PATCH 0061/1120] Update README: Document corresponding jscs rules --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d7b56aae9a..f3e09449f8 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,7 @@ Other Style Guides const [first, second] = arr; ``` - - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring. + - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn) > Why? You can add new properties over time or change the order of things without breaking call sites. From e7f5e0f336501282bfdfc7a58424d140fb543533 Mon Sep 17 00:00:00 2001 From: giang pi Date: Mon, 7 Mar 2016 14:01:57 +0700 Subject: [PATCH 0062/1120] Vietnamese language --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f3e09449f8..b8c355601d 100644 --- a/README.md +++ b/README.md @@ -2595,6 +2595,7 @@ Other Style Guides - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [uprock/javascript](https://github.com/uprock/javascript) - ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide) - ![th](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Thailand.png) **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide) + - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [giangpii/javascript-style-guide](https://github.com/giangpii/javascript-style-guide) ## The JavaScript Style Guide Guide From 34f64c21e56df09e548d04f29e16664b80fc1b93 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 Mar 2016 14:16:06 -0800 Subject: [PATCH 0063/1120] Add defaults for `react/jsx-no-bind` --- packages/eslint-config-airbnb/rules/react.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 835fb43125..a5d0d17de2 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -40,7 +40,11 @@ module.exports = { 'react/jsx-max-props-per-line': [0, { 'maximum': 1 }], // Prevent usage of .bind() and arrow functions in JSX props // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md - 'react/jsx-no-bind': 2, + 'react/jsx-no-bind': [2, { + 'ignoreRefs': false, + 'allowArrowFunctions': false, + 'allowBind': false, + }], // Prevent duplicate props in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md 'react/jsx-no-duplicate-props': [0, { 'ignoreCase': false }], From 01fc30b65b64ad9485dfccd8f64257e77475dd83 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 Mar 2016 14:48:32 -0800 Subject: [PATCH 0064/1120] [Dev Deps] update `tape` --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 9c26a62532..0721839841 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -46,7 +46,7 @@ "eslint": "^2.3.0", "eslint-plugin-react": "^4.2.0", "react": "^0.14.7", - "tape": "^4.5.0", + "tape": "^4.5.1", "parallelshell": "^2.0.0" }, "peerDependencies": { From 9e87e1d13bb8258adcdc7b05c7bece52adc1abbb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 8 Mar 2016 10:07:30 -0800 Subject: [PATCH 0065/1120] [guide] add some more justification for one-var and `String()` type coercions --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b8c355601d..97530e537a 100644 --- a/README.md +++ b/README.md @@ -590,7 +590,7 @@ Other Style Guides - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) - > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`. + > Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`. ```javascript // bad @@ -1112,7 +1112,7 @@ Other Style Guides - [13.2](#13.2) Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) - > 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. + > 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. You can also step through each declaration with the debugger, instead of jumping through all of them at once. ```javascript // bad @@ -1339,6 +1339,7 @@ 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. @@ -2011,7 +2012,10 @@ Other Style Guides // => this.reviewScore = 9; // bad - const totalScore = this.reviewScore + ''; + const totalScore = this.reviewScore + ''; // invokes this.reviewScore.valueOf() + + // bad + const totalScore = this.reviewScore.toString(); // isn't guaranteed to return a string // good const totalScore = String(this.reviewScore); From 4709e644c0a622e020c3d5446a4cb1f22e910b10 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 Mar 2016 22:50:40 -0800 Subject: [PATCH 0066/1120] [guide] Permanent links. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Preserve the original links, because cool URLs don’t change. --- README.md | 376 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 247 insertions(+), 129 deletions(-) diff --git a/README.md b/README.md index 97530e537a..5368efacf7 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ Other Style Guides ## Types - - [1.1](#1.1) **Primitives**: When you access a primitive type you work directly on its value. + + - [1.1](#types--primitives) **Primitives**: When you access a primitive type you work directly on its value. + `string` + `number` @@ -68,7 +69,9 @@ Other Style Guides console.log(foo, bar); // => 1, 9 ``` - - [1.2](#1.2) **Complex**: When you access a complex type you work on a reference to its value. + + + - [1.2](#types--complex) **Complex**: When you access a complex type you work on a reference to its value. + `object` + `array` @@ -87,7 +90,8 @@ Other Style Guides ## References - - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. eslint: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html) + + - [2.1](#references--prefer-const) Use `const` for all of your references; avoid using `var`. eslint: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html) > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. @@ -101,7 +105,8 @@ Other Style Guides const b = 2; ``` - - [2.2](#2.2) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](http://eslint.org/docs/rules/no-var.html) jscs: [`disallowVar`](http://jscs.info/rule/disallowVar) + + - [2.2](#references--disallow-var) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](http://eslint.org/docs/rules/no-var.html) jscs: [`disallowVar`](http://jscs.info/rule/disallowVar) > Why? `let` is block-scoped rather than function-scoped like `var`. @@ -119,7 +124,8 @@ Other Style Guides } ``` - - [2.3](#2.3) Note that both `let` and `const` are block-scoped. + + - [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped. ```javascript // const and let only exist in the blocks they are defined in. @@ -135,7 +141,8 @@ Other Style Guides ## Objects - - [3.1](#3.1) Use the literal syntax for object creation. eslint: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html) + + - [3.1](#objects--no-new) Use the literal syntax for object creation. eslint: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html) ```javascript // bad @@ -145,7 +152,8 @@ Other Style Guides const item = {}; ``` - - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) + + - [3.2](#objects--reserved-words) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -161,7 +169,8 @@ Other Style Guides }; ``` - - [3.3](#3.3) Use readable synonyms in place of reserved words. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) + + - [3.3](#objects--reserved-words-2) Use readable synonyms in place of reserved words. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -180,8 +189,8 @@ Other Style Guides }; ``` - - - [3.4](#3.4) Use computed property names when creating objects with dynamic property names. + + - [3.4](#es6-computed-properties) Use computed property names when creating objects with dynamic property names. > Why? They allow you to define all the properties of an object in one place. @@ -206,8 +215,8 @@ Other Style Guides }; ``` - - - [3.5](#3.5) Use object method shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + + - [3.5](#es6-object-shorthand) Use object method shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) ```javascript // bad @@ -229,8 +238,8 @@ Other Style Guides }; ``` - - - [3.6](#3.6) Use property value shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + + - [3.6](#es6-object-concise) Use property value shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) > Why? It is shorter to write and descriptive. @@ -248,7 +257,8 @@ Other Style Guides }; ``` - - [3.7](#3.7) Group your shorthand properties at the beginning of your object declaration. + + - [3.7](#objects--grouped-shorthand) Group your shorthand properties at the beginning of your object declaration. > Why? It's easier to tell which properties are using the shorthand. @@ -277,7 +287,8 @@ Other Style Guides }; ``` - - [3.8](#3.8) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) + + - [3.8](#objects-quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. @@ -301,7 +312,8 @@ Other Style Guides ## Arrays - - [4.1](#4.1) Use the literal syntax for array creation. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html) + + - [4.1](#arrays--literals) Use the literal syntax for array creation. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html) ```javascript // bad @@ -311,7 +323,8 @@ Other Style Guides const items = []; ``` - - [4.2](#4.2) Use Array#push instead of direct assignment to add items to an array. + + - [4.2](#arrays--push) Use Array#push instead of direct assignment to add items to an array. ```javascript const someStack = []; @@ -323,8 +336,8 @@ Other Style Guides someStack.push('abracadabra'); ``` - - - [4.3](#4.3) Use array spreads `...` to copy arrays. + + - [4.3](#es6-array-spreads) Use array spreads `...` to copy arrays. ```javascript // bad @@ -339,14 +352,17 @@ Other Style Guides // good const itemsCopy = [...items]; ``` - - [4.4](#4.4) To convert an array-like object to an array, use Array#from. + + + - [4.4](#arrays--from) To convert an array-like object to an array, use Array#from. ```javascript const foo = document.querySelectorAll('.foo'); const nodes = Array.from(foo); ``` - - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return) + + - [4.5](#arrays--callback-return) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return) ```javascript // good @@ -398,7 +414,8 @@ Other Style Guides ## Destructuring - - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) + + - [5.1](#destructuring--object) Use object destructuring when accessing and using multiple properties of an object. jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) > Why? Destructuring saves you from creating temporary references for those properties. @@ -423,7 +440,8 @@ Other Style Guides } ``` - - [5.2](#5.2) Use array destructuring. jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) + + - [5.2](#destructuring--array) Use array destructuring. jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) ```javascript const arr = [1, 2, 3, 4]; @@ -436,7 +454,8 @@ Other Style Guides const [first, second] = arr; ``` - - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn) + + - [5.3](#destructuring--object-over-array) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn) > Why? You can add new properties over time or change the order of things without breaking call sites. @@ -465,7 +484,8 @@ Other Style Guides ## Strings - - [6.1](#6.1) Use single quotes `''` for strings. eslint: [`quotes`](http://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) + + - [6.1](#strings--quotes) Use single quotes `''` for strings. eslint: [`quotes`](http://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) ```javascript // bad @@ -475,8 +495,11 @@ Other Style Guides const name = 'Capt. Janeway'; ``` - - [6.2](#6.2) Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation. - - [6.3](#6.3) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). + + - [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation. + + + - [6.3](#strings--concat-perf) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). ```javascript // bad @@ -494,8 +517,8 @@ Other Style Guides 'with this, you would get nowhere fast.'; ``` - - - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) + + - [6.4](#es6-template-literals) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. @@ -520,14 +543,17 @@ Other Style Guides return `How are you, ${name}?`; } ``` - - [6.5](#6.5) Never use `eval()` on a string, it opens too many vulnerabilities. + + + - [6.5](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities. **[⬆ back to top](#table-of-contents)** ## Functions - - [7.1](#7.1) Use function declarations instead of function expressions. jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) + + - [7.1](#functions--declarations) Use function declarations instead of function expressions. jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. @@ -541,7 +567,8 @@ Other Style Guides } ``` - - [7.2](#7.2) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) + + - [7.2](#functions--iife) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) > Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE. @@ -552,9 +579,11 @@ Other Style Guides }()); ``` - - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html) + + - [7.3](#functions--in-blocks) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html) - - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). + + - [7.4](#functions--note-on-blocks) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). ```javascript // bad @@ -573,7 +602,8 @@ Other Style Guides } ``` - - [7.5](#7.5) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope. + + - [7.5](#functions--arguments-shadow) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope. ```javascript // bad @@ -587,8 +617,8 @@ Other Style Guides } ``` - - - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) + + - [7.6](#es6-rest) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) > Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`. @@ -605,8 +635,8 @@ Other Style Guides } ``` - - - [7.7](#7.7) Use default parameter syntax rather than mutating function arguments. + + - [7.7](#es6-default-parameters) Use default parameter syntax rather than mutating function arguments. ```javascript // really bad @@ -632,7 +662,8 @@ Other Style Guides } ``` - - [7.8](#7.8) Avoid side effects with default parameters. + + - [7.8](#functions--default-side-effects) Avoid side effects with default parameters. > Why? They are confusing to reason about. @@ -648,7 +679,8 @@ Other Style Guides count(); // 3 ``` - - [7.9](#7.9) Always put default parameters last. + + - [7.9](#functions--defaults-last) Always put default parameters last. ```javascript // bad @@ -662,7 +694,8 @@ Other Style Guides } ``` - - [7.10](#7.10) Never use the Function constructor to create a new function. + + - [7.10](#functions--constructor) Never use the Function constructor to create a new function. > Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities. @@ -674,7 +707,8 @@ Other Style Guides var subtract = Function('a', 'b', 'return a - b'); ``` - - [7.11](#7.11) Spacing in a function signature. + + - [7.11](#functions--signature-spacing) 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. @@ -689,7 +723,8 @@ Other Style Guides const y = function a() {}; ``` - - [7.12](#7.12) Never mutate parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) + + - [7.12](#functions--mutate-params) Never mutate parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller. @@ -705,7 +740,8 @@ Other Style Guides }; ``` - - [7.13](#7.13) Never reassign parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) + + - [7.13](#functions--reassign-params) Never reassign parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8. @@ -732,7 +768,8 @@ Other Style Guides ## Arrow Functions - - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation. eslint: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) + + - [8.1](#arrows--use-them) When you must use function expressions (as when passing an anonymous function), use arrow function notation. eslint: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) > Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax. @@ -752,7 +789,8 @@ Other Style Guides }); ``` - - [8.2](#8.2) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions) + + - [8.2](#arrows--implicit-return) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions) > Why? Syntactic sugar. It reads well when multiple functions are chained together. @@ -775,7 +813,8 @@ Other Style Guides }); ``` - - [8.3](#8.3) In case the expression spans over multiple lines, wrap it in parentheses for better readability. + + - [8.3](#arrows--paren-wrap) 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. @@ -793,8 +832,8 @@ Other Style Guides )); ``` - - - [8.4](#8.4) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) + + - [8.4](#arrows--one-arg-parens) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) > Why? Less visual clutter. @@ -824,7 +863,8 @@ Other Style Guides }); ``` - - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](http://eslint.org/docs/rules/no-confusing-arrow) + + - [8.5](#arrows--confusing) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](http://eslint.org/docs/rules/no-confusing-arrow) ```js // bad @@ -842,7 +882,8 @@ Other Style Guides ## Constructors - - [9.1](#9.1) Always use `class`. Avoid manipulating `prototype` directly. + + - [9.1](#constructors--use-class) Always use `class`. Avoid manipulating `prototype` directly. > Why? `class` syntax is more concise and easier to reason about. @@ -871,7 +912,8 @@ Other Style Guides } ``` - - [9.2](#9.2) Use `extends` for inheritance. + + - [9.2](#constructors--extends) Use `extends` for inheritance. > Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`. @@ -894,7 +936,8 @@ Other Style Guides } ``` - - [9.3](#9.3) Methods can return `this` to help with method chaining. + + - [9.3](#constructors--chaining) Methods can return `this` to help with method chaining. ```javascript // bad @@ -931,7 +974,8 @@ Other Style Guides ``` - - [9.4](#9.4) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects. + + - [9.4](#constructors--tostring) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects. ```javascript class Jedi { @@ -949,7 +993,8 @@ Other Style Guides } ``` - - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) + + - [9.5](#constructors--no-useless) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) ```javascript // bad @@ -982,7 +1027,8 @@ Other Style Guides ## Modules - - [10.1](#10.1) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system. + + - [10.1](#modules--use-them) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system. > Why? Modules are the future, let's start using the future now. @@ -1000,7 +1046,8 @@ Other Style Guides export default es6; ``` - - [10.2](#10.2) Do not use wildcard imports. + + - [10.2](#modules--no-wildcard) Do not use wildcard imports. > Why? This makes sure you have a single default export. @@ -1012,7 +1059,8 @@ Other Style Guides import AirbnbStyleGuide from './AirbnbStyleGuide'; ``` - - [10.3](#10.3) And do not export directly from an import. + + - [10.3](#modules--no-export-from-import) And do not export directly from an import. > Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent. @@ -1031,7 +1079,8 @@ Other Style Guides ## Iterators and Generators - - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) + + - [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. @@ -1056,7 +1105,8 @@ Other Style Guides sum === 15; ``` - - [11.2](#11.2) Don't use generators for now. + + - [11.2](#generators--nope) Don't use generators for now. > Why? They don't transpile well to ES5. @@ -1065,7 +1115,8 @@ Other Style Guides ## Properties - - [12.1](#12.1) Use dot notation when accessing properties. eslint: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html) jscs: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation) + + - [12.1](#properties--dot) Use dot notation when accessing properties. eslint: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html) jscs: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation) ```javascript const luke = { @@ -1080,7 +1131,8 @@ Other Style Guides const isJedi = luke.jedi; ``` - - [12.2](#12.2) Use subscript notation `[]` when accessing properties with a variable. + + - [12.2](#properties--bracket) Use bracket notation `[]` when accessing properties with a variable. ```javascript const luke = { @@ -1100,7 +1152,8 @@ Other Style Guides ## Variables - - [13.1](#13.1) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. + + - [13.1](#variables--const) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. ```javascript // bad @@ -1110,7 +1163,8 @@ Other Style Guides const superPower = new SuperPower(); ``` - - [13.2](#13.2) Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) + + - [13.2](#variables--one-const) Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) > 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. You can also step through each declaration with the debugger, instead of jumping through all of them at once. @@ -1132,7 +1186,8 @@ Other Style Guides const dragonball = 'z'; ``` - - [13.3](#13.3) Group all your `const`s and then group all your `let`s. + + - [13.3](#variables--const-let-group) Group all your `const`s and then group all your `let`s. > Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables. @@ -1157,7 +1212,8 @@ Other Style Guides let length; ``` - - [13.4](#13.4) Assign variables where you need them, but place them in a reasonable place. + + - [13.4](#variables--define-where-used) Assign variables where you need them, but place them in a reasonable place. > Why? `let` and `const` are block scoped and not function scoped. @@ -1200,7 +1256,8 @@ Other Style Guides ## Hoisting - - [14.1](#14.1) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15). + + - [14.1](#hoisting--about) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15). ```javascript // we know this wouldn't work (assuming there @@ -1235,7 +1292,8 @@ Other Style Guides } ``` - - [14.2](#14.2) Anonymous function expressions hoist their variable name, but not the function assignment. + + - [14.2](#hoisting--anon-expressions) Anonymous function expressions hoist their variable name, but not the function assignment. ```javascript function example() { @@ -1249,7 +1307,8 @@ Other Style Guides } ``` - - [14.3](#14.3) Named function expressions hoist the variable name, not the function name or the function body. + + - [14.3](#hoisting--named-expresions) Named function expressions hoist the variable name, not the function name or the function body. ```javascript function example() { @@ -1277,7 +1336,8 @@ Other Style Guides } ``` - - [14.4](#14.4) Function declarations hoist their name and the function body. + + - [14.4](#hoisting--declarations) Function declarations hoist their name and the function body. ```javascript function example() { @@ -1296,9 +1356,11 @@ Other Style Guides ## Comparison Operators & Equality - - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. eslint: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html) + + - [15.1](#comparison--eqeqeq) Use `===` and `!==` over `==` and `!=`. eslint: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html) - - [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: + + - [15.2](#comparison--if) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: + **Objects** evaluate to **true** + **Undefined** evaluates to **false** @@ -1314,7 +1376,8 @@ Other Style Guides } ``` - - [15.3](#15.3) Use shortcuts. + + - [15.3](#comparison--shortcuts) Use shortcuts. ```javascript // bad @@ -1338,9 +1401,11 @@ 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.4](#comparison--moreinfo) 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`). + + - [15.5](#comparison--switch-blocks) 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. @@ -1385,7 +1450,8 @@ Other Style Guides } ``` - - [15.6](#15.6) Ternaries should not be nested and generally be single line expressions. + + - [15.6](#comparison--nested-ternaries) Ternaries should not be nested and generally be single line expressions. eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html). @@ -1408,7 +1474,8 @@ Other Style Guides const foo = maybe1 > maybe2 ? 'bar' : maybeNull; ``` - - [15.7](#15.7) Avoid unneeded ternary statements. + + - [15.7](#comparison--unneeded-ternary) Avoid unneeded ternary statements. eslint rules: [`no-unneeded-ternary`](http://eslint.org/docs/rules/no-unneeded-ternary.html). @@ -1429,7 +1496,8 @@ Other Style Guides ## Blocks - - [16.1](#16.1) Use braces with all multi-line blocks. + + - [16.1](#blocks--braces) Use braces with all multi-line blocks. ```javascript // bad @@ -1453,8 +1521,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: [`brace-style`](http://eslint.org/docs/rules/brace-style.html) jscs: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements) + + - [16.2](#blocks--cuddled-elses) 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: [`brace-style`](http://eslint.org/docs/rules/brace-style.html) jscs: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements) ```javascript // bad @@ -1481,7 +1549,8 @@ Other Style Guides ## Comments - - [17.1](#17.1) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values. + + - [17.1](#comments--multiline) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values. ```javascript // bad @@ -1513,7 +1582,8 @@ 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 unless it's on the first line of a block. + + - [17.2](#comments--singleline) 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 @@ -1551,9 +1621,11 @@ Other Style Guides } ``` - - [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`. + + - [17.3](#comments--actionitems) 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`. - - [17.4](#17.4) Use `// FIXME:` to annotate problems. + + - [17.4](#comments--fixme) Use `// FIXME:` to annotate problems. ```javascript class Calculator extends Abacus { @@ -1566,7 +1638,8 @@ Other Style Guides } ``` - - [17.5](#17.5) Use `// TODO:` to annotate solutions to problems. + + - [17.5](#comments--todo) Use `// TODO:` to annotate solutions to problems. ```javascript class Calculator extends Abacus { @@ -1584,7 +1657,8 @@ 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](#whitespace--spaces) Use soft tabs set to 2 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) ```javascript // bad @@ -1603,7 +1677,8 @@ Other Style Guides } ``` - - [18.2](#18.2) Place 1 space before the leading brace. eslint: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html) jscs: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements) + + - [18.2](#whitespace--before-blocks) Place 1 space before the leading brace. eslint: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html) jscs: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements) ```javascript // bad @@ -1629,7 +1704,8 @@ Other Style Guides }); ``` - - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) + + - [18.3](#whitespace--around-keywords) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) ```javascript // bad @@ -1653,7 +1729,8 @@ Other Style Guides } ``` - - [18.4](#18.4) Set off operators with spaces. eslint: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html) jscs: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) + + - [18.4](#whitespace--infix-ops) Set off operators with spaces. eslint: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html) jscs: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) ```javascript // bad @@ -1663,7 +1740,8 @@ Other Style Guides const x = y + 5; ``` - - [18.5](#18.5) End files with a single newline character. + + - [18.5](#whitespace--newline-at-end) End files with a single newline character. ```javascript // bad @@ -1687,7 +1765,8 @@ Other Style Guides })(this);↵ ``` - - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which + + - [18.6](#whitespace--chains) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which emphasizes that the line is a method call, not a new statement. eslint: [`newline-per-chained-call`](http://eslint.org/docs/rules/newline-per-chained-call) [`no-whitespace-before-property`](http://eslint.org/docs/rules/no-whitespace-before-property) ```javascript @@ -1730,7 +1809,8 @@ Other Style Guides const leds = stage.selectAll('.led').data(data); ``` - - [18.7](#18.7) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) + + - [18.7](#whitespace--after-blocks) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) ```javascript // bad @@ -1787,7 +1867,8 @@ Other Style Guides return arr; ``` - - [18.8](#18.8) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html) jscs: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) + + - [18.8](#whitespace--padded-blocks) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html) jscs: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) ```javascript // bad @@ -1819,7 +1900,8 @@ Other Style Guides } ``` - - [18.9](#18.9) Do not add spaces inside parentheses. eslint: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html) jscs: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) + + - [18.9](#whitespace--in-parens) Do not add spaces inside parentheses. eslint: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html) jscs: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) ```javascript // bad @@ -1843,7 +1925,8 @@ Other Style Guides } ``` - - [18.10](#18.10) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html) jscs: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets) + + - [18.10](#whitespace--in-brackets) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html) jscs: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets) ```javascript // bad @@ -1855,7 +1938,8 @@ Other Style Guides console.log(foo[0]); ``` - - [18.11](#18.11) Add spaces inside curly braces. eslint: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets) + + - [18.11](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets) ```javascript // bad @@ -1865,7 +1949,8 @@ Other Style Guides const foo = { clark: 'kent' }; ``` - - [18.12](#18.12) Avoid having lines of code that are longer than 100 characters (including whitespace). eslint: [`max-len`](http://eslint.org/docs/rules/max-len.html) jscs: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) + + - [18.12](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). eslint: [`max-len`](http://eslint.org/docs/rules/max-len.html) jscs: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) > Why? This ensures readability and maintainability. @@ -1894,7 +1979,8 @@ Other Style Guides ## Commas - - [19.1](#19.1) Leading commas: **Nope.** eslint: [`comma-style`](http://eslint.org/docs/rules/comma-style.html) jscs: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) + + - [19.1](#commas--leading-trailing) Leading commas: **Nope.** eslint: [`comma-style`](http://eslint.org/docs/rules/comma-style.html) jscs: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) ```javascript // bad @@ -1928,7 +2014,8 @@ Other Style Guides }; ``` - - [19.2](#19.2) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) + + - [19.2](#commas--dangling) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) > 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. @@ -1976,7 +2063,8 @@ Other Style Guides ## Semicolons - - [20.1](#20.1) **Yup.** eslint: [`semi`](http://eslint.org/docs/rules/semi.html) jscs: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) + + - [20.1](#20.1) **Yup.** eslint: [`semi`](http://eslint.org/docs/rules/semi.html) jscs: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) ```javascript // bad @@ -2005,8 +2093,11 @@ Other Style Guides ## Type Casting & Coercion - - [21.1](#21.1) Perform type coercion at the beginning of the statement. - - [21.2](#21.2) Strings: + + - [21.1](#coercion--explicit) Perform type coercion at the beginning of the statement. + + + - [21.2](#coercion--strings) Strings: ```javascript // => this.reviewScore = 9; @@ -2021,7 +2112,8 @@ Other Style Guides const totalScore = String(this.reviewScore); ``` - - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](http://eslint.org/docs/rules/radix) + + - [21.3](#coercion--numbers) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](http://eslint.org/docs/rules/radix) ```javascript const inputValue = '4'; @@ -2045,7 +2137,8 @@ Other Style Guides const val = parseInt(inputValue, 10); ``` - - [21.4](#21.4) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing. + + - [21.4](#coercion--comment-deviations) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing. ```javascript // good @@ -2057,7 +2150,8 @@ Other Style Guides const val = inputValue >> 0; ``` - - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: + + - [21.5](#coercion--bitwise) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: ```javascript 2147483647 >> 0 //=> 2147483647 @@ -2065,7 +2159,8 @@ Other Style Guides 2147483649 >> 0 //=> -2147483647 ``` - - [21.6](#21.6) Booleans: + + - [21.6](#coercion--booleans) Booleans: ```javascript const age = 0; @@ -2085,7 +2180,8 @@ Other Style Guides ## Naming Conventions - - [22.1](#22.1) Avoid single letter names. Be descriptive with your naming. + + - [22.1](#naming--descriptive) Avoid single letter names. Be descriptive with your naming. ```javascript // bad @@ -2099,7 +2195,8 @@ Other Style Guides } ``` - - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](http://eslint.org/docs/rules/camelcase.html) jscs: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) + + - [22.2](#naming--camelCase) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](http://eslint.org/docs/rules/camelcase.html) jscs: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) ```javascript // bad @@ -2112,7 +2209,8 @@ Other Style Guides function thisIsMyFunction() {} ``` - - [22.3](#22.3) Use PascalCase when naming constructors or classes. eslint: [`new-cap`](http://eslint.org/docs/rules/new-cap.html) jscs: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) + + - [22.3](#naming--PascalCase) Use PascalCase only when naming constructors or classes. eslint: [`new-cap`](http://eslint.org/docs/rules/new-cap.html) jscs: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) ```javascript // bad @@ -2136,7 +2234,8 @@ Other Style Guides }); ``` - - [22.4](#22.4) Use a leading underscore `_` when naming private properties. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) + + - [22.4](#naming--leading-underscore) Use a leading underscore `_` when naming private properties. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) ```javascript // bad @@ -2147,7 +2246,8 @@ Other Style Guides this._firstName = 'Panda'; ``` - - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) + + - [22.5](#naming--self-this) Don't save references to `this`. Use arrow functions or Function#bind. jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) ```javascript // bad @@ -2174,7 +2274,8 @@ Other Style Guides } ``` - - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class. + + - [22.6](#naming--filename-matches-export) If your file exports a single class, your filename should be exactly the name of the class. ```javascript // file contents @@ -2194,7 +2295,8 @@ Other Style Guides import CheckBox from './CheckBox'; ``` - - [22.7](#22.7) Use camelCase when you export-default a function. Your filename should be identical to your function's name. + + - [22.7](#naming--camelCase-default-export) Use camelCase when you export-default a function. Your filename should be identical to your function's name. ```javascript function makeStyleGuide() { @@ -2203,7 +2305,8 @@ Other Style Guides export default makeStyleGuide; ``` - - [22.8](#22.8) Use PascalCase when you export a singleton / function library / bare object. + + - [22.8](#naming--PascalCase-singleton) Use PascalCase when you export a singleton / function library / bare object. ```javascript const AirbnbStyleGuide = { @@ -2220,8 +2323,11 @@ Other Style Guides ## Accessors - - [23.1](#23.1) Accessor functions for properties are not required. - - [23.2](#23.2) Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello'). + + - [23.1](#accessors--not-required) Accessor functions for properties are not required. + + + - [23.2](#accessors--no-getters-setters) Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello'). ```javascript // bad @@ -2237,7 +2343,8 @@ Other Style Guides dragon.setAge(25); ``` - - [23.3](#23.3) If the property is a `boolean`, use `isVal()` or `hasVal()`. + + - [23.3](#accessors--boolean-prefix) If the property/method is a `boolean`, use `isVal()` or `hasVal()`. ```javascript // bad @@ -2251,7 +2358,8 @@ Other Style Guides } ``` - - [23.4](#23.4) It's okay to create get() and set() functions, but be consistent. + + - [23.4](#accessors--consistent) It's okay to create get() and set() functions, but be consistent. ```javascript class Jedi { @@ -2275,7 +2383,8 @@ Other Style Guides ## Events - - [24.1](#24.1) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of: + + - [24.1](#events--hash) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of: ```javascript // bad @@ -2306,7 +2415,8 @@ Other Style Guides ## jQuery - - [25.1](#25.1) Prefix jQuery object variables with a `$`. jscs: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) + + - [25.1](#jquery--dollar-prefix) Prefix jQuery object variables with a `$`. jscs: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) ```javascript // bad @@ -2319,7 +2429,8 @@ Other Style Guides const $sidebarBtn = $('.sidebar-btn'); ``` - - [25.2](#25.2) Cache jQuery lookups. + + - [25.2](#jquery--cache) Cache jQuery lookups. ```javascript // bad @@ -2346,8 +2457,11 @@ Other Style Guides } ``` - - [25.3](#25.3) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16) - - [25.4](#25.4) Use `find` with scoped jQuery object queries. + + - [25.3](#jquery--queries) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16) + + + - [25.4](#jquery--find) Use `find` with scoped jQuery object queries. ```javascript // bad @@ -2371,13 +2485,15 @@ Other Style Guides ## ECMAScript 5 Compatibility - - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/). + + - [26.1](#es5-compat--kangax) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/). **[⬆ back to top](#table-of-contents)** ## ECMAScript 6 Styles - - [27.1](#27.1) This is a collection of links to the various ES6 features. + + - [27.1](#es6-styles) This is a collection of links to the various ES6 features. 1. [Arrow Functions](#arrow-functions) 1. [Classes](#constructors) @@ -2397,7 +2513,8 @@ Other Style Guides ## Testing - - [28.1](#28.1) **Yup.** + + - [28.1](#esting--yup) **Yup.** ```javascript function foo() { @@ -2405,7 +2522,8 @@ Other Style Guides } ``` - - [28.2](#28.2) **No, but seriously**: + + - [28.2](#testing--for-real) **No, but seriously**: - Whichever testing framework you use, you should be writing tests! - Strive to write many small pure functions, and minimize where mutations occur. - Be cautious about stubs and mocks - they can make your tests more brittle. From 2ff6c427b0e1bc8f60581be3481699628fdd8a0b Mon Sep 17 00:00:00 2001 From: Jason Bacchetta Date: Wed, 9 Mar 2016 19:14:00 -0600 Subject: [PATCH 0067/1120] Update README.md Add parentheses around argument, to be consistent with section 8.4 (include parentheses when using braces). --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5368efacf7..603f4f82e3 100644 --- a/README.md +++ b/README.md @@ -874,7 +874,7 @@ Other Style Guides const itemHeight = (item) => item.height > 256 ? item.largeSize : item.smallSize; // good - const itemHeight = item => { return item.height > 256 ? item.largeSize : item.smallSize; } + const itemHeight = (item) => { return item.height > 256 ? item.largeSize : item.smallSize; } ``` **[⬆ back to top](#table-of-contents)** From c38cdd20158ad76030d8a596b67bbc32d7b5494f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 11 Mar 2016 09:29:44 +0100 Subject: [PATCH 0068/1120] Add ascribe's styleguide to the list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 603f4f82e3..d4ed168963 100644 --- a/README.md +++ b/README.md @@ -2637,6 +2637,7 @@ Other Style Guides - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript) - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript) - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript) + - **Ascribe**: [ascribe/javascript](https://github.com/ascribe/javascript) - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript) - **Avant**: [avantcredit/javascript](https://github.com/avantcredit/javascript) - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) From 8fe2f9ed522107e5f22794402342006fa2139aff Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 11 Mar 2016 16:33:31 -0800 Subject: [PATCH 0069/1120] [eslint config] [dev deps] update `eslint`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 0721839841..c4ecc16d43 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,8 +43,8 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.3.0", - "eslint-plugin-react": "^4.2.0", + "eslint": "^2.4.0", + "eslint-plugin-react": "^4.2.1", "react": "^0.14.7", "tape": "^4.5.1", "parallelshell": "^2.0.0" From 6f125a5e85840c08594bfc2a3d1c181282634fc9 Mon Sep 17 00:00:00 2001 From: Tim Cheung Date: Tue, 15 Mar 2016 15:11:28 +0100 Subject: [PATCH 0070/1120] fix react/prefer-stateless-function link --- packages/eslint-config-airbnb/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index bb9374e170..774fad0795 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -174,4 +174,5 @@ [react/jsx-no-bind]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md [react/no-is-mounted]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md [react/prefer-es6-class]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md -[react/jsx-quotes]: https://github.com/yannickcr/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md \ No newline at end of file +[react/jsx-quotes]: https://github.com/yannickcr/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md +[react/prefer-stateless-function]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md From 9eb24d6b61515747f5a67f179ddb3d73ad385121 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 16 Mar 2016 14:47:35 -0700 Subject: [PATCH 0071/1120] [editorial] clean up some constructor examples Fixes #792 --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d4ed168963..09f6f28627 100644 --- a/README.md +++ b/README.md @@ -890,23 +890,23 @@ Other Style Guides ```javascript // bad function Queue(contents = []) { - this._queue = [...contents]; + this.queue = [...contents]; } Queue.prototype.pop = function () { - const value = this._queue[0]; - this._queue.splice(0, 1); + const value = this.queue[0]; + this.queue.splice(0, 1); return value; - } + }; // good class Queue { constructor(contents = []) { - this._queue = [...contents]; + this.queue = [...contents]; } pop() { - const value = this._queue[0]; - this._queue.splice(0, 1); + const value = this.queue[0]; + this.queue.splice(0, 1); return value; } } From 5ded256d3fab29b7b3fa42238093b9af632fb32b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 20 Mar 2016 17:23:49 -0700 Subject: [PATCH 0072/1120] [Fix] re-enable `no-confusing-arrow` rule, with `allowParens` option enabled. Per #752, fixes #791. --- packages/eslint-config-airbnb/rules/es6.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index d0b7bbde9f..a26e49d9df 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,7 +30,9 @@ module.exports = { 'no-class-assign': 0, // disallow arrow functions where they could be confused with comparisons // http://eslint.org/docs/rules/no-confusing-arrow - 'no-confusing-arrow': 0, + 'no-confusing-arrow': [2, { + 'allowParens': true, + }], // disallow modifying variables that are declared using const 'no-const-assign': 2, // disallow symbol constructor From f796cfc81f14d80b67f341a436c4c31f3500bcd1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 20 Mar 2016 17:26:15 -0700 Subject: [PATCH 0073/1120] [peer deps] update `eslint`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index c4ecc16d43..ff8adb78c8 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -50,7 +50,7 @@ "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": "^2.2.0", - "eslint-plugin-react": "^4.0.0" + "eslint": "^2.4.0", + "eslint-plugin-react": "^4.2.3" } } From 8db205c4d2309fcf31c2681366bdd35d68c77dff Mon Sep 17 00:00:00 2001 From: Arnav Singh Date: Sun, 20 Mar 2016 22:40:07 -0700 Subject: [PATCH 0074/1120] Fix "object destructuring for multiple return values" example ... to use the same destructured properties in the good and bad code. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09f6f28627..432ef98900 100644 --- a/README.md +++ b/README.md @@ -476,7 +476,7 @@ Other Style Guides } // the caller selects only the data they need - const { left, right } = processInput(input); + const { left, top } = processInput(input); ``` From 94ace27f465bbbdd814bafedbbd3708b8d21b06e Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Wed, 9 Mar 2016 08:59:48 -0800 Subject: [PATCH 0075/1120] Allow arrow functions in JSX props --- packages/eslint-config-airbnb/rules/react.js | 4 ++-- react/README.md | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index a5d0d17de2..470738b769 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -41,8 +41,8 @@ module.exports = { // Prevent usage of .bind() and arrow functions in JSX props // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md 'react/jsx-no-bind': [2, { - 'ignoreRefs': false, - 'allowArrowFunctions': false, + 'ignoreRefs': true, + 'allowArrowFunctions': true, 'allowBind': false, }], // Prevent duplicate props in JSX diff --git a/react/README.md b/react/README.md index 8bab601e12..6eddabcad2 100644 --- a/react/README.md +++ b/react/README.md @@ -274,6 +274,23 @@ ## Methods + - Use arrow functions to close over local variables. + + ```javascript + function ItemList(props) { + return ( +
    + {props.items.map((item, index) => ( + doSomethingWith(item.name, index)} + /> + ))} +
+ ); + } + ``` + - Bind event handlers for the render method in the constructor. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md) > Why? A bind call in the render path creates a brand new function on every single render. From ec898a67e09a5f47b7afdc24dbb5bb3ab0214268 Mon Sep 17 00:00:00 2001 From: Juan Scolari Date: Mon, 21 Mar 2016 20:54:59 -0300 Subject: [PATCH 0076/1120] Add SysGarage to list of organizations --- README.md | 1 + es5/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 432ef98900..6013998b27 100644 --- a/README.md +++ b/README.md @@ -2689,6 +2689,7 @@ Other Style Guides - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - **Springload**: [springload/javascript](https://github.com/springload/javascript) - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript) + - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide) - **Target**: [target/javascript](https://github.com/target/javascript) - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) diff --git a/es5/README.md b/es5/README.md index caaa17b503..b2fa49d9c1 100644 --- a/es5/README.md +++ b/es5/README.md @@ -1672,6 +1672,7 @@ - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/javascript) - **Super**: [SuperJobs/javascript](https://github.com/SuperJobs/javascript) + - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide) - **Target**: [target/javascript](https://github.com/target/javascript) - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) From ff6e1d0d08c129db5876a897ee146ae801178809 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 22 Mar 2016 23:34:59 -0700 Subject: [PATCH 0077/1120] [eslint config] v6.2.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 7 +++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 774fad0795..3968eea84b 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,10 @@ +6.2.0 / 2016-03-22 +================== +- [new] Allow arrow functions in JSX props +- [fix] re-enable `no-confusing-arrow` rule, with `allowParens` option enabled ([#752](https://github.com/airbnb/javascript/issues/752), [#791](https://github.com/airbnb/javascript/issues/791)) +- [dev deps] update `tape`, `eslint`, `eslint-plugin-react` +- [peer deps] update `eslint`, `eslint-plugin-react` + 6.1.0 / 2016-02-22 ================== - [new] enable [`react/prefer-stateless-function`][react/prefer-stateless-function] diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index ff8adb78c8..da5bf3f2fc 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.1.0", + "version": "6.2.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 5ce6fb1eae2b0a948e526d127654b044f34d3b1b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 26 Mar 2016 22:39:17 -0700 Subject: [PATCH 0078/1120] [eslint config] [dev deps] update `eslint`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index da5bf3f2fc..0d059f0c8d 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,8 +43,8 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.4.0", - "eslint-plugin-react": "^4.2.1", + "eslint": "^2.5.3", + "eslint-plugin-react": "^4.2.3", "react": "^0.14.7", "tape": "^4.5.1", "parallelshell": "^2.0.0" From 24565121c1847fbf27d0854a1d2fc9accbbef4df Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 26 Mar 2016 22:42:29 -0700 Subject: [PATCH 0079/1120] [eslint config] [breaking] add `no-duplicate-imports` rule. --- README.md | 21 +++++++++++++++++++++ packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 6013998b27..8233e4916e 100644 --- a/README.md +++ b/README.md @@ -1075,6 +1075,27 @@ Other Style Guides export default es6; ``` + + - [10.4](#modules--no-duplicate-imports) Only import from a path in one place. + eslint: [`no-duplicate-imports`](http://eslint.org/docs/rules/no-duplicate-imports) + > Why? Having multiple lines that import from the same path can make code harder to maintain. + + ```javascript + // bad + import foo from 'foo'; + // … some other imports … // + import { named1, named2 } from 'foo'; + + // good + import foo, { named1, named2 } from 'foo'; + + // good + import foo, { + named1, + named2, + } from 'foo'; + ``` + **[⬆ back to top](#table-of-contents)** ## Iterators and Generators diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index a26e49d9df..78a43b94cd 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -35,6 +35,9 @@ module.exports = { }], // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow importing from the same path more than once + // http://eslint.org/docs/rules/no-duplicate-imports + 'no-duplicate-imports': 2, // disallow symbol constructor // http://eslint.org/docs/rules/no-new-symbol 'no-new-symbol': 2, From 81241b83cf3a95c1560d4080c39bf8b57381656f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 26 Mar 2016 23:11:23 -0700 Subject: [PATCH 0080/1120] [eslint config] [breaking] add `no-useless-escape` rule. --- README.md | 14 ++++++++++++++ .../eslint-config-airbnb/rules/best-practices.js | 3 +++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 8233e4916e..664b24921a 100644 --- a/README.md +++ b/README.md @@ -547,6 +547,20 @@ Other Style Guides - [6.5](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities. + + - [6.6](#strings--escaping) Do not unnecessarily escape characters in strings. eslint: [`no-useless-escape`](http://eslint.org/docs/rules/no-useless-escape) + + > Why? Backslashes harm readability, thus they should only be present when necessary. + + ```javascript + // bad + const foo = '\'this\' \i\s \"quoted\"'; + + // good + const foo = '\'this\' is "quoted"'; + const foo = `'this' is "quoted"`; + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index ff782a5b7a..e9a0026546 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -113,6 +113,9 @@ module.exports = { 'no-unused-labels': 2, // disallow unnecessary .call() and .apply() 'no-useless-call': 0, + // disallow unnecessary string escaping + // http://eslint.org/docs/rules/no-useless-escape + 'no-useless-escape': 2, // disallow use of void operator 'no-void': 0, // disallow usage of configurable warning terms in comments: e.g. todo From 9415b88afd0d21800e6b595828f0526689084f0a Mon Sep 17 00:00:00 2001 From: Saad Quadri Date: Wed, 30 Mar 2016 02:50:21 -0400 Subject: [PATCH 0081/1120] Add missing description for 7.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 664b24921a..064e9f6276 100644 --- a/README.md +++ b/README.md @@ -582,7 +582,7 @@ Other Style Guides ``` - - [7.2](#functions--iife) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) + - [7.2](#functions--iife) Wrap immediately invoked function expressions in parentheses. eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) > Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE. From 5ec8765a28923671a59465901c03a7f997eb861a Mon Sep 17 00:00:00 2001 From: Yarun Luon Date: Thu, 31 Mar 2016 18:17:26 -0700 Subject: [PATCH 0082/1120] Add Chartboost to 'In the Wild' --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 064e9f6276..ff42af3d2c 100644 --- a/README.md +++ b/README.md @@ -2679,6 +2679,7 @@ Other Style Guides - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/) - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript) - **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript) + - **Chartboost**: [ChartBoost/javascript-style-guide](https://github.com/ChartBoost/javascript-style-guide) - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide) - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) From 062929ee5f5ca368b2b36390fc36aed34ed96797 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 1 Apr 2016 14:25:31 -0700 Subject: [PATCH 0083/1120] [eslint config] [breaking] error on debugger statements --- packages/eslint-config-airbnb/rules/errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/errors.js b/packages/eslint-config-airbnb/rules/errors.js index 1c1addf5fa..62594e0c3e 100644 --- a/packages/eslint-config-airbnb/rules/errors.js +++ b/packages/eslint-config-airbnb/rules/errors.js @@ -9,7 +9,7 @@ module.exports = { // disallow control characters in regular expressions 'no-control-regex': 2, // disallow use of debugger - 'no-debugger': 1, + 'no-debugger': 2, // disallow duplicate arguments in functions 'no-dupe-args': 2, // disallow duplicate keys when creating object literals From 5b9f081d1dac5240f60313784de316c9a63fde62 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 2 Apr 2016 17:46:24 -0700 Subject: [PATCH 0084/1120] [eslint config] [deps] update `eslint`, `react` --- packages/eslint-config-airbnb/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 0d059f0c8d..aefe9a76a6 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,14 +43,14 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.5.3", + "eslint": "^2.6.0", "eslint-plugin-react": "^4.2.3", - "react": "^0.14.7", + "react": "^0.14.8", "tape": "^4.5.1", "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": "^2.4.0", + "eslint": "^2.6.0", "eslint-plugin-react": "^4.2.3" } } From 76e1e4c1de263948f9c35bf43c4de526b17bebb9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 2 Apr 2016 18:08:27 -0700 Subject: [PATCH 0085/1120] [eslint config] [breaking] Add `no-dupe-class-members` rule + section. Closes #785. --- README.md | 30 +++++++++++++++++++--- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ff42af3d2c..03c422d931 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Other Style Guides 1. [Strings](#strings) 1. [Functions](#functions) 1. [Arrow Functions](#arrow-functions) - 1. [Constructors](#constructors) + 1. [Classes & Constructors](#constructors) 1. [Modules](#modules) 1. [Iterators and Generators](#iterators-and-generators) 1. [Properties](#properties) @@ -894,7 +894,7 @@ Other Style Guides **[⬆ back to top](#table-of-contents)** -## Constructors +## Classes & Constructors - [9.1](#constructors--use-class) Always use `class`. Avoid manipulating `prototype` directly. @@ -1008,7 +1008,7 @@ Other Style Guides ``` - - [9.5](#constructors--no-useless) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) + - [9.5](#constructors--no-useless) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. eslint: [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) ```javascript // bad @@ -1036,6 +1036,30 @@ Other Style Guides } ``` + + - [9.6](#classes--no-duplicate-members) Avoid duplicate class members. eslint: [`no-dupe-class-members`](http://eslint.org/docs/rules/no-dupe-class-members) + + > Why? Duplicate class member declarations will silently prefer the last one - having duplicates is almost certainly a bug. + + ```javascript + // bad + class Foo { + bar() { return 1; } + bar() { return 2; } + } + + // good + class Foo { + bar() { return 1; } + } + + // good + class Foo { + bar() { return 2; } + } + ``` + + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 78a43b94cd..a826da8d0e 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -35,6 +35,9 @@ module.exports = { }], // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow duplicate class members + // http://eslint.org/docs/rules/no-dupe-class-members + 'no-dupe-class-members': 2, // disallow importing from the same path more than once // http://eslint.org/docs/rules/no-duplicate-imports 'no-duplicate-imports': 2, From 6671a55556e09b9f70924e9fd63e76c9e079fa5e Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 3 Apr 2016 09:59:12 -0400 Subject: [PATCH 0086/1120] CHORE - Remove Trailing Spaces --- linters/SublimeLinter/SublimeLinter.sublime-settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index 12360f3f1c..259dbaff6a 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -63,7 +63,7 @@ // Warn when variables are defined but never used. "unused": true, - + // Enforce line length to 80 characters "maxlen": 80, From f21412cba916e4af18cd1594a6b6d18ef4ebc341 Mon Sep 17 00:00:00 2001 From: Amin Date: Mon, 4 Apr 2016 11:39:47 +0400 Subject: [PATCH 0087/1120] Broken link to Classes and constructors --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03c422d931..3034aa4c24 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Other Style Guides 1. [Strings](#strings) 1. [Functions](#functions) 1. [Arrow Functions](#arrow-functions) - 1. [Classes & Constructors](#constructors) + 1. [Classes & Constructors](#classes--constructors) 1. [Modules](#modules) 1. [Iterators and Generators](#iterators-and-generators) 1. [Properties](#properties) From a2bdbb83d15e8d35fa40a14b888ad1eee029c7df Mon Sep 17 00:00:00 2001 From: Peter Kuiper Date: Mon, 4 Apr 2016 14:20:17 +0200 Subject: [PATCH 0088/1120] Add KickorStick to 'In the Wild' --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3034aa4c24..5384d7dc9f 100644 --- a/README.md +++ b/README.md @@ -2727,6 +2727,7 @@ Other Style Guides - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions) - **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md) - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript) + - **KickorStick**: [kickorstick/javascript](https://github.com/kickorstick/javascript) - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide) - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript) - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript) From 6e770062bb84aa054ff939c1b805cbb12e9195a1 Mon Sep 17 00:00:00 2001 From: Kevin Moot Date: Mon, 4 Apr 2016 19:07:35 -0500 Subject: [PATCH 0089/1120] Adding The Nerdery to the "In the Wild" section --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5384d7dc9f..ec1dca2cc5 100644 --- a/README.md +++ b/README.md @@ -2753,6 +2753,7 @@ Other Style Guides - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide) - **Target**: [target/javascript](https://github.com/target/javascript) - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) + - **The Nerdery**: [thenerdery/javascript-standards](https://github.com/thenerdery/javascript-standards) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide) - **WeBox Studio**: [weboxstudio/javascript](https://github.com/weboxstudio/javascript) From acbddc1083d5ea7608fba212bb6898ca6e224afc Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:14:03 -0700 Subject: [PATCH 0090/1120] Add note and rule about image alt text We want our React apps to be accessible. One thing that developers can do is properly use alt text on images. Thankfully, there is an ESLint rule that will enforce these things for us. --- packages/eslint-config-airbnb/package.json | 2 ++ packages/eslint-config-airbnb/rules/react.js | 5 +++++ .../test/test-react-order.js | 4 ++-- react/README.md | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index aefe9a76a6..769c8950a3 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -44,6 +44,7 @@ "devDependencies": { "babel-tape-runner": "^1.3.1", "eslint": "^2.6.0", + "eslint-plugin-jsx-a11y": "^0.6.0", "eslint-plugin-react": "^4.2.3", "react": "^0.14.8", "tape": "^4.5.1", @@ -51,6 +52,7 @@ }, "peerDependencies": { "eslint": "^2.6.0", + "eslint-plugin-jsx-a11y": "^0.6.0", "eslint-plugin-react": "^4.2.3" } } diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 470738b769..0b128aef63 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -1,5 +1,6 @@ module.exports = { 'plugins': [ + 'jsx-a11y', 'react' ], 'ecmaFeatures': { @@ -8,6 +9,10 @@ module.exports = { // View link below for react rules documentation // https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules 'rules': { + // Require to have a non-empty `alt` prop, or role="presentation" + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md + 'jsx-a11y/img-uses-alt': 2, + // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 'react/display-name': [0, { 'ignoreTranspilerName': false }], diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index f5b2d452fe..81d8235fce 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -28,9 +28,9 @@ ${body} } test('validate react prop order', t => { - t.test('make sure our eslintrc has React linting dependencies', t => { + t.test('make sure our eslintrc has React and JSX linting dependencies', t => { t.plan(1); - t.equal(reactRules.plugins[0], 'react', 'uses eslint-plugin-react'); + t.deepEqual(reactRules.plugins, ['jsx-a11y', 'react']); }); t.test('passes a good component', t => { diff --git a/react/README.md b/react/README.md index 6eddabcad2..29af5cf806 100644 --- a/react/README.md +++ b/react/README.md @@ -217,6 +217,22 @@ /> ``` + - Always include a non-empty `alt` prop on `` tags. If `alt` is an empty string, the `` must have `role="presentation"`. eslint: [`jsx-a11y/img-uses-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md) + + ```javascript + // bad + + + // bad + + + // good + Me waving hello + + // good + + ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From f2aca29ed95dbec65590660e5e0032a00808cf4a Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:21:48 -0700 Subject: [PATCH 0091/1120] Add note and rule about redundant alt text Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text. This will give people using assistive technologies a smoother experience. --- packages/eslint-config-airbnb/rules/react.js | 4 ++++ react/README.md | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 0b128aef63..f505c75ba1 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -13,6 +13,10 @@ module.exports = { // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md 'jsx-a11y/img-uses-alt': 2, + // Prevent img alt text from containing redundant words like "image", "picture", or "photo" + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/redundant-alt.md + 'jsx-a11y/redundant-alt': 2, + // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 'react/display-name': [0, { 'ignoreTranspilerName': false }], diff --git a/react/README.md b/react/README.md index 29af5cf806..bc149b0908 100644 --- a/react/README.md +++ b/react/README.md @@ -233,6 +233,18 @@ ``` + - Do not use words like "image", "photo", or "picture" in `` `alt` props. eslint: [`jsx-a11y/redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md) + + > Why? Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text. + + ```javascript + // bad + Picture of me waving hello + + // good + Me waving hello + ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From 0c3b13fe93e880450305e6c87a1a59f14e042bc5 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:27:21 -0700 Subject: [PATCH 0092/1120] Add note and rule about valid, non-abstract ARIA roles This rule will help people use only valid roles, which might save people from simple, accessibility-busting mistakes. --- packages/eslint-config-airbnb/rules/react.js | 4 ++++ react/README.md | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index f505c75ba1..02794495b1 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -17,6 +17,10 @@ module.exports = { // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/redundant-alt.md 'jsx-a11y/redundant-alt': 2, + // Require ARIA roles to be valid and non-abstract + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/valid-aria-role.md + 'jsx-a11y/valid-aria-role': 2, + // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 'react/display-name': [0, { 'ignoreTranspilerName': false }], diff --git a/react/README.md b/react/README.md index bc149b0908..0ac01a5b6f 100644 --- a/react/README.md +++ b/react/README.md @@ -245,6 +245,19 @@ Me waving hello ``` + - Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/roles#role_definitions). eslint: [`jsx-a11y/valid-aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/valid-aria-role.md) + + ```javascript + // bad - not an ARIA role +
+ + // bad - abstract ARIA role +
+ + // good +
+ ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From f697a15e5036932805cb7a5160b6c0ceb2401afe Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:32:55 -0700 Subject: [PATCH 0093/1120] Add note and rule about not using accessKey Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility. --- packages/eslint-config-airbnb/rules/react.js | 4 ++++ react/README.md | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 02794495b1..3c05265b06 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -9,6 +9,10 @@ module.exports = { // View link below for react rules documentation // https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules 'rules': { + // Prevent use of `accessKey` + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md + 'jsx-a11y/no-access-key': 2, + // Require to have a non-empty `alt` prop, or role="presentation" // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md 'jsx-a11y/img-uses-alt': 2, diff --git a/react/README.md b/react/README.md index 0ac01a5b6f..4fc7c7c783 100644 --- a/react/README.md +++ b/react/README.md @@ -249,15 +249,27 @@ ```javascript // bad - not an ARIA role -
+
// bad - abstract ARIA role -
+
// good -
+
``` + - Do not use `accessKey` on elements. eslint: [`jsx-a11y/no-access-key`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md) + + > Why? Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility. + + ```javascript + // bad +
+ + // good +
+ ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From 3f73e35b1874128161a97acbc6a299a801ec077b Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:34:21 -0700 Subject: [PATCH 0094/1120] Use jsx fenced codeblocks for JSX code GitHub knows how to do JSX syntax highlighting. Since we are using JSX in this document, I figured we might as well tell GitHub to highlight the syntax as JSX here. This will lead to a better reading experience. --- react/README.md | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/react/README.md b/react/README.md index 4fc7c7c783..6db60dd18a 100644 --- a/react/README.md +++ b/react/README.md @@ -29,7 +29,7 @@ - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) - ```javascript + ```jsx // bad const Listing = React.createClass({ // ... @@ -49,8 +49,7 @@ And if you don't have state or refs, prefer normal functions (not arrow functions) over classes: - ```javascript - + ```jsx // bad class Listing extends React.Component { render() { @@ -75,7 +74,7 @@ - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`. - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) - ```javascript + ```jsx // bad import reservationCard from './ReservationCard'; @@ -91,7 +90,7 @@ - **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name: - ```javascript + ```jsx // bad import Footer from './Footer/Footer'; @@ -106,7 +105,7 @@ - Do not use `displayName` for naming components. Instead, name the component by reference. - ```javascript + ```jsx // bad export default React.createClass({ displayName: 'ReservationCard', @@ -122,7 +121,7 @@ - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) - ```javascript + ```jsx // bad @@ -152,7 +151,7 @@ > Why? JSX attributes [can't contain escaped quotes](http://eslint.org/docs/rules/jsx-quotes), so double quotes make conjunctions like `"don't"` easier to type. > Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention. - ```javascript + ```jsx // bad @@ -170,7 +169,7 @@ - Always include a single space in your self-closing tag. - ```javascript + ```jsx // bad @@ -189,7 +188,7 @@ - Always use camelCase for prop names. - ```javascript + ```jsx // bad