From 5fd7c6f08c0650ed67297fc83c8a0590c9a92cc8 Mon Sep 17 00:00:00 2001 From: Estelle Date: Mon, 23 Mar 2015 18:48:19 -0700 Subject: [PATCH 001/408] 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 262b07b106bdb83f476c77923340aa9c679da9a2 Mon Sep 17 00:00:00 2001 From: Ben Fortner Date: Tue, 16 Jan 2018 09:55:54 -0500 Subject: [PATCH 002/408] fix example to meet standard listingId v listingID fixed code example to meet the standard. `listingId` changed to `listingID` See - Naming Conventions: Acronyms and initialisms should always be all capitalized, or all lowercased. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ae1aaf8a3b..d6f4836fa5 100644 --- a/README.md +++ b/README.md @@ -3178,8 +3178,8 @@ Other Style Guides // ... - $(this).on('listingUpdated', (e, listingId) => { - // do something with listingId + $(this).on('listingUpdated', (e, listingID) => { + // do something with listingID }); ``` @@ -3187,12 +3187,12 @@ Other Style Guides ```javascript // good - $(this).trigger('listingUpdated', { listingId: listing.id }); + $(this).trigger('listingUpdated', { listingID: listing.id }); // ... $(this).on('listingUpdated', (e, data) => { - // do something with data.listingId + // do something with data.listingID }); ``` From 7b1ced2bf79cfe119ab1b7becd096b88b9250ee7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 20 Jan 2018 23:35:21 -0800 Subject: [PATCH 003/408] [eslint config] [base] [deps] update `eslint` --- .../eslint-config-airbnb-base/package.json | 4 ++-- .../eslint-config-airbnb-base/rules/style.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 83565bbac0..5d4cd5ccc5 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -51,7 +51,7 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.15.0", + "eslint": "^4.16.0", "eslint-find-rules": "^3.1.1", "eslint-plugin-import": "^2.8.0", "in-publish": "^2.0.0", @@ -59,7 +59,7 @@ "tape": "^4.8.0" }, "peerDependencies": { - "eslint": "^4.15.0", + "eslint": "^4.16.0", "eslint-plugin-import": "^2.8.0" }, "engines": { diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index 5566ce7076..81ee87a4fc 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -51,7 +51,21 @@ module.exports = { 'comma-spacing': ['error', { before: false, after: true }], // enforce one true comma style - 'comma-style': ['error', 'last'], + 'comma-style': ['error', 'last', { + exceptions: { + ArrayExpression: false, + ArrayPattern: false, + ArrowFunctionExpression: false, + CallExpression: false, + FunctionDeclaration: false, + FunctionExpression: false, + ImportDeclaration: false, + ObjectExpression: false, + ObjectPattern: false, + VariableDeclaration: false, + NewExpression: false, + } + }], // disallow padding inside computed properties 'computed-property-spacing': ['error', 'never'], @@ -375,7 +389,7 @@ module.exports = { // enforce "same line" or "multiple line" on object properties. // https://eslint.org/docs/rules/object-property-newline 'object-property-newline': ['error', { - allowMultiplePropertiesPerLine: true, + allowAllPropertiesOnSameLine: true, }], // allow just one var statement per function From 7dab8371c9302cb4c228e652d376a6c2d66db4a3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 20 Jan 2018 23:36:32 -0800 Subject: [PATCH 004/408] [eslint config] [deps] update `eslint` --- 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 17664483ac..7fd3a288fc 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -54,7 +54,7 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.15.0", + "eslint": "^4.16.0", "eslint-find-rules": "^3.1.1", "eslint-plugin-import": "^2.8.0", "eslint-plugin-jsx-a11y": "^6.0.3", @@ -65,9 +65,9 @@ "tape": "^4.8.0" }, "peerDependencies": { - "eslint": "^4.15.0", + "eslint": "^4.16.0", "eslint-plugin-import": "^2.8.0", - "eslint-plugin-jsx-a11y": "^6.0.2", + "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.4.0" }, "engines": { From c4dcfd93a732c950004c500b8696a50412d8ad82 Mon Sep 17 00:00:00 2001 From: zwei Date: Tue, 16 Jan 2018 16:20:46 +0800 Subject: [PATCH 005/408] [guide] fix indentation in section 4.7 --- README.md | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index d6f4836fa5..7e5a491ba5 100644 --- a/README.md +++ b/README.md @@ -441,39 +441,39 @@ Other Style Guides - [4.7](#arrays--bracket-newline) Use line breaks after open and before close array brackets if an array has multiple lines - ```javascript - // bad - const arr = [ - [0, 1], [2, 3], [4, 5], - ]; - - const objectInArray = [{ - id: 1, - }, { - id: 2, - }]; - - const numberInArray = [ - 1, 2, - ]; - - // good - const arr = [[0, 1], [2, 3], [4, 5]]; - - const objectInArray = [ - { + ```javascript + // bad + const arr = [ + [0, 1], [2, 3], [4, 5], + ]; + + const objectInArray = [{ id: 1, - }, - { + }, { id: 2, - }, - ]; - - const numberInArray = [ - 1, - 2, - ]; - ``` + }]; + + const numberInArray = [ + 1, 2, + ]; + + // good + const arr = [[0, 1], [2, 3], [4, 5]]; + + const objectInArray = [ + { + id: 1, + }, + { + id: 2, + }, + ]; + + const numberInArray = [ + 1, + 2, + ]; + ``` **[⬆ back to top](#table-of-contents)** From 53b2d7d245ba4abefc0429bfda4a46f099b9ace5 Mon Sep 17 00:00:00 2001 From: Alex Baulch Date: Mon, 22 Jan 2018 10:42:28 +0000 Subject: [PATCH 006/408] [eslint config] [breaking] bump react pragma to v16; update `class-methods-use-this`'s `exceptMethods` to include `componentDidCatch` --- packages/eslint-config-airbnb/rules/react.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 8bf726bed6..999d3a1cbb 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -29,6 +29,7 @@ module.exports = { 'componentWillUpdate', 'componentDidUpdate', 'componentWillUnmount', + 'componentDidCatch', ], }], @@ -363,7 +364,7 @@ module.exports = { }, react: { pragma: 'React', - version: '15.0' + version: '16.0' }, propWrapperFunctions: [ 'forbidExtraProps', // https://www.npmjs.com/package/airbnb-prop-types From e9fff7adbf6dd4e3723c12849c407aafd429cf0f Mon Sep 17 00:00:00 2001 From: Sharmila Date: Fri, 26 Jan 2018 10:57:21 -0800 Subject: [PATCH 007/408] [eslint config] [base] [breaking] Prevent line breaks before and after `=` --- README.md | 22 +++++++++++++++++++ .../eslint-config-airbnb-base/rules/style.js | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e5a491ba5..e3410a172e 100644 --- a/README.md +++ b/README.md @@ -1699,6 +1699,28 @@ Other Style Guides const truthyCount = array.filter(Boolean).length; ``` + - [13.7](#variables--linebreak) Avoid linebreaks before or after `=` in an assignment. If your assignment violates [`max-len`](https://eslint.org/docs/rules/max-len.html), surround the value in parens. eslint [`operator-linebreak`](https://eslint.org/docs/rules/operator-linebreak.html). + + > Why? Linebreaks surrounding `=` can obfuscate the value of an assignment. + + ```javascript + // bad + const foo = + superLongLongLongLongLongLongLongLongFunctionName(); + + // bad + const foo + = 'superLongLongLongLongLongLongLongLongString'; + + // good + const foo = ( + superLongLongLongLongLongLongLongLongFunctionName() + ); + + // good + const foo = 'superLongLongLongLongLongLongLongLongString'; + ``` + **[⬆ back to top](#table-of-contents)** ## Hoisting diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index 81ee87a4fc..bc5e032e4a 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -405,7 +405,7 @@ module.exports = { // Requires operator at the beginning of the line in multiline statements // https://eslint.org/docs/rules/operator-linebreak - 'operator-linebreak': ['error', 'before'], + 'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }], // disallow padding within blocks 'padded-blocks': ['error', { blocks: 'never', classes: 'never', switches: 'never' }], From fc99aefc4c4ca7b66ef665b35a898a0c83ae2b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Fri, 26 Jan 2018 13:16:39 -0500 Subject: [PATCH 008/408] [guide] Use `acc` as `reduce` accumulator instead of `memo` to make it valid In [this part of the `no-param-reassign` configuration](https://github.com/airbnb/javascript/blob/53b2d7d245ba4abefc0429bfda4a46f099b9ace5/packages/eslint-config-airbnb-base/rules/best-practices.js#L174-L175), `acc` is allowed to be mutated (rule [7.12](https://github.com/airbnb/javascript#functions--mutate-params), but `memo` is not. This causes the [rule 4.6 example](https://github.com/airbnb/javascript#arrays--callback-return) in the README to actually be invalid. --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e3410a172e..609c43f201 100644 --- a/README.md +++ b/README.md @@ -404,16 +404,16 @@ Other Style Guides // good [1, 2, 3].map(x => x + 1); - // bad - no returned value means `memo` becomes undefined after the first iteration - [[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => { - const flatten = memo.concat(item); - memo[index] = flatten; + // bad - no returned value means `acc` becomes undefined after the first iteration + [[0, 1], [2, 3], [4, 5]].reduce((acc, item, index) => { + const flatten = acc.concat(item); + acc[index] = flatten; }); // good - [[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => { - const flatten = memo.concat(item); - memo[index] = flatten; + [[0, 1], [2, 3], [4, 5]].reduce((acc, item, index) => { + const flatten = acc.concat(item); + acc[index] = flatten; return flatten; }); From 1eefaed4fbb8ff469a864de5dfb652bb04607253 Mon Sep 17 00:00:00 2001 From: Antonio Erdeljac Date: Wed, 10 Jan 2018 09:08:21 +0100 Subject: [PATCH 009/408] [guide] [css] Fixed Italic subtitle in css-in-js README.md --- css-in-javascript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css-in-javascript/README.md b/css-in-javascript/README.md index 2b4d5e489b..d6162df55d 100644 --- a/css-in-javascript/README.md +++ b/css-in-javascript/README.md @@ -1,6 +1,6 @@ # Airbnb CSS-in-JavaScript Style Guide -*A mostly reasonable approach to CSS-in-JavaScript +*A mostly reasonable approach to CSS-in-JavaScript* ## Table of Contents From 17b6491ae2ec5da4f8c3a8d6352840dfa0facc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20O=C4=9Fuzhan=20Y=C4=B1ld=C4=B1z?= Date: Mon, 4 Sep 2017 00:00:04 +0300 Subject: [PATCH 010/408] add Turkish translation --- react/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/react/README.md b/react/README.md index e1133c3754..bf3ed2666c 100644 --- a/react/README.md +++ b/react/README.md @@ -689,6 +689,7 @@ - ![Br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide) - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb/tree/master/react) - ![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/tree/master/react) + - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [alioguzhan/react-style-guide](https://github.com/alioguzhan/react-style-guide) - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript/tree/master/react) **[⬆ back to top](#table-of-contents)** From 9a3e6356cf67b9c6bb6002041d854f1483a4a510 Mon Sep 17 00:00:00 2001 From: David Clark Date: Sun, 28 Jan 2018 00:38:48 -0700 Subject: [PATCH 011/408] Added GreenChef organization to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 609c43f201..a304b078db 100644 --- a/README.md +++ b/README.md @@ -3519,6 +3519,7 @@ Other Style Guides - **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript) - **Generation Tux**: [GenerationTux/javascript](https://github.com/generationtux/styleguide) - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style) + - **GreenChef**: [greenchef/javascript](https://github.com/greenchef/javascript) - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript) - **Grupo-Abraxas**: [Grupo-Abraxas/javascript](https://github.com/Grupo-Abraxas/javascript) - **Honey**: [honeyscience/javascript](https://github.com/honeyscience/javascript) From aefff97bd10e8e17963749bd1013a6927d90fe29 Mon Sep 17 00:00:00 2001 From: ParkSB Date: Tue, 30 Jan 2018 11:49:24 +0900 Subject: [PATCH 012/408] Update Korean translation link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a304b078db..5a6d678f98 100644 --- a/README.md +++ b/README.md @@ -3591,7 +3591,7 @@ Other Style Guides - ![de](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png) **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide) - ![it](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png) **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide) - ![jp](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide) - - ![kr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide) + - ![kr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [ParkSB/javascript-style-guide](https://github.com/ParkSB/javascript-style-guide) - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb) - ![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) From c5411a42d2385762ec879d900dcfdcfc60f54f62 Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Sun, 4 Feb 2018 17:11:01 -0500 Subject: [PATCH 013/408] Suggest using WeakMaps when hidden properties are needed This updates the "trailing or leading underscores" guideline to suggest an better way to make properties hidden, as an alternative to just removing the underscore and making the property public. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5a6d678f98..d070347150 100644 --- a/README.md +++ b/README.md @@ -2993,6 +2993,11 @@ Other Style Guides // good this.firstName = 'Panda'; + + // good, in environments where WeakMaps are available + // see https://kangax.github.io/compat-table/es6/#test-WeakMap + const firstNames = new WeakMap(); + firstNames.set(this, 'Panda'); ``` From 16190d8cb5cb9b8257aec53a04ef3efc25ad9dff Mon Sep 17 00:00:00 2001 From: Ajay Poshak Date: Sun, 4 Feb 2018 18:52:51 +0530 Subject: [PATCH 014/408] Note added for translation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d070347150..ee02c0e97c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ [![Downloads](https://img.shields.io/npm/dm/eslint-config-airbnb-base.svg)](https://www.npmjs.com/package/eslint-config-airbnb-base) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +This guide is available in other languages too. See [Translation](#translation) + Other Style Guides - [ES5 (Deprecated)](https://github.com/airbnb/javascript/tree/es5-deprecated/es5) From c8b1164105064b7786b24258f53f6237fb4bdd15 Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Thu, 8 Feb 2018 13:07:34 -0800 Subject: [PATCH 015/408] control-statement--value-selection 2 --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index ee02c0e97c..556e874c17 100644 --- a/README.md +++ b/README.md @@ -2175,6 +2175,20 @@ Other Style Guides } ``` + + - [17.2](#control-statements--value-selection) Don't use selection operators in place of control statements. + + + ```javascript + // bad + !isRunning && startRunning(); + + // good + if (!isRunning) { + startRunning(); + } + ``` + **[⬆ back to top](#table-of-contents)** ## Comments From 4c870cbd4090016fa36d15f8b2673324c83aabcc Mon Sep 17 00:00:00 2001 From: Kevin Ji Date: Thu, 8 Feb 2018 11:29:44 -0800 Subject: [PATCH 016/408] [guide] Fix function signature spacing --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 556e874c17..ead4903bdb 100644 --- a/README.md +++ b/README.md @@ -2816,7 +2816,7 @@ Other Style Guides // bad - raises exception const reaction = "No! That's impossible!" - (async function meanwhileOnTheFalcon(){ + (async function meanwhileOnTheFalcon() { // handle `leia`, `lando`, `chewie`, `r2`, `c3p0` // ... }()) @@ -2836,7 +2836,7 @@ Other Style Guides // good const reaction = "No! That's impossible!"; - (async function meanwhileOnTheFalcon(){ + (async function meanwhileOnTheFalcon() { // handle `leia`, `lando`, `chewie`, `r2`, `c3p0` // ... }()); From cfe10c17d3f1df7325f8d40a4fcb2486254892f1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 8 Feb 2018 21:45:09 -0800 Subject: [PATCH 017/408] fix linting error in guide --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ead4903bdb..c2840b0b6f 100644 --- a/README.md +++ b/README.md @@ -2178,7 +2178,6 @@ Other Style Guides - [17.2](#control-statements--value-selection) Don't use selection operators in place of control statements. - ```javascript // bad !isRunning && startRunning(); From 901fd85b7cd9386f20a86530f56ec4661b4f18e7 Mon Sep 17 00:00:00 2001 From: Rauno Freiberg Date: Mon, 19 Feb 2018 14:58:24 +0200 Subject: [PATCH 018/408] Use single quotes for consistency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2840b0b6f..b299c9be10 100644 --- a/README.md +++ b/README.md @@ -2162,7 +2162,7 @@ Other Style Guides // good if ( - (foo === 123 || bar === "abc") + (foo === 123 || bar === 'abc') && doesItLookGoodWhenItBecomesThatLong() && isThisReallyHappening() ) { From ff1c12178e268d4ee33321b4aab39571739af49d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 26 Jan 2018 23:31:30 -0800 Subject: [PATCH 019/408] [eslint config] [breaking] update `eslint-plugin-react` to `v7.6`; update rule configs --- packages/eslint-config-airbnb/package.json | 4 +- packages/eslint-config-airbnb/rules/react.js | 109 ++++++++++++++++--- 2 files changed, 95 insertions(+), 18 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 7fd3a288fc..0e52b0e0ea 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -58,7 +58,7 @@ "eslint-find-rules": "^3.1.1", "eslint-plugin-import": "^2.8.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.4.0", + "eslint-plugin-react": "^7.6.1", "in-publish": "^2.0.0", "react": ">= 0.13.0", "safe-publish-latest": "^1.1.1", @@ -68,7 +68,7 @@ "eslint": "^4.16.0", "eslint-plugin-import": "^2.8.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.4.0" + "eslint-plugin-react": "^7.6.1" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 999d3a1cbb..6332546b26 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -38,8 +38,16 @@ module.exports = { 'react/display-name': ['off', { 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': ['error', { forbid: ['any', 'array', 'object'] }], + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/forbid-prop-types.md + 'react/forbid-prop-types': ['error', { + forbid: ['any', 'array', 'object'], + checkContextTypes: true, + checkChildContextTypes: true, + }], + + // Forbid certain props on DOM Nodes + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/forbid-dom-props.md + 'react/forbid-dom-props': ['off', { forbid: [] }], // Enforce boolean attributes notation in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md @@ -109,6 +117,7 @@ module.exports = { ignoreCase: true, callbacksLast: false, requiredFirst: false, + sortShapeProp: true, }], // Deprecated in favor of react/jsx-sort-props @@ -125,6 +134,12 @@ module.exports = { reservedFirst: true, }], + // Enforce defaultProps declarations alphabetical sorting + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-sort-default-props.md + 'react/jsx-sort-default-props': ['off', { + ignoreCase: true, + }], + // Prevent React to be incorrectly marked as unused // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md 'react/jsx-uses-react': ['error'], @@ -207,28 +222,59 @@ module.exports = { 'react/self-closing-comp': 'error', // Enforce component methods order - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/sort-comp.md 'react/sort-comp': ['error', { order: [ 'static-methods', + 'instance-variables', 'lifecycle', '/^on.+$/', 'getters', 'setters', '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', + 'instance-methods', 'everything-else', - '/^render.+$/', - 'render' + 'rendering', ], + groups: { + lifecycle: [ + 'displayName', + 'propTypes', + 'contextTypes', + 'childContextTypes', + 'mixins', + 'statics', + 'defaultProps', + 'constructor', + 'getDefaultProps', + 'getInitialState', + 'state', + 'getChildContext', + 'componentWillMount', + 'componentDidMount', + 'componentWillReceiveProps', + 'shouldComponentUpdate', + 'componentWillUpdate', + 'componentDidUpdate', + 'componentWillUnmount', + ], + rendering: [ + '/^render.+$/', + 'render' + ], + }, }], // Prevent missing parentheses around multilines JSX - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-wrap-multilines.md 'react/jsx-wrap-multilines': ['error', { - declaration: true, - assignment: true, - return: true, - arrow: true, + declaration: 'parens-new-line', + assignment: 'parens-new-line', + return: 'parens-new-line', + arrow: 'parens-new-line', + condition: 'parens-new-line', + logical: 'parens-new-line', + prop: 'parens-new-line', }], // Require that the first prop in a JSX element be on a new line when the element is multiline @@ -300,11 +346,12 @@ module.exports = { 'react/no-children-prop': 'error', // Validate whitespace in and around the JSX opening and closing brackets - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-tag-spacing.md 'react/jsx-tag-spacing': ['error', { closingSlash: 'never', beforeSelfClosing: 'always', - afterOpening: 'never' + afterOpening: 'never', + beforeClosing: 'never', }], // Enforce spaces before the closing bracket of self-closing JSX elements @@ -317,8 +364,10 @@ module.exports = { 'react/no-array-index-key': 'error', // Enforce a defaultProps definition for every prop that is not a required prop - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-default-props.md - 'react/require-default-props': 'error', + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/require-default-props.md + 'react/require-default-props': ['error', { + forbidDefaultForRequired: true, + }], // Forbids using non-exported propTypes // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md @@ -341,10 +390,11 @@ module.exports = { 'react/no-unused-state': 'error', // Enforces consistent naming for boolean props - // https://github.com/yannickcr/eslint-plugin-react/blob/73abadb697034b5ccb514d79fb4689836fe61f91/docs/rules/boolean-prop-naming.md + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/boolean-prop-naming.md 'react/boolean-prop-naming': ['off', { propTypeNames: ['bool', 'mutuallyExclusiveTrueProps'], rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+', + message: '', }], // Prevents common casing typos @@ -353,7 +403,34 @@ module.exports = { // Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md - 'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }] + 'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }], + + // One JSX Element Per Line + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-one-expression-per-line.md + 'react/jsx-one-expression-per-line': 'error', + + // Enforce consistent usage of destructuring assignment of props, state, and context + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/destructuring-assignment.md + 'react/destructuring-assignment': ['error', 'always'], + + // Prevent using this.state within a this.setState + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-access-state-in-setstate.md + 'react/no-access-state-in-setstate': 'error', + + // Prevent usage of button elements without an explicit type attribute + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/button-has-type.md + 'react/button-has-type': ['error', { + button: true, + submit: true, + reset: false, + }], + + // Ensures inline tags are not rendered without spaces between them + 'react/jsx-child-element-spacing': 'off', + + // Prevent this from being used in stateless functional components + // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-this-in-sfc.md + 'react/no-this-in-sfc': 'error', }, settings: { From 3c3074e502dc9ebc7dbdad372df474e49f52d512 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 20 Feb 2018 00:10:46 -0800 Subject: [PATCH 020/408] [eslint config] [*] [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-react`, `tape` --- packages/eslint-config-airbnb-base/package.json | 6 +++--- packages/eslint-config-airbnb/package.json | 12 ++++++------ packages/eslint-config-airbnb/rules/react.js | 7 ++++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 5d4cd5ccc5..a3d13d59f0 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -51,12 +51,12 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.16.0", - "eslint-find-rules": "^3.1.1", + "eslint": "^4.18.0", + "eslint-find-rules": "^3.2.0", "eslint-plugin-import": "^2.8.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", - "tape": "^4.8.0" + "tape": "^4.9.0" }, "peerDependencies": { "eslint": "^4.16.0", diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 0e52b0e0ea..66c0b8294c 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -54,21 +54,21 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.16.0", - "eslint-find-rules": "^3.1.1", + "eslint": "^4.18.0", + "eslint-find-rules": "^3.2.0", "eslint-plugin-import": "^2.8.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.6.1", + "eslint-plugin-react": "^7.7.0", "in-publish": "^2.0.0", "react": ">= 0.13.0", "safe-publish-latest": "^1.1.1", - "tape": "^4.8.0" + "tape": "^4.9.0" }, "peerDependencies": { - "eslint": "^4.16.0", + "eslint": "^4.18.0", "eslint-plugin-import": "^2.8.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.6.1" + "eslint-plugin-react": "^7.7.0" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 6332546b26..7d8145a17a 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -371,7 +371,8 @@ module.exports = { // Forbids using non-exported propTypes // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md - 'react/forbid-foreign-prop-types': 'off', + // TODO: enable? + 'react/forbid-foreign-prop-types': ['off', { allowInPropTypes: true }], // Prevent void DOM elements from receiving children // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/void-dom-elements-no-children.md @@ -431,6 +432,10 @@ module.exports = { // Prevent this from being used in stateless functional components // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-this-in-sfc.md 'react/no-this-in-sfc': 'error', + + // Validate JSX maximum depth + // https://github.com/yannickcr/eslint-plugin-react/blob/abe8381c0d6748047224c430ce47f02e40160ed0/docs/rules/jsx-max-depth.md + 'react/jsx-max-depth': 'off', }, settings: { From a7a7cab504576b32157edaf92c8d4613fc235c54 Mon Sep 17 00:00:00 2001 From: Song Xie Date: Wed, 21 Feb 2018 14:44:58 -0800 Subject: [PATCH 021/408] [guide] Add an anchor for rule 13.7 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b299c9be10..881eb01490 100644 --- a/README.md +++ b/README.md @@ -1701,6 +1701,7 @@ Other Style Guides const truthyCount = array.filter(Boolean).length; ``` + - [13.7](#variables--linebreak) Avoid linebreaks before or after `=` in an assignment. If your assignment violates [`max-len`](https://eslint.org/docs/rules/max-len.html), surround the value in parens. eslint [`operator-linebreak`](https://eslint.org/docs/rules/operator-linebreak.html). > Why? Linebreaks surrounding `=` can obfuscate the value of an assignment. From ea14bda1101abc2971c86b663fa7eed6bd4e6be8 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Thu, 22 Feb 2018 15:48:50 +0100 Subject: [PATCH 022/408] Add licenses to sub packages --- packages/eslint-config-airbnb-base/LICENSE.md | 21 +++++++++++++++++++ packages/eslint-config-airbnb/LICENSE.md | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 packages/eslint-config-airbnb-base/LICENSE.md create mode 100644 packages/eslint-config-airbnb/LICENSE.md diff --git a/packages/eslint-config-airbnb-base/LICENSE.md b/packages/eslint-config-airbnb-base/LICENSE.md new file mode 100644 index 0000000000..69d80c0252 --- /dev/null +++ b/packages/eslint-config-airbnb-base/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012 Airbnb + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/eslint-config-airbnb/LICENSE.md b/packages/eslint-config-airbnb/LICENSE.md new file mode 100644 index 0000000000..69d80c0252 --- /dev/null +++ b/packages/eslint-config-airbnb/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012 Airbnb + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From fd68fdbd2270021eaf0fcc6e4a4f66c261b5b0da Mon Sep 17 00:00:00 2001 From: Rauno Freiberg Date: Tue, 20 Feb 2018 19:28:52 +0200 Subject: [PATCH 023/408] [guide] [react] add comment about what JS standards are followed Seen a few pull requests for the React style guide that try to introduce features that aren't yet in stage >= 3 (static class fields for i.e), so I've decided to add a comment to the beginning of the guide. Not sure if this is the right place to put it, but here it is. This disclaimer might help: 1) give the community an idea what standards this guide is based on 2) prevent redundant pull requests --- react/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/react/README.md b/react/README.md index bf3ed2666c..0db1fa8d3d 100644 --- a/react/README.md +++ b/react/README.md @@ -2,6 +2,8 @@ *A mostly reasonable approach to React and JSX* +This style guide is mostly based on the standards that are currently prevalent in JavaScript, although some conventions (i.e async/await or static class fields) may still be included or prohibited on a case-by-case basis. Currently, anything prior to stage 3 is not included nor recommended in this guide. + ## Table of Contents 1. [Basic Rules](#basic-rules) From 1fbeabd0c4b5d6ece9b7b966aa594854c6da9930 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 22 Feb 2018 13:51:02 -0800 Subject: [PATCH 024/408] [eslint config] [*] [breaking] [deps] update `eslint`, `eslint-plugin-import` --- .../eslint-config-airbnb-base/package.json | 8 ++++---- .../rules/imports.js | 20 +++++++++++++++++++ packages/eslint-config-airbnb/package.json | 8 ++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index a3d13d59f0..f74a57d8e2 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -51,16 +51,16 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.18.0", + "eslint": "^4.18.1", "eslint-find-rules": "^3.2.0", - "eslint-plugin-import": "^2.8.0", + "eslint-plugin-import": "^2.9.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", "tape": "^4.9.0" }, "peerDependencies": { - "eslint": "^4.16.0", - "eslint-plugin-import": "^2.8.0" + "eslint": "^4.18.1", + "eslint-plugin-import": "^2.9.0" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 9536e9b4a4..88f704a996 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -211,5 +211,25 @@ module.exports = { // https://github.com/benmosher/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md // TODO: enable? 'import/exports-last': 'off', + + // Reports when named exports are not grouped together in a single export declaration + // or when multiple assignments to CommonJS module.exports or exports object are present + // in a single file. + // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md + 'import/group-exports': 'off', + + // forbid default exports. this is a terrible rule, do not use it. + // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md + 'import/no-default-export': 'off', + + // Forbid a module from importing itself + // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md + // TODO: enable + 'import/no-self-import': 'off', + + // Ensures that there are no useless path segments + // https://github.com/benmosher/eslint-plugin-import/issues/1032 + // TODO: enable + 'import/no-useless-path-segments': 'off', }, }; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 66c0b8294c..b67dd57cdb 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -54,9 +54,9 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.18.0", + "eslint": "^4.18.1", "eslint-find-rules": "^3.2.0", - "eslint-plugin-import": "^2.8.0", + "eslint-plugin-import": "^2.9.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0", "in-publish": "^2.0.0", @@ -65,8 +65,8 @@ "tape": "^4.9.0" }, "peerDependencies": { - "eslint": "^4.18.0", - "eslint-plugin-import": "^2.8.0", + "eslint": "^4.18.1", + "eslint-plugin-import": "^2.9.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0" }, From c82500d7fa65e199d3df0ce52783a058fb6f4683 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 22 Feb 2018 01:07:09 +0000 Subject: [PATCH 025/408] [eslint config] [base] [breaking] enable `no-useless-path-segments` --- packages/eslint-config-airbnb-base/rules/imports.js | 3 +-- packages/eslint-config-airbnb-base/test/test-base.js | 2 +- packages/eslint-config-airbnb/test/test-react-order.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 88f704a996..005656e6f8 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -229,7 +229,6 @@ module.exports = { // Ensures that there are no useless path segments // https://github.com/benmosher/eslint-plugin-import/issues/1032 - // TODO: enable - 'import/no-useless-path-segments': 'off', + 'import/no-useless-path-segments': 'error', }, }; diff --git a/packages/eslint-config-airbnb-base/test/test-base.js b/packages/eslint-config-airbnb-base/test/test-base.js index 01b5dd12d3..f907581502 100644 --- a/packages/eslint-config-airbnb-base/test/test-base.js +++ b/packages/eslint-config-airbnb-base/test/test-base.js @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; import test from 'tape'; -import index from '../'; +import index from '..'; const files = { ...{ index } }; // object spread is to test parsing diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index b28792a6d5..2527f04e19 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -1,6 +1,6 @@ import test from 'tape'; import { CLIEngine } from 'eslint'; -import eslintrc from '../'; +import eslintrc from '..'; import reactRules from '../rules/react'; import reactA11yRules from '../rules/react-a11y'; From 6373dab9901a29105712ec040006f2352a318dd6 Mon Sep 17 00:00:00 2001 From: Sharmila Date: Wed, 21 Feb 2018 20:18:56 -0800 Subject: [PATCH 026/408] Adds config entry point with only whitespace rules enabled Adds a change to eslint-config-airbnb and eslint-config-airbnb-base to pull a list of rules from the project root and return a config with all rules turned off except the whitespace rules explicitly listed in the array. Also adds entry point data to readme. --- packages/eslint-config-airbnb-base/README.md | 4 + .../eslint-config-airbnb-base/package.json | 3 +- .../eslint-config-airbnb-base/whitespace.js | 73 ++++++++++++++++ packages/eslint-config-airbnb/README.md | 4 + packages/eslint-config-airbnb/package.json | 3 +- packages/eslint-config-airbnb/whitespace.js | 87 +++++++++++++++++++ 6 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 packages/eslint-config-airbnb-base/whitespace.js create mode 100644 packages/eslint-config-airbnb/whitespace.js diff --git a/packages/eslint-config-airbnb-base/README.md b/packages/eslint-config-airbnb-base/README.md index 686ccb06e8..fa0152eb04 100644 --- a/packages/eslint-config-airbnb-base/README.md +++ b/packages/eslint-config-airbnb-base/README.md @@ -84,6 +84,10 @@ Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`. See [Airbnb's overarching ESLint config](https://npmjs.com/eslint-config-airbnb), [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript), and the [ESlint config docs](https://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information. +### eslint-config-airbnb-base/whitespace + +This entry point that only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/whitespace.js). + ## Improving this config Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc? diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index f74a57d8e2..6dd7461c8e 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -66,6 +66,7 @@ "node": ">= 4" }, "dependencies": { - "eslint-restricted-globals": "^0.1.1" + "eslint-restricted-globals": "^0.1.1", + "object.entries": "^1.0.4" } } diff --git a/packages/eslint-config-airbnb-base/whitespace.js b/packages/eslint-config-airbnb-base/whitespace.js new file mode 100644 index 0000000000..408c0b72b6 --- /dev/null +++ b/packages/eslint-config-airbnb-base/whitespace.js @@ -0,0 +1,73 @@ +const baseConfig = require('.'); +const entries = require('object.entries'); +const { CLIEngine } = require('eslint'); + +function onlyErrorOnRules(rulesToError, config) { + const errorsOnly = { ...config }; + const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); + const baseRules = cli.getConfigForFile('./').rules; + + entries(baseRules).forEach(([key, value]) => { + if (rulesToError.indexOf(key) === -1) { + if (Array.isArray(value)) { + errorsOnly.rules[key] = ['warn'].concat(value.slice(1)); + } else if (typeof value === 'number') { + errorsOnly.rules[key] = 1; + } else { + errorsOnly.rules[key] = 'warn'; + } + } + }); + + return errorsOnly; +} + +module.exports = onlyErrorOnRules([ + 'array-bracket-newline', + 'array-bracket-spacing', + 'array-element-newline', + 'arrow-spacing', + 'block-spacing', + 'comma-spacing', + 'computed-property-spacing', + 'dot-location', + 'eol-last', + 'func-call-spacing', + 'function-paren-newline', + 'generator-star-spacing', + 'implicit-arrow-linebreak', + 'indent', + 'key-spacing', + 'keyword-spacing', + 'line-comment-position', + 'linebreak-style', + 'multiline-ternary', + 'newline-per-chained-call', + 'no-irregular-whitespace', + 'no-mixed-spaces-and-tabs', + 'no-multi-spaces', + 'no-regex-spaces', + 'no-spaced-func', + 'no-trailing-spaces', + 'no-whitespace-before-property', + 'nonblock-statement-body-position', + 'object-curly-newline', + 'object-curly-spacing', + 'object-property-newline', + 'one-var-declaration-per-line', + 'operator-linebreak', + 'padded-blocks', + 'padding-line-between-statements', + 'rest-spread-spacing', + 'semi-spacing', + 'semi-style', + 'space-before-blocks', + 'space-before-function-paren', + 'space-in-parens', + 'space-infix-ops', + 'space-unary-ops', + 'spaced-comment', + 'switch-colon-spacing', + 'template-tag-spacing', + 'import/newline-after-import', +], baseConfig); diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index 88e6c80d23..2f341ec187 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -55,6 +55,10 @@ If you use yarn, run `npm info "eslint-config-airbnb@latest" peerDependencies` t 2. Add `"extends": "airbnb"` to your .eslintrc +### eslint-config-airbnb/whitespace + +This entry point that only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/whitespace.js). + ### eslint-config-airbnb/base This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base). diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index b67dd57cdb..9dc6c92a45 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -48,7 +48,8 @@ }, "homepage": "https://github.com/airbnb/javascript", "dependencies": { - "eslint-config-airbnb-base": "^12.1.0" + "eslint-config-airbnb-base": "^12.1.0", + "object.entries": "^1.0.4" }, "devDependencies": { "babel-preset-airbnb": "^2.4.0", diff --git a/packages/eslint-config-airbnb/whitespace.js b/packages/eslint-config-airbnb/whitespace.js new file mode 100644 index 0000000000..f533385e80 --- /dev/null +++ b/packages/eslint-config-airbnb/whitespace.js @@ -0,0 +1,87 @@ +const baseConfig = require('.'); +const entries = require('object.entries'); +const { CLIEngine } = require('eslint'); + +function onlyErrorOnRules(rulesToError, config) { + const errorsOnly = { ...config }; + const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); + const baseRules = cli.getConfigForFile('./').rules; + + entries(baseRules).forEach(([key, value]) => { + if (rulesToError.indexOf(key) === -1) { + if (Array.isArray(value)) { + errorsOnly.rules[key] = ['warn'].concat(value.slice(1)); + } else if (typeof value === 'number') { + errorsOnly.rules[key] = 1; + } else { + errorsOnly.rules[key] = 'warn'; + } + } + }); + + return errorsOnly; +} + +module.exports = onlyErrorOnRules([ + 'array-bracket-newline', + 'array-bracket-spacing', + 'array-element-newline', + 'arrow-spacing', + 'block-spacing', + 'comma-spacing', + 'computed-property-spacing', + 'dot-location', + 'eol-last', + 'func-call-spacing', + 'function-paren-newline', + 'generator-star-spacing', + 'implicit-arrow-linebreak', + 'indent', + 'key-spacing', + 'keyword-spacing', + 'line-comment-position', + 'linebreak-style', + 'multiline-ternary', + 'newline-per-chained-call', + 'no-irregular-whitespace', + 'no-mixed-spaces-and-tabs', + 'no-multi-spaces', + 'no-regex-spaces', + 'no-spaced-func', + 'no-trailing-spaces', + 'no-whitespace-before-property', + 'nonblock-statement-body-position', + 'object-curly-newline', + 'object-curly-spacing', + 'object-property-newline', + 'one-var-declaration-per-line', + 'operator-linebreak', + 'padded-blocks', + 'padding-line-between-statements', + 'rest-spread-spacing', + 'semi-spacing', + 'semi-style', + 'space-before-blocks', + 'space-before-function-paren', + 'space-in-parens', + 'space-infix-ops', + 'space-unary-ops', + 'spaced-comment', + 'switch-colon-spacing', + 'template-tag-spacing', + 'import/newline-after-import', + // eslint-plugin-react rules + 'react/jsx-child-element-spacing', + 'react/jsx-closing-bracket-location', + 'react/jsx-closing-tag-location', + 'react/jsx-curly-spacing', + 'react/jsx-equals-spacing', + 'react/jsx-first-prop-newline', + 'react/jsx-indent', + 'react/jsx-indent-props', + 'react/jsx-max-props-per-line', + 'react/jsx-one-expression-per-line', + 'react/jsx-space-before-closing', + 'react/jsx-tag-spacing', + 'react/jsx-wrap-multilines', +], baseConfig); From 40dbeace170d3cf309e857dd9a9caa092d6aac2c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 28 Feb 2018 23:00:19 -0800 Subject: [PATCH 027/408] [Tests] ensure all entry points parse --- packages/eslint-config-airbnb-base/package.json | 1 + .../eslint-config-airbnb-base/test/requires.js | 16 ++++++++++++++++ packages/eslint-config-airbnb/package.json | 1 + packages/eslint-config-airbnb/test/requires.js | 17 +++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 packages/eslint-config-airbnb-base/test/requires.js create mode 100644 packages/eslint-config-airbnb/test/requires.js diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 6dd7461c8e..608046874c 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -6,6 +6,7 @@ "scripts": { "prelint": "editorconfig-tools check * rules/* test/*", "lint": "eslint --report-unused-disable-directives .", + "pretests-only": "node ./test/requires", "tests-only": "babel-tape-runner ./test/test-*.js", "prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test) && safe-publish-latest", "pretest": "npm run --silent lint", diff --git a/packages/eslint-config-airbnb-base/test/requires.js b/packages/eslint-config-airbnb-base/test/requires.js new file mode 100644 index 0000000000..180a09bf42 --- /dev/null +++ b/packages/eslint-config-airbnb-base/test/requires.js @@ -0,0 +1,16 @@ +/* eslint + strict: 0, + global-require: 0, + */ + +'use strict'; + +const test = require('tape'); + +test('all entry points parse', (t) => { + t.doesNotThrow(() => require('..'), 'index does not throw'); + t.doesNotThrow(() => require('../legacy'), 'legacy does not throw'); + t.doesNotThrow(() => require('../whitespace'), 'whitespace does not throw'); + + t.end(); +}); diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 9dc6c92a45..54e9883cc5 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -6,6 +6,7 @@ "scripts": { "prelint": "editorconfig-tools check * rules/* test/*", "lint": "eslint .", + "pretests-only": "node ./test/requires", "tests-only": "babel-tape-runner ./test/test-*.js", "prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test) && safe-publish-latest", "pretest": "npm run --silent lint", diff --git a/packages/eslint-config-airbnb/test/requires.js b/packages/eslint-config-airbnb/test/requires.js new file mode 100644 index 0000000000..0ab4aae58d --- /dev/null +++ b/packages/eslint-config-airbnb/test/requires.js @@ -0,0 +1,17 @@ +/* eslint + strict: 0, + global-require: 0, + */ + +'use strict'; + +const test = require('tape'); + +test('all entry points parse', (t) => { + t.doesNotThrow(() => require('..'), 'index does not throw'); + t.doesNotThrow(() => require('../base'), 'base does not throw'); + t.doesNotThrow(() => require('../legacy'), 'legacy does not throw'); + t.doesNotThrow(() => require('../whitespace'), 'whitespace does not throw'); + + t.end(); +}); From 396166b1d3266c3bd4c9a83a8f3142c7bcc58865 Mon Sep 17 00:00:00 2001 From: Pirasis <1pete@users.noreply.github.com> Date: Thu, 1 Mar 2018 12:15:56 +0700 Subject: [PATCH 028/408] [eslint config] [*] [fix] ensure `whitespace` entry point is compatible with node 4 --- packages/eslint-config-airbnb-base/.eslintrc | 4 +++- .../eslint-config-airbnb-base/package.json | 1 + .../eslint-config-airbnb-base/whitespace.js | 22 +++++++++++-------- packages/eslint-config-airbnb/.eslintrc | 6 +++-- packages/eslint-config-airbnb/package.json | 1 + packages/eslint-config-airbnb/whitespace.js | 22 +++++++++++-------- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/packages/eslint-config-airbnb-base/.eslintrc b/packages/eslint-config-airbnb-base/.eslintrc index 224149fda6..f9bd289286 100644 --- a/packages/eslint-config-airbnb-base/.eslintrc +++ b/packages/eslint-config-airbnb-base/.eslintrc @@ -3,6 +3,8 @@ "rules": { // disable requiring trailing commas because it might be nice to revert to // being JSON at some point, and I don't want to make big changes now. - "comma-dangle": 0 + "comma-dangle": 0, + // we support node 4 + "prefer-destructuring": 0, }, } diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 608046874c..e9a6589bd0 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -68,6 +68,7 @@ }, "dependencies": { "eslint-restricted-globals": "^0.1.1", + "object.assign": "^4.1.0", "object.entries": "^1.0.4" } } diff --git a/packages/eslint-config-airbnb-base/whitespace.js b/packages/eslint-config-airbnb-base/whitespace.js index 408c0b72b6..66a05e52b9 100644 --- a/packages/eslint-config-airbnb-base/whitespace.js +++ b/packages/eslint-config-airbnb-base/whitespace.js @@ -1,20 +1,24 @@ const baseConfig = require('.'); +const assign = require('object.assign'); const entries = require('object.entries'); -const { CLIEngine } = require('eslint'); +const CLIEngine = require('eslint').CLIEngine; function onlyErrorOnRules(rulesToError, config) { - const errorsOnly = { ...config }; + const errorsOnly = assign({}, config); const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); const baseRules = cli.getConfigForFile('./').rules; - entries(baseRules).forEach(([key, value]) => { - if (rulesToError.indexOf(key) === -1) { - if (Array.isArray(value)) { - errorsOnly.rules[key] = ['warn'].concat(value.slice(1)); - } else if (typeof value === 'number') { - errorsOnly.rules[key] = 1; + entries(baseRules).forEach((rule) => { + const ruleName = rule[0]; + const ruleConfig = rule[1]; + + if (rulesToError.indexOf(ruleName) === -1) { + if (Array.isArray(ruleConfig)) { + errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); + } else if (typeof ruleConfig === 'number') { + errorsOnly.rules[ruleName] = 1; } else { - errorsOnly.rules[key] = 'warn'; + errorsOnly.rules[ruleName] = 'warn'; } } }); diff --git a/packages/eslint-config-airbnb/.eslintrc b/packages/eslint-config-airbnb/.eslintrc index 6c8556be3b..f9bd289286 100644 --- a/packages/eslint-config-airbnb/.eslintrc +++ b/packages/eslint-config-airbnb/.eslintrc @@ -3,6 +3,8 @@ "rules": { // disable requiring trailing commas because it might be nice to revert to // being JSON at some point, and I don't want to make big changes now. - "comma-dangle": 0 - } + "comma-dangle": 0, + // we support node 4 + "prefer-destructuring": 0, + }, } diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 54e9883cc5..df135d545a 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -50,6 +50,7 @@ "homepage": "https://github.com/airbnb/javascript", "dependencies": { "eslint-config-airbnb-base": "^12.1.0", + "object.assign": "^4.1.0", "object.entries": "^1.0.4" }, "devDependencies": { diff --git a/packages/eslint-config-airbnb/whitespace.js b/packages/eslint-config-airbnb/whitespace.js index f533385e80..ba36569a99 100644 --- a/packages/eslint-config-airbnb/whitespace.js +++ b/packages/eslint-config-airbnb/whitespace.js @@ -1,20 +1,24 @@ const baseConfig = require('.'); +const assign = require('object.assign'); const entries = require('object.entries'); -const { CLIEngine } = require('eslint'); +const CLIEngine = require('eslint').CLIEngine; function onlyErrorOnRules(rulesToError, config) { - const errorsOnly = { ...config }; + const errorsOnly = assign({}, config); const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); const baseRules = cli.getConfigForFile('./').rules; - entries(baseRules).forEach(([key, value]) => { - if (rulesToError.indexOf(key) === -1) { - if (Array.isArray(value)) { - errorsOnly.rules[key] = ['warn'].concat(value.slice(1)); - } else if (typeof value === 'number') { - errorsOnly.rules[key] = 1; + entries(baseRules).forEach((rule) => { + const ruleName = rule[0]; + const ruleConfig = rule[1]; + + if (rulesToError.indexOf(ruleName) === -1) { + if (Array.isArray(ruleConfig)) { + errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); + } else if (typeof ruleConfig === 'number') { + errorsOnly.rules[ruleName] = 1; } else { - errorsOnly.rules[key] = 'warn'; + errorsOnly.rules[ruleName] = 'warn'; } } }); From a9fc9d8a0f8b606d560bd173af4cdcfa18e86261 Mon Sep 17 00:00:00 2001 From: Rauno Date: Mon, 5 Mar 2018 22:24:19 +0200 Subject: [PATCH 029/408] [docs] [js] add function-paren-newline eslint reference link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 881eb01490..4b9f4f709c 100644 --- a/README.md +++ b/README.md @@ -879,7 +879,7 @@ Other Style Guides ``` - - [7.15](#functions--signature-invocation-indentation) Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself, with a trailing comma on the last item. + - [7.15](#functions--signature-invocation-indentation) Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself, with a trailing comma on the last item. eslint: [`function-paren-newline`](https://eslint.org/docs/rules/function-paren-newline) ```javascript // bad From 55adae99c960be8d4433b8c98b410695f6cea733 Mon Sep 17 00:00:00 2001 From: Michael Altamirano Date: Sat, 10 Mar 2018 17:30:38 -0800 Subject: [PATCH 030/408] [guide] Reflect adoption of jest --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b9f4f709c..2c6c5c6c7d 100644 --- a/README.md +++ b/README.md @@ -3401,7 +3401,7 @@ Other Style Guides - 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. - - We primarily use [`mocha`](https://www.npmjs.com/package/mocha) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules. + - We primarily use [`mocha`](https://www.npmjs.com/package/mocha) and [`jest`](https://www.npmjs.com/package/jest) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules. - 100% test coverage is a good goal to strive for, even if it’s not always practical to reach it. - Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future. From a100a3957ffb11c841dbd74a649cbb9b5a17a2aa Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Thu, 1 Mar 2018 14:33:02 +0100 Subject: [PATCH 031/408] [eslint config] [base] [breaking] Update `object-curly-newline` to match eslint 4.18.0 In eslint v4.18.0 separate settings are introduced for imports and exports for the `object-curly-newline` rule. Without this change, there is different behavior when updating eslint to this version. --- packages/eslint-config-airbnb-base/rules/style.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index bc5e032e4a..12cd60d509 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -383,7 +383,9 @@ module.exports = { // https://eslint.org/docs/rules/object-curly-newline 'object-curly-newline': ['error', { ObjectExpression: { minProperties: 4, multiline: true, consistent: true }, - ObjectPattern: { minProperties: 4, multiline: true, consistent: true } + ObjectPattern: { minProperties: 4, multiline: true, consistent: true }, + ImportDeclaration: { minProperties: 4, multiline: true, consistent: true }, + ExportDeclaration: { minProperties: 4, multiline: true, consistent: true }, }], // enforce "same line" or "multiple line" on object properties. From 8247e338a2d689f2e16010b0db225fbce7760f97 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 4 Dec 2017 10:11:35 +0100 Subject: [PATCH 032/408] [eslint config] [base] [patch] Set import/extensions to ignorePackages This allows to import non-JavaScript files through the main export of a dependency's package.json. The following would trigger an error before, but is fine with the new configuration: ```js import 'roboto-fontface'; ``` --- packages/eslint-config-airbnb-base/rules/imports.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 005656e6f8..4a83126e1b 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -132,7 +132,7 @@ module.exports = { // Ensure consistent use of file extension within the import path // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md - 'import/extensions': ['error', 'always', { + 'import/extensions': ['error', 'ignorePackages', { js: 'never', mjs: 'never', jsx: 'never', From a9f5d519fe7356a60843c2c24aae974f716e6d17 Mon Sep 17 00:00:00 2001 From: Shane Mileham Date: Mon, 12 Mar 2018 11:20:34 -0700 Subject: [PATCH 033/408] Added naming--uppercase section from comment --- README.md | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1116dcb4ba..49f554e2cf 100644 --- a/README.md +++ b/README.md @@ -3140,32 +3140,43 @@ Other Style Guides ``` - - [23.10](#naming--uppercase) Use UPPERCASE for nested object namespacing, global variables, and constants. + - [23.10](#naming--uppercase) You may optionally uppercase a constant only if it (1) is exported, (2) is a `const` (it can not be reassigned), and (3) the programmer can trust it (and its nested properties) to never change. + > Why? This is an additional tool to assist in situations where the programmer would be unsure if a variable might ever change. UPPERCASE_VARIABLES are letting the programmer know that they can trust the variable (and its properties) not to change. + - What about all `const` variables? - This is unnecessary, so uppercasing should not be used for constants within a file. It should be used for exported constants however. + - What about exported objects? - Uppercase at the top level of export (e.g. `EXPORTED_OBJECT.key`) and maintain that all nested properties do not change. ```javascript // bad - const namespace = namespace || {}; + const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file'; - namespace.util.Widget = { - // ...stuff... - } + // bad + export const THING_TO_BE_CHANGED = 'should obviously not be uppercased'; // bad - const apiKey = '44b345234534t455245njkl523452-vbb9'; + export let REASSIGNABLE_VARIABLE = 'do not use let with uppercase variables'; - // good - const NAMESPACE = NAMESPACE || {}; + // --- - NAMESPACE.util.Widget = { - // ...stuff... - } + // allowed but does not supply semantic value + export const apiKey = 'SOMEKEY'; + + // better in most cases + export const API_KEY = 'SOMEKEY'; + + // --- + + // bad - unnecessarily uppercases key while adding no semantic value + export const MAPPING = { + KEY: 'value' + }; // good - const API_KEY = '44b345234534t455245njkl523452-vbb9'; + export const MAPPING = { + key: 'value' + }; ``` - **[⬆ back to top](#table-of-contents)** ## Accessors From 49dab881da79eb3742e7f1e26c754194a9f26991 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Fri, 23 Mar 2018 08:42:42 -0700 Subject: [PATCH 034/408] Change import/no-self-import from "off" to "error" We recently had an incident where this rule would have prevented infinite loops in Hypernova and in the browser. --- packages/eslint-config-airbnb-base/rules/imports.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 4a83126e1b..a34e7f2524 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -224,8 +224,7 @@ module.exports = { // Forbid a module from importing itself // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md - // TODO: enable - 'import/no-self-import': 'off', + 'import/no-self-import': 'error', // Ensures that there are no useless path segments // https://github.com/benmosher/eslint-plugin-import/issues/1032 From 8ed1d855bbefccbb147fe17d902a18c8f9aa3977 Mon Sep 17 00:00:00 2001 From: Naomi Jacobs Date: Tue, 20 Mar 2018 11:40:04 -0700 Subject: [PATCH 035/408] [eslint config] [base] [patch] Include 'accumulator' exception for `no-param-reassign` --- packages/eslint-config-airbnb-base/rules/best-practices.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb-base/rules/best-practices.js b/packages/eslint-config-airbnb-base/rules/best-practices.js index 978cafc698..b5712d00b2 100644 --- a/packages/eslint-config-airbnb-base/rules/best-practices.js +++ b/packages/eslint-config-airbnb-base/rules/best-practices.js @@ -173,6 +173,7 @@ module.exports = { props: true, ignorePropertyModificationsFor: [ 'acc', // for reduce accumulators + 'accumulator', // for reduce accumulators 'e', // for e.returnvalue 'ctx', // for Koa routing 'req', // for Express requests From 06e28997b239a341bcc196905f710f2c437ed8cf Mon Sep 17 00:00:00 2001 From: Simon Owen Date: Wed, 28 Mar 2018 15:39:14 +0100 Subject: [PATCH 036/408] Minor spacing update --- react/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react/README.md b/react/README.md index 0db1fa8d3d..b89bad0710 100644 --- a/react/README.md +++ b/react/README.md @@ -421,13 +421,13 @@ This style guide is mostly based on the standards that are currently prevalent i Filter out unnecessary props when possible. Also, use [prop-types-exact](https://www.npmjs.com/package/prop-types-exact) to help prevent bugs. ```jsx - //good + // good render() { const { irrelevantProp, ...relevantProps } = this.props; return } - //bad + // bad render() { const { irrelevantProp, ...relevantProps } = this.props; return From 31d95fded451b31695d9cc09abc117edcea4969d Mon Sep 17 00:00:00 2001 From: Sharmila Date: Wed, 4 Apr 2018 16:23:02 -0700 Subject: [PATCH 037/408] [eslint config] [*] [deps] update `eslint`, `eslint-plugin-import`, `eslint-find-rules` --- packages/eslint-config-airbnb-base/package.json | 10 +++++----- packages/eslint-config-airbnb-base/rules/imports.js | 5 +++++ packages/eslint-config-airbnb/package.json | 10 +++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index e9a6589bd0..2c3d49bd21 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -52,16 +52,16 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.18.1", - "eslint-find-rules": "^3.2.0", - "eslint-plugin-import": "^2.9.0", + "eslint": "^4.19.1", + "eslint-find-rules": "^3.2.2", + "eslint-plugin-import": "^2.10.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", "tape": "^4.9.0" }, "peerDependencies": { - "eslint": "^4.18.1", - "eslint-plugin-import": "^2.9.0" + "eslint": "^4.19.1", + "eslint-plugin-import": "^2.10.0" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index a34e7f2524..3c76a5aa3d 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -226,6 +226,11 @@ module.exports = { // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md 'import/no-self-import': 'error', + // Forbid cyclical dependencies between modules + // https://github.com/benmosher/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md + // TODO: enable, semver-major + 'import/no-cycle': ['off', { maxDepth: Infinity }], + // Ensures that there are no useless path segments // https://github.com/benmosher/eslint-plugin-import/issues/1032 'import/no-useless-path-segments': 'error', diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index df135d545a..dfaadad2ad 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -57,9 +57,9 @@ "babel-preset-airbnb": "^2.4.0", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.18.1", - "eslint-find-rules": "^3.2.0", - "eslint-plugin-import": "^2.9.0", + "eslint": "^4.19.1", + "eslint-find-rules": "^3.2.2", + "eslint-plugin-import": "^2.10.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0", "in-publish": "^2.0.0", @@ -68,8 +68,8 @@ "tape": "^4.9.0" }, "peerDependencies": { - "eslint": "^4.18.1", - "eslint-plugin-import": "^2.9.0", + "eslint": "^4.19.1", + "eslint-plugin-import": "^2.10.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0" }, From c71e8c9231394ef9489cacf6cbf1ea9dd63b1b32 Mon Sep 17 00:00:00 2001 From: Sharmila Date: Wed, 4 Apr 2018 16:15:27 -0700 Subject: [PATCH 038/408] [eslint config] [base] [breaking] enable `import/no-cycle`: warn on cyclical dependencies --- packages/eslint-config-airbnb-base/rules/imports.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 3c76a5aa3d..1ea95697c9 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -228,8 +228,7 @@ module.exports = { // Forbid cyclical dependencies between modules // https://github.com/benmosher/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md - // TODO: enable, semver-major - 'import/no-cycle': ['off', { maxDepth: Infinity }], + 'import/no-cycle': ['error', { maxDepth: Infinity }], // Ensures that there are no useless path segments // https://github.com/benmosher/eslint-plugin-import/issues/1032 From bd97fca21b99b542d9ef9eebec78198d6bb5fde0 Mon Sep 17 00:00:00 2001 From: Pramod Garg Date: Wed, 4 Apr 2018 22:45:44 +0530 Subject: [PATCH 039/408] [guide] Minor addition of spaces --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49f554e2cf..b0093efe40 100644 --- a/README.md +++ b/README.md @@ -2106,7 +2106,7 @@ Other Style Guides } } - //good + // good function dogs(x) { if (x) { if (z) { @@ -2267,7 +2267,7 @@ Other Style Guides ```javascript // bad - //is current tab + // is current tab const active = true; // good From 8720f5f90bbe4aaf87e03d81b3b4f607f27ff6c6 Mon Sep 17 00:00:00 2001 From: "C. T. Lin" Date: Wed, 28 Mar 2018 13:05:12 +0800 Subject: [PATCH 040/408] [eslint config] [base] [patch] avoid `__mocks__` `no-extraneous-dependencies` check --- packages/eslint-config-airbnb-base/rules/imports.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 1ea95697c9..04455c97fb 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -74,6 +74,7 @@ module.exports = { 'tests/**', // also common npm pattern 'spec/**', // mocha, rspec-like pattern '**/__tests__/**', // jest pattern + '**/__mocks__/**', // jest pattern 'test.{js,jsx}', // repos with a single test file 'test-*.{js,jsx}', // repos with multiple top-level test files '**/*.{test,spec}.{js,jsx}', // tests where the extension denotes that it is a test From 06998522e1f4935f81f732c458d2cc72dde2cac9 Mon Sep 17 00:00:00 2001 From: Hernaldo Jesus Henriquez Date: Fri, 6 Apr 2018 14:53:46 -0300 Subject: [PATCH 041/408] [guide] fix "bad" comment to be actually bad --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b0093efe40..6a58c28480 100644 --- a/README.md +++ b/README.md @@ -2267,7 +2267,7 @@ Other Style Guides ```javascript // bad - // is current tab + //is current tab const active = true; // good From 8956338ee95087ab2da99b368d00ff482e77df3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=87etinay?= Date: Sun, 8 Apr 2018 22:51:19 +0300 Subject: [PATCH 042/408] [guide] Turkish Translation Link Added --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6a58c28480..57ca65ed4e 100644 --- a/README.md +++ b/README.md @@ -3654,6 +3654,7 @@ Other Style Guides - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb) - ![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) + - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [eraycetinay/javascript](https://github.com/eraycetinay/javascript) - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript) - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [hngiang/javascript-style-guide](https://github.com/hngiang/javascript-style-guide) From 6088a8f5b503c4e383552cbb6ae36d3fa4c6e7b1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 12 Apr 2018 15:46:55 -0700 Subject: [PATCH 043/408] [guide] remove references to jscs --- README.md | 71 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 57ca65ed4e..ed54520555 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ Other Style Guides ``` - - [2.2](#references--disallow-var) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](https://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`](https://eslint.org/docs/rules/no-var.html) > Why? `let` is block-scoped rather than function-scoped like `var`. @@ -192,7 +192,7 @@ Other Style Guides ``` - - [3.3](#es6-object-shorthand) Use object method shorthand. eslint: [`object-shorthand`](https://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + - [3.3](#es6-object-shorthand) Use object method shorthand. eslint: [`object-shorthand`](https://eslint.org/docs/rules/object-shorthand.html) ```javascript // bad @@ -215,7 +215,7 @@ Other Style Guides ``` - - [3.4](#es6-object-concise) Use property value shorthand. eslint: [`object-shorthand`](https://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + - [3.4](#es6-object-concise) Use property value shorthand. eslint: [`object-shorthand`](https://eslint.org/docs/rules/object-shorthand.html) > Why? It is shorter to write and descriptive. @@ -264,7 +264,7 @@ Other Style Guides ``` - - [3.6](#objects--quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](https://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) + - [3.6](#objects--quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](https://eslint.org/docs/rules/quote-props.html) > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. @@ -482,7 +482,7 @@ Other Style Guides ## Destructuring - - [5.1](#destructuring--object) Use object destructuring when accessing and using multiple properties of an object. eslint: [`prefer-destructuring`](https://eslint.org/docs/rules/prefer-destructuring) jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) + - [5.1](#destructuring--object) Use object destructuring when accessing and using multiple properties of an object. eslint: [`prefer-destructuring`](https://eslint.org/docs/rules/prefer-destructuring) > Why? Destructuring saves you from creating temporary references for those properties. @@ -508,7 +508,7 @@ Other Style Guides ``` - - [5.2](#destructuring--array) Use array destructuring. eslint: [`prefer-destructuring`](https://eslint.org/docs/rules/prefer-destructuring) jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) + - [5.2](#destructuring--array) Use array destructuring. eslint: [`prefer-destructuring`](https://eslint.org/docs/rules/prefer-destructuring) ```javascript const arr = [1, 2, 3, 4]; @@ -522,7 +522,7 @@ Other Style Guides ``` - - [5.3](#destructuring--object-over-array) 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. > Why? You can add new properties over time or change the order of things without breaking call sites. @@ -551,7 +551,7 @@ Other Style Guides ## Strings - - [6.1](#strings--quotes) Use single quotes `''` for strings. eslint: [`quotes`](https://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) + - [6.1](#strings--quotes) Use single quotes `''` for strings. eslint: [`quotes`](https://eslint.org/docs/rules/quotes.html) ```javascript // bad @@ -586,7 +586,7 @@ Other Style Guides ``` - - [6.3](#es6-template-literals) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](https://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](https://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) + - [6.3](#es6-template-literals) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](https://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](https://eslint.org/docs/rules/template-curly-spacing) > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. @@ -634,7 +634,7 @@ Other Style Guides ## Functions - - [7.1](#functions--declarations) Use named function expressions instead of function declarations. eslint: [`func-style`](https://eslint.org/docs/rules/func-style) jscs: [`disallowFunctionDeclarations`](http://jscs.info/rule/disallowFunctionDeclarations) + - [7.1](#functions--declarations) Use named function expressions instead of function declarations. eslint: [`func-style`](https://eslint.org/docs/rules/func-style) > Why? Function declarations are hoisted, which means that it’s easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function’s definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it’s time to extract it to its own module! Don’t forget to explicitly name the expression, regardless of whether or not the name is inferred from the containing variable (which is often the case in modern browsers or when using compilers such as Babel). This eliminates any assumptions made about the Error's call stack. ([Discussion](https://github.com/airbnb/javascript/issues/794)) @@ -657,7 +657,7 @@ Other Style Guides ``` - - [7.2](#functions--iife) Wrap immediately invoked function expressions in parentheses. eslint: [`wrap-iife`](https://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`](https://eslint.org/docs/rules/wrap-iife.html) > 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. @@ -916,7 +916,7 @@ Other Style Guides ## Arrow Functions - - [8.1](#arrows--use-them) When you must use an anonymous function (as when passing an inline callback), use arrow function notation. eslint: [`prefer-arrow-callback`](https://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](https://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) + - [8.1](#arrows--use-them) When you must use an anonymous function (as when passing an inline callback), use arrow function notation. eslint: [`prefer-arrow-callback`](https://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](https://eslint.org/docs/rules/arrow-spacing.html) > 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. @@ -937,7 +937,7 @@ Other Style Guides ``` - - [8.2](#arrows--implicit-return) If the function body consists of a single statement returning an [expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions) without side effects, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](https://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 statement returning an [expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions) without side effects, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](https://eslint.org/docs/rules/arrow-body-style.html) > Why? Syntactic sugar. It reads well when multiple functions are chained together. @@ -1004,7 +1004,7 @@ Other Style Guides ``` - - [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 for clarity and consistency. Note: it is also acceptable to always use parentheses, in which case use the [“always” option](https://eslint.org/docs/rules/arrow-parens#always) for eslint or do not include [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) for jscs. eslint: [`arrow-parens`](https://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 for clarity and consistency. Note: it is also acceptable to always use parentheses, in which case use the [“always” option](https://eslint.org/docs/rules/arrow-parens#always) for eslint. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html) > Why? Less visual clutter. @@ -1491,7 +1491,7 @@ Other Style Guides ## Properties - - [12.1](#properties--dot) Use dot notation when accessing properties. eslint: [`dot-notation`](https://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`](https://eslint.org/docs/rules/dot-notation.html) ```javascript const luke = { @@ -1548,7 +1548,7 @@ Other Style Guides ``` - - [13.2](#variables--one-const) Use one `const` or `let` declaration per variable. eslint: [`one-var`](https://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) + - [13.2](#variables--one-const) Use one `const` or `let` declaration per variable. eslint: [`one-var`](https://eslint.org/docs/rules/one-var.html) > 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. @@ -2032,7 +2032,7 @@ Other Style Guides ``` - - [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`](https://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`](https://eslint.org/docs/rules/brace-style.html) ```javascript // bad @@ -2335,7 +2335,7 @@ Other Style Guides ## Whitespace - - [19.1](#whitespace--spaces) Use soft tabs (space character) set to 2 spaces. eslint: [`indent`](https://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) + - [19.1](#whitespace--spaces) Use soft tabs (space character) set to 2 spaces. eslint: [`indent`](https://eslint.org/docs/rules/indent.html) ```javascript // bad @@ -2355,7 +2355,7 @@ Other Style Guides ``` - - [19.2](#whitespace--before-blocks) Place 1 space before the leading brace. eslint: [`space-before-blocks`](https://eslint.org/docs/rules/space-before-blocks.html) jscs: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements) + - [19.2](#whitespace--before-blocks) Place 1 space before the leading brace. eslint: [`space-before-blocks`](https://eslint.org/docs/rules/space-before-blocks.html) ```javascript // bad @@ -2382,7 +2382,7 @@ Other Style Guides ``` - - [19.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: [`keyword-spacing`](https://eslint.org/docs/rules/keyword-spacing.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) + - [19.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: [`keyword-spacing`](https://eslint.org/docs/rules/keyword-spacing.html) ```javascript // bad @@ -2407,7 +2407,7 @@ Other Style Guides ``` - - [19.4](#whitespace--infix-ops) Set off operators with spaces. eslint: [`space-infix-ops`](https://eslint.org/docs/rules/space-infix-ops.html) jscs: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) + - [19.4](#whitespace--infix-ops) Set off operators with spaces. eslint: [`space-infix-ops`](https://eslint.org/docs/rules/space-infix-ops.html) ```javascript // bad @@ -2487,7 +2487,7 @@ Other Style Guides ``` - - [19.7](#whitespace--after-blocks) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) + - [19.7](#whitespace--after-blocks) Leave a blank line after blocks and before the next statement. ```javascript // bad @@ -2545,7 +2545,7 @@ Other Style Guides ``` - - [19.8](#whitespace--padded-blocks) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](https://eslint.org/docs/rules/padded-blocks.html) jscs: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) + - [19.8](#whitespace--padded-blocks) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](https://eslint.org/docs/rules/padded-blocks.html) ```javascript // bad @@ -2586,7 +2586,7 @@ Other Style Guides ``` - - [19.9](#whitespace--in-parens) Do not add spaces inside parentheses. eslint: [`space-in-parens`](https://eslint.org/docs/rules/space-in-parens.html) jscs: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) + - [19.9](#whitespace--in-parens) Do not add spaces inside parentheses. eslint: [`space-in-parens`](https://eslint.org/docs/rules/space-in-parens.html) ```javascript // bad @@ -2611,7 +2611,7 @@ Other Style Guides ``` - - [19.10](#whitespace--in-brackets) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](https://eslint.org/docs/rules/array-bracket-spacing.html) jscs: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets) + - [19.10](#whitespace--in-brackets) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](https://eslint.org/docs/rules/array-bracket-spacing.html) ```javascript // bad @@ -2624,7 +2624,7 @@ Other Style Guides ``` - - [19.11](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](https://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`requireSpacesInsideObjectBrackets`](http://jscs.info/rule/requireSpacesInsideObjectBrackets) + - [19.11](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](https://eslint.org/docs/rules/object-curly-spacing.html) ```javascript // bad @@ -2635,7 +2635,7 @@ Other Style Guides ``` - - [19.12](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per [above](#strings--line-length), long strings are exempt from this rule, and should not be broken up. eslint: [`max-len`](https://eslint.org/docs/rules/max-len.html) jscs: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) + - [19.12](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per [above](#strings--line-length), long strings are exempt from this rule, and should not be broken up. eslint: [`max-len`](https://eslint.org/docs/rules/max-len.html) > Why? This ensures readability and maintainability. @@ -2669,7 +2669,7 @@ Other Style Guides ## Commas - - [20.1](#commas--leading-trailing) Leading commas: **Nope.** eslint: [`comma-style`](https://eslint.org/docs/rules/comma-style.html) jscs: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) + - [20.1](#commas--leading-trailing) Leading commas: **Nope.** eslint: [`comma-style`](https://eslint.org/docs/rules/comma-style.html) ```javascript // bad @@ -2704,7 +2704,7 @@ Other Style Guides ``` - - [20.2](#commas--dangling) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](https://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) + - [20.2](#commas--dangling) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](https://eslint.org/docs/rules/comma-dangle.html) > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don’t have to worry about the [trailing comma problem](https://github.com/airbnb/javascript/blob/es5-deprecated/es5/README.md#commas) in legacy browsers. @@ -2804,7 +2804,7 @@ Other Style Guides ## Semicolons - - [21.1](#semicolons--required) **Yup.** eslint: [`semi`](https://eslint.org/docs/rules/semi.html) jscs: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) + - [21.1](#semicolons--required) **Yup.** eslint: [`semi`](https://eslint.org/docs/rules/semi.html) > Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called [Automatic Semicolon Insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion) to determine whether or not it should regard that line break as the end of a statement, and (as the name implies) place a semicolon into your code before the line break if it thinks so. ASI contains a few eccentric behaviors, though, and your code will break if JavaScript misinterprets your line break. These rules will become more complicated as new features become a part of JavaScript. Explicitly terminating your statements and configuring your linter to catch missing semicolons will help prevent you from encountering issues. @@ -2958,7 +2958,7 @@ Other Style Guides ``` - - [23.2](#naming--camelCase) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](https://eslint.org/docs/rules/camelcase.html) jscs: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) + - [23.2](#naming--camelCase) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](https://eslint.org/docs/rules/camelcase.html) ```javascript // bad @@ -2972,7 +2972,7 @@ Other Style Guides ``` - - [23.3](#naming--PascalCase) Use PascalCase only when naming constructors or classes. eslint: [`new-cap`](https://eslint.org/docs/rules/new-cap.html) jscs: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) + - [23.3](#naming--PascalCase) Use PascalCase only when naming constructors or classes. eslint: [`new-cap`](https://eslint.org/docs/rules/new-cap.html) ```javascript // bad @@ -2997,7 +2997,7 @@ Other Style Guides ``` - - [23.4](#naming--leading-underscore) Do not use trailing or leading underscores. eslint: [`no-underscore-dangle`](https://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) + - [23.4](#naming--leading-underscore) Do not use trailing or leading underscores. eslint: [`no-underscore-dangle`](https://eslint.org/docs/rules/no-underscore-dangle.html) > Why? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean “private”, in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won’t count as breaking, or that tests aren’t needed. tl;dr: if you want something to be “private”, it must not be observably present. @@ -3017,7 +3017,7 @@ Other Style Guides ``` - - [23.5](#naming--self-this) Don’t save references to `this`. Use arrow functions or [Function#bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) + - [23.5](#naming--self-this) Don’t save references to `this`. Use arrow functions or [Function#bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). ```javascript // bad @@ -3282,7 +3282,7 @@ Other Style Guides ## jQuery - - [26.1](#jquery--dollar-prefix) Prefix jQuery object variables with a `$`. jscs: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) + - [26.1](#jquery--dollar-prefix) Prefix jQuery object variables with a `$`. ```javascript // bad @@ -3477,7 +3477,6 @@ Other Style Guides - Code Style Linters - [ESlint](https://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc) - [JSHint](http://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) (Deprecated, please use [ESlint](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base)) - Neutrino preset - [neutrino-preset-airbnb-base](https://neutrino.js.org/presets/neutrino-preset-airbnb-base/) **Other Style Guides** From 308fb24815a62c98aa4e89aae1bad0744dab3a92 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 13 Apr 2018 13:43:43 -0700 Subject: [PATCH 044/408] [eslint config] [*] [deps] update `eslint-plugin-import` --- packages/eslint-config-airbnb-base/package.json | 4 ++-- packages/eslint-config-airbnb/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 2c3d49bd21..7739f54005 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -54,14 +54,14 @@ "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", "eslint-find-rules": "^3.2.2", - "eslint-plugin-import": "^2.10.0", + "eslint-plugin-import": "^2.11.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", "tape": "^4.9.0" }, "peerDependencies": { "eslint": "^4.19.1", - "eslint-plugin-import": "^2.10.0" + "eslint-plugin-import": "^2.11.0" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index dfaadad2ad..bc80fdd060 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -59,7 +59,7 @@ "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", "eslint-find-rules": "^3.2.2", - "eslint-plugin-import": "^2.10.0", + "eslint-plugin-import": "^2.11.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0", "in-publish": "^2.0.0", @@ -69,7 +69,7 @@ }, "peerDependencies": { "eslint": "^4.19.1", - "eslint-plugin-import": "^2.10.0", + "eslint-plugin-import": "^2.11.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0" }, From 87f97e042ddb94d87950be7c483b4aa4e391e2c2 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 18 Apr 2018 11:28:06 -0700 Subject: [PATCH 045/408] Replace flag images with emoji We can use emoji for most of these flags, which should make them look better on higher resolution displays and improve the loading performance of the style guide a little. The only flag we have here that does not have a good emoji yet is the flag of Catalonia, which I left as-is for now. https://emojipedia.org/flag-for-catalonia-esct/ --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ed54520555..3ca74e2606 100644 --- a/README.md +++ b/README.md @@ -3640,22 +3640,22 @@ Other Style Guides This style guide is also available in other languages: - - ![br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide) - - ![bg](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Bulgaria.png) **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript) + - 🇧🇷 **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide) + - 🇧🇬 **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript) - ![ca](https://raw.githubusercontent.com/fpmweb/javascript-style-guide/master/img/catala.png) **Catalan**: [fpmweb/javascript-style-guide](https://github.com/fpmweb/javascript-style-guide) - - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [yuche/javascript](https://github.com/yuche/javascript) - - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript) - - ![fr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/France.png) **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide) - - ![de](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png) **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide) - - ![it](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png) **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide) - - ![jp](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide) - - ![kr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [ParkSB/javascript-style-guide](https://github.com/ParkSB/javascript-style-guide) - - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb) - - ![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) - - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [eraycetinay/javascript](https://github.com/eraycetinay/javascript) - - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript) - - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [hngiang/javascript-style-guide](https://github.com/hngiang/javascript-style-guide) + - 🇨🇳 **Chinese (Simplified)**: [yuche/javascript](https://github.com/yuche/javascript) + - 🇹🇼 **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript) + - 🇫🇷 **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide) + - 🇩🇪 **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide) + - 🇮🇹 **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide) + - 🇯🇵 **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide) + - 🇰🇷 **Korean**: [ParkSB/javascript-style-guide](https://github.com/ParkSB/javascript-style-guide) + - 🇷🇺 **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb) + - 🇪🇸 **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide) + - 🇹🇭 **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide) + - 🇹🇷 **Turkish**: [eraycetinay/javascript](https://github.com/eraycetinay/javascript) + - 🇺🇦 **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript) + - 🇻🇳 **Vietnam**: [hngiang/javascript-style-guide](https://github.com/hngiang/javascript-style-guide) ## The JavaScript Style Guide Guide From b56875bee21eb8d87213c787dc105c288066f43e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 20 Apr 2018 14:00:50 -0700 Subject: [PATCH 046/408] [eslint config] [base] [patch] `function-paren-newline`: change to "consistent" --- packages/eslint-config-airbnb-base/rules/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index 12cd60d509..0f58957211 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -98,7 +98,7 @@ module.exports = { // enforce consistent line breaks inside function parentheses // https://eslint.org/docs/rules/function-paren-newline - 'function-paren-newline': ['error', 'multiline'], + 'function-paren-newline': ['error', 'consistent'], // Blacklist certain identifiers to prevent them being used // https://eslint.org/docs/rules/id-blacklist From fd0834764c8b991a807e6366181c1a3eddba240d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 20 Apr 2018 15:19:14 -0700 Subject: [PATCH 047/408] [eslint config] [base] fix tests --- packages/eslint-config-airbnb-base/test/test-base.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb-base/test/test-base.js b/packages/eslint-config-airbnb-base/test/test-base.js index f907581502..07d17b1027 100644 --- a/packages/eslint-config-airbnb-base/test/test-base.js +++ b/packages/eslint-config-airbnb-base/test/test-base.js @@ -11,9 +11,9 @@ fs.readdirSync(path.join(__dirname, '../rules')).forEach((name) => { files[name] = require(`../rules/${name}`); // eslint-disable-line global-require }); -Object.keys(files).forEach(( // eslint-disable-line function-paren-newline +Object.keys(files).forEach(( name, // trailing function comma is to test parsing -) => { // eslint-disable-line function-paren-newline +) => { const config = files[name]; test(`${name}: does not reference react`, (t) => { From 5705b8ae6b22305cc9dca048e0a4b14db7ce6934 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 22 Apr 2018 14:48:50 -0700 Subject: [PATCH 048/408] Revert "Replace flag images with emoji" This reverts commit 87f97e042ddb94d87950be7c483b4aa4e391e2c2. Closes #1789. --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3ca74e2606..ed54520555 100644 --- a/README.md +++ b/README.md @@ -3640,22 +3640,22 @@ Other Style Guides This style guide is also available in other languages: - - 🇧🇷 **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide) - - 🇧🇬 **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript) + - ![br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide) + - ![bg](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Bulgaria.png) **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript) - ![ca](https://raw.githubusercontent.com/fpmweb/javascript-style-guide/master/img/catala.png) **Catalan**: [fpmweb/javascript-style-guide](https://github.com/fpmweb/javascript-style-guide) - - 🇨🇳 **Chinese (Simplified)**: [yuche/javascript](https://github.com/yuche/javascript) - - 🇹🇼 **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript) - - 🇫🇷 **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide) - - 🇩🇪 **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide) - - 🇮🇹 **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide) - - 🇯🇵 **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide) - - 🇰🇷 **Korean**: [ParkSB/javascript-style-guide](https://github.com/ParkSB/javascript-style-guide) - - 🇷🇺 **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb) - - 🇪🇸 **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide) - - 🇹🇭 **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide) - - 🇹🇷 **Turkish**: [eraycetinay/javascript](https://github.com/eraycetinay/javascript) - - 🇺🇦 **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript) - - 🇻🇳 **Vietnam**: [hngiang/javascript-style-guide](https://github.com/hngiang/javascript-style-guide) + - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [yuche/javascript](https://github.com/yuche/javascript) + - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript) + - ![fr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/France.png) **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide) + - ![de](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png) **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide) + - ![it](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png) **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide) + - ![jp](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide) + - ![kr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [ParkSB/javascript-style-guide](https://github.com/ParkSB/javascript-style-guide) + - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb) + - ![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) + - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [eraycetinay/javascript](https://github.com/eraycetinay/javascript) + - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript) + - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [hngiang/javascript-style-guide](https://github.com/hngiang/javascript-style-guide) ## The JavaScript Style Guide Guide From 2653730fee20e46a1fc6e6c9fd512329d8719fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ti=E1=BA=BFn=20Minh?= Date: Sat, 21 Apr 2018 13:51:56 +0700 Subject: [PATCH 049/408] [react] add vietnamese --- react/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/react/README.md b/react/README.md index b89bad0710..1af23d4d1f 100644 --- a/react/README.md +++ b/react/README.md @@ -693,5 +693,6 @@ This style guide is mostly based on the standards that are currently prevalent i - ![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/tree/master/react) - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [alioguzhan/react-style-guide](https://github.com/alioguzhan/react-style-guide) - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript/tree/master/react) + - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [uetcodecamp/jsx-style-guide](https://github.com/UETCodeCamp/jsx-style-guide) **[⬆ back to top](#table-of-contents)** From 22f01558a08eed9f32ad3b6e963ac71bebd37433 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 25 Apr 2018 20:28:41 -0700 Subject: [PATCH 050/408] Add StandardJS to "Other Style Guides" list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StandardJS is one of the top style guides, though like the Google and jQuery styles, it's less popular than the airbnb style. 😀 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ed54520555..855be914f9 100644 --- a/README.md +++ b/README.md @@ -3484,6 +3484,7 @@ Other Style Guides - [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml) - [jQuery Core Style Guidelines](https://contribute.jquery.org/style-guide/js/) - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js) + - [StandardJS](https://standardjs.com) **Other Styles** From 8c83d03a20d166aba0acefa1358efe6043eacc3e Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Thu, 15 Feb 2018 11:58:17 -0800 Subject: [PATCH 051/408] [eslint config] [base] [patch] Allow devDependencies for foo_spec.js naming style Some projects name test files like `foo_spec.js` instead of `foo.spec.js`. --- packages/eslint-config-airbnb-base/rules/imports.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 04455c97fb..46c6135093 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -77,7 +77,7 @@ module.exports = { '**/__mocks__/**', // jest pattern 'test.{js,jsx}', // repos with a single test file 'test-*.{js,jsx}', // repos with multiple top-level test files - '**/*.{test,spec}.{js,jsx}', // tests where the extension denotes that it is a test + '**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test '**/jest.config.js', // jest config '**/webpack.config.js', // webpack config '**/webpack.config.*.js', // webpack config From 2d9779907f9760472e0318ad11b01f67a9f5dc7e Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 30 Apr 2018 09:30:38 +0100 Subject: [PATCH 052/408] [eslint config] [base] [minor] only allow one newline at the end --- packages/eslint-config-airbnb-base/rules/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index 0f58957211..ca8fc07ae6 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -302,7 +302,7 @@ module.exports = { 'no-multi-assign': ['error'], // disallow multiple empty lines and only one newline at the end - 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }], + 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0 }], // disallow negated conditions // https://eslint.org/docs/rules/no-negated-condition From edf942eeb6bee3ae538e1484861ea0721fad4856 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Wed, 2 May 2018 01:01:19 -0400 Subject: [PATCH 053/408] [guide] Add descriptions of enforced rules This commit adds brief descriptions and examples of rules enforced by the guide that were not previously mentioned in the README. --- README.md | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/README.md b/README.md index 855be914f9..8a2cb4b6fc 100644 --- a/README.md +++ b/README.md @@ -1053,6 +1053,24 @@ Other Style Guides }; ``` + - [8.6](#whitespace--implicit-arrow-linebreak) Enforce the location of arrow function bodies with implicit returns. eslint: [`implicit-arrow-linebreak`](https://eslint.org/docs/rules/implicit-arrow-linebreak) + + ```javascript + // bad + (foo) => + bar; + + (foo) => + (bar); + + // good + (foo) => bar; + (foo) => (bar); + (foo) => ( + bar + ) + ``` + **[⬆ back to top](#table-of-contents)** ## Classes & Constructors @@ -2664,6 +2682,90 @@ Other Style Guides .fail(() => console.log('You have failed this city.')); ``` + - [19.13](#whitespace--block-spacing) Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. eslint: [`block-spacing`](https://eslint.org/docs/rules/block-spacing) + + ```javascript + // bad + function foo() {return true;} + if (foo) { bar = 0;} + + // good + function foo() { return true; } + if (foo) { bar = 0; } + ``` + + - [19.14](#whitespace--comma-spacing) Avoid spaces before commas and require a space after commas. eslint: [`comma-spacing`](https://eslint.org/docs/rules/comma-spacing) + + ```javascript + // bad + var foo = 1,bar = 2; + var arr = [1 , 2]; + + // good + var foo = 1, bar = 2; + var arr = [1, 2]; + ``` + + - [19.15](#whitespace--computed-property-spacing) Avoid spaces before commas and require a space after commas. eslint: [`computed-property-spacing`](https://eslint.org/docs/rules/computed-property-spacing) + + ```javascript + // bad + obj[foo ] + obj[ 'foo'] + var x = {[ b ]: a} + obj[foo[ bar ]] + + // good + obj[foo] + obj['foo'] + var x = { [b]: a } + obj[foo[bar]] + ``` + + - [19.16](#whitespace--func-call-spacing) Enforce spacing between functions and their invocations. eslint: [`func-call-spacing`](https://eslint.org/docs/rules/func-call-spacing) + + ```javascript + // bad + func (); + + func + (); + + // good + func(); + ``` + + - [19.17](#whitespace--key-spacing) Enforce spacing between keys and values in object literal properties. eslint: [`key-spacing`](https://eslint.org/docs/rules/key-spacing) + + ```javascript + // bad + var obj = { "foo" : 42 }; + var obj2 = { "foo":42 }; + + // good + var obj = { "foo": 42 }; + ``` + + - [19.18](#whitespace--no-trailing-spaces) Avoid trailing spaces at the end of lines. eslint: [`no-trailing-spaces`](https://eslint.org/docs/rules/no-trailing-spaces) + + - [19.19](#whitespace--no-multiple-empty-lines) Avoid multiple empty lines and only allow one newline at the end of files. eslint: [`no-multiple-empty-lines`](https://eslint.org/docs/rules/no-multiple-empty-lines) + + + ```javascript + // bad + var x = 1; + + + + var y = 2; + + // good + var x = 1; + + var y = 2; + ``` + + **[⬆ back to top](#table-of-contents)** ## Commas From 71e54f2af8e17c6147f1e8f7baafdbcf86d1d2d9 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Fri, 4 May 2018 11:11:55 +0300 Subject: [PATCH 054/408] doc: fix some nits in README.md * Add missing anchors for section references. * Correct a rule description. --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a2cb4b6fc..8ef84ade85 100644 --- a/README.md +++ b/README.md @@ -1053,6 +1053,7 @@ Other Style Guides }; ``` + - [8.6](#whitespace--implicit-arrow-linebreak) Enforce the location of arrow function bodies with implicit returns. eslint: [`implicit-arrow-linebreak`](https://eslint.org/docs/rules/implicit-arrow-linebreak) ```javascript @@ -2682,6 +2683,7 @@ Other Style Guides .fail(() => console.log('You have failed this city.')); ``` + - [19.13](#whitespace--block-spacing) Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. eslint: [`block-spacing`](https://eslint.org/docs/rules/block-spacing) ```javascript @@ -2694,6 +2696,7 @@ Other Style Guides if (foo) { bar = 0; } ``` + - [19.14](#whitespace--comma-spacing) Avoid spaces before commas and require a space after commas. eslint: [`comma-spacing`](https://eslint.org/docs/rules/comma-spacing) ```javascript @@ -2706,7 +2709,8 @@ Other Style Guides var arr = [1, 2]; ``` - - [19.15](#whitespace--computed-property-spacing) Avoid spaces before commas and require a space after commas. eslint: [`computed-property-spacing`](https://eslint.org/docs/rules/computed-property-spacing) + + - [19.15](#whitespace--computed-property-spacing) Enforce spacing inside of computed properties. eslint: [`computed-property-spacing`](https://eslint.org/docs/rules/computed-property-spacing) ```javascript // bad @@ -2722,6 +2726,7 @@ Other Style Guides obj[foo[bar]] ``` + - [19.16](#whitespace--func-call-spacing) Enforce spacing between functions and their invocations. eslint: [`func-call-spacing`](https://eslint.org/docs/rules/func-call-spacing) ```javascript @@ -2735,6 +2740,7 @@ Other Style Guides func(); ``` + - [19.17](#whitespace--key-spacing) Enforce spacing between keys and values in object literal properties. eslint: [`key-spacing`](https://eslint.org/docs/rules/key-spacing) ```javascript @@ -2746,8 +2752,10 @@ Other Style Guides var obj = { "foo": 42 }; ``` + - [19.18](#whitespace--no-trailing-spaces) Avoid trailing spaces at the end of lines. eslint: [`no-trailing-spaces`](https://eslint.org/docs/rules/no-trailing-spaces) + - [19.19](#whitespace--no-multiple-empty-lines) Avoid multiple empty lines and only allow one newline at the end of files. eslint: [`no-multiple-empty-lines`](https://eslint.org/docs/rules/no-multiple-empty-lines) From 2bd77bc1e0fb6fb17f9601961cd9d5b878623c28 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Sat, 5 May 2018 22:34:19 -0400 Subject: [PATCH 055/408] [eslint config] [base] [patch] `label-has-for`: Remove redundant component Also make the rule configuration more explicit. --- packages/eslint-config-airbnb/rules/react-a11y.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react-a11y.js b/packages/eslint-config-airbnb/rules/react-a11y.js index 3e7f5c970c..f53b3d22f6 100644 --- a/packages/eslint-config-airbnb/rules/react-a11y.js +++ b/packages/eslint-config-airbnb/rules/react-a11y.js @@ -48,7 +48,13 @@ module.exports = { // require that JSX labels use "htmlFor" // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md - 'jsx-a11y/label-has-for': ['error', { components: ['label'] }], + 'jsx-a11y/label-has-for': ['error', { + components: [], + required: { + every: ['nesting', 'id'], + }, + allowChildren: false, + }], // require that mouseover/out come with focus/blur, for keyboard-only users // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md From 2ba36de952fcb6a931471980f4fbbdc4df468baa Mon Sep 17 00:00:00 2001 From: ParkSB Date: Sat, 5 May 2018 03:04:38 +0900 Subject: [PATCH 056/408] [guide] Add backticks --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8ef84ade85..969c65c0e4 100644 --- a/README.md +++ b/README.md @@ -370,7 +370,7 @@ Other Style Guides ``` - - [4.4](#arrays--from) To convert an array-like object to an array, use spreads `...` instead of [Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from). + - [4.4](#arrays--from) To convert an array-like object to an array, use spreads `...` instead of [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from). ```javascript const foo = document.querySelectorAll('.foo'); @@ -786,7 +786,7 @@ Other Style Guides - [7.10](#functions--constructor) Never use the Function constructor to create a new function. eslint: [`no-new-func`](https://eslint.org/docs/rules/no-new-func) - > Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities. + > Why? Creating a function in this way evaluates a string similarly to `eval()`, which opens vulnerabilities. ```javascript // bad @@ -1167,7 +1167,7 @@ Other Style Guides ``` - - [9.4](#constructors--tostring) 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 { @@ -1687,7 +1687,7 @@ Other Style Guides ``` - - [13.6](#variables--unary-increment-decrement) Avoid using unary increments and decrements (++, --). eslint [`no-plusplus`](https://eslint.org/docs/rules/no-plusplus) + - [13.6](#variables--unary-increment-decrement) Avoid using unary increments and decrements (`++`, `--`). eslint [`no-plusplus`](https://eslint.org/docs/rules/no-plusplus) > Why? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with incrementing or decrementing values within an application. It is also more expressive to mutate your values with statements like `num += 1` instead of `num++` or `num ++`. Disallowing unary increment and decrement statements also prevents you from pre-incrementing/pre-decrementing values unintentionally which can also cause unexpected behavior in your programs. @@ -3295,7 +3295,7 @@ Other Style Guides - [24.1](#accessors--not-required) Accessor functions for properties are not required. - - [24.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'). + - [24.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 @@ -3337,7 +3337,7 @@ Other Style Guides ``` - - [24.4](#accessors--consistent) It’s okay to create get() and set() functions, but be consistent. + - [24.4](#accessors--consistent) It’s okay to create `get()` and `set()` functions, but be consistent. ```javascript class Jedi { From c068d7cbf1bfb2f263bc928ca7fd895a6a6add7f Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 26 May 2018 13:38:45 -0700 Subject: [PATCH 057/408] Fix link for Temporal Dead Zone --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 969c65c0e4..0a3a1f88f3 100644 --- a/README.md +++ b/README.md @@ -1748,7 +1748,7 @@ Other Style Guides ## Hoisting - - [14.1](#hoisting--about) `var` declarations get hoisted to the top of their closest enclosing function 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 closest enclosing function 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). 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 From 04ab225858b75b9fb1180075b92845700849ea5b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 27 May 2018 08:47:29 -0700 Subject: [PATCH 058/408] [eslint config] [*] [deps] update `eslint-plugin-import`, `eslint-find-rules`, `eslint-plugin-react` --- packages/eslint-config-airbnb-base/package.json | 6 +++--- packages/eslint-config-airbnb-base/rules/imports.js | 9 ++++++++- packages/eslint-config-airbnb/package.json | 10 +++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 7739f54005..a4b83cda9c 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -53,15 +53,15 @@ "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", - "eslint-find-rules": "^3.2.2", - "eslint-plugin-import": "^2.11.0", + "eslint-find-rules": "^3.2.3", + "eslint-plugin-import": "^2.12.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", "tape": "^4.9.0" }, "peerDependencies": { "eslint": "^4.19.1", - "eslint-plugin-import": "^2.11.0" + "eslint-plugin-import": "^2.12.0" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 46c6135093..a8502d554a 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -232,7 +232,14 @@ module.exports = { 'import/no-cycle': ['error', { maxDepth: Infinity }], // Ensures that there are no useless path segments - // https://github.com/benmosher/eslint-plugin-import/issues/1032 + // https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md 'import/no-useless-path-segments': 'error', + + // dynamic imports require a leading comment with a webpackChunkName + // https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md + 'import/dynamic-import-chunkname': ['off', { + importFunctions: [], + webpackChunknameFormat: '[0-9a-zA-Z-_/.]+', + }], }, }; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index bc80fdd060..d3fc6d8df1 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -58,10 +58,10 @@ "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", - "eslint-find-rules": "^3.2.2", - "eslint-plugin-import": "^2.11.0", + "eslint-find-rules": "^3.2.3", + "eslint-plugin-import": "^2.12.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.7.0", + "eslint-plugin-react": "^7.8.2", "in-publish": "^2.0.0", "react": ">= 0.13.0", "safe-publish-latest": "^1.1.1", @@ -69,9 +69,9 @@ }, "peerDependencies": { "eslint": "^4.19.1", - "eslint-plugin-import": "^2.11.0", + "eslint-plugin-import": "^2.12.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.7.0" + "eslint-plugin-react": "^7.8.2" }, "engines": { "node": ">= 4" From ae82d7678303bd08242299a4a9e2c47717bf9c6b Mon Sep 17 00:00:00 2001 From: Alexandre Syenchuk Date: Wed, 30 May 2018 09:06:14 +0200 Subject: [PATCH 059/408] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0a3a1f88f3..3b00f8c274 100644 --- a/README.md +++ b/README.md @@ -3719,6 +3719,7 @@ Other Style Guides - **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript) - **OutBoxSoft**: [OutBoxSoft/javascript](https://github.com/OutBoxSoft/javascript) - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript) + - **Qotto**: [Qotto/javascript-style-guide](https://github.com/Qotto/javascript-style-guide) - **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.github.io/react/contributing/how-to-contribute.html#style-guide](https://facebook.github.io/react/contributing/how-to-contribute.html#style-guide) From dfc9da71d9ac8669d074cbe0f918b504c8a68be8 Mon Sep 17 00:00:00 2001 From: Andrew Macpherson Date: Thu, 31 May 2018 18:34:17 +0100 Subject: [PATCH 060/408] Add Drupal to In The Wild section. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3b00f8c274..d6e1c5e0ab 100644 --- a/README.md +++ b/README.md @@ -3677,6 +3677,7 @@ Other Style Guides - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) - **DoSomething**: [DoSomething/eslint-config](https://github.com/DoSomething/eslint-config) - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) + - **Drupal**: [www.drupal.org](https://www.drupal.org/project/drupal) - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript) - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide) - **Evolution Gaming**: [evolution-gaming/javascript](https://github.com/evolution-gaming/javascript) From 8a244801196924797878186d744249c78fa4ed37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Garc=C3=ADa=20Salas?= Date: Sun, 3 Jun 2018 10:48:10 -0700 Subject: [PATCH 061/408] Fix broken aria roles link in React style guide README --- react/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index 1af23d4d1f..c4fcf76d56 100644 --- a/react/README.md +++ b/react/README.md @@ -307,7 +307,7 @@ This style guide is mostly based on the standards that are currently prevalent i Me waving hello ``` - - Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/roles#role_definitions). eslint: [`jsx-a11y/aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md) + - Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/#usage_intro). eslint: [`jsx-a11y/aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md) ```jsx // bad - not an ARIA role From 5e260928b65f48c895b21d49ea0aa752df2e4d80 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 3 Jun 2018 22:19:41 -0700 Subject: [PATCH 062/408] [eslint config] [react] update `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- packages/eslint-config-airbnb/rules/react.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index d3fc6d8df1..faee46ec90 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -61,7 +61,7 @@ "eslint-find-rules": "^3.2.3", "eslint-plugin-import": "^2.12.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.8.2", + "eslint-plugin-react": "^7.9.1", "in-publish": "^2.0.0", "react": ">= 0.13.0", "safe-publish-latest": "^1.1.1", @@ -71,7 +71,7 @@ "eslint": "^4.19.1", "eslint-plugin-import": "^2.12.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.8.2" + "eslint-plugin-react": "^7.9.1" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 7d8145a17a..f5a807faac 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -290,8 +290,8 @@ module.exports = { 'react/jsx-indent': ['error', 2], // Disallow target="_blank" on links - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md - 'react/jsx-no-target-blank': 'error', + // https://github.com/yannickcr/eslint-plugin-react/blob/ac102885765be5ff37847a871f239c6703e1c7cc/docs/rules/jsx-no-target-blank.md + 'react/jsx-no-target-blank': ['error', { enforceDynamicLinks: 'always' }], // only .jsx files may have JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md @@ -436,6 +436,10 @@ module.exports = { // Validate JSX maximum depth // https://github.com/yannickcr/eslint-plugin-react/blob/abe8381c0d6748047224c430ce47f02e40160ed0/docs/rules/jsx-max-depth.md 'react/jsx-max-depth': 'off', + + // Disallow multiple spaces between inline JSX props + // https://github.com/yannickcr/eslint-plugin-react/blob/ac102885765be5ff37847a871f239c6703e1c7cc/docs/rules/jsx-props-no-multi-spaces.md + 'react/jsx-props-no-multi-spaces': 'error', }, settings: { From 74fb34f08d4f1961169e9c37c9036a5b42aa7bf1 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Fri, 8 Jun 2018 01:38:03 -0400 Subject: [PATCH 063/408] Add no-unused-vars to README This documents the enforced but currently undocumented `no-unused-vars` rule with a brief description, examples, and noting the `"ignoreRestSiblings": true` option. --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index d6e1c5e0ab..b807154d99 100644 --- a/README.md +++ b/README.md @@ -1743,6 +1743,45 @@ Other Style Guides const foo = 'superLongLongLongLongLongLongLongLongString'; ``` + - [13.8](#variables--no-unused-vars) Disallow unused variables. eslint: [`no-unused-vars`](https://eslint.org/docs/rules/no-unused-vars) + + > Why? Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers. + + ```javascript + // bad + + var some_unused_var = 42; + + // Write-only variables are not considered as used. + var y = 10; + y = 5; + + // A read for a modification of itself is not considered as used. + var z = 0; + z = z + 1; + + // Unused function arguments. + function getX(x, y) { + return x; + } + + // good + + function getXPlusY(x, y) { + return x + y; + } + + var x = 1; + var y = a + 2; + + alert(getXPlusY(x, y)); + + // 'type' is ignored even if unused because it has a rest property sibling. + // This is a form of extracting an object that omits the specified keys. + var { type, ...coords } = data; + // 'coords' is now the 'data' object without its 'type' property. + ``` + **[⬆ back to top](#table-of-contents)** ## Hoisting From 103f5e2a5901392878889ec1f1ad4e59c8d65dc3 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Fri, 8 Jun 2018 19:49:37 +0300 Subject: [PATCH 064/408] doc: add missing anchor in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b807154d99..e486ae170e 100644 --- a/README.md +++ b/README.md @@ -1743,6 +1743,7 @@ Other Style Guides const foo = 'superLongLongLongLongLongLongLongLongString'; ``` + - [13.8](#variables--no-unused-vars) Disallow unused variables. eslint: [`no-unused-vars`](https://eslint.org/docs/rules/no-unused-vars) > Why? Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers. From d270031fc07bd26df9d53106704e04abc37d8256 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Jun 2018 13:28:22 -0700 Subject: [PATCH 065/408] [eslint config] [*] [dev deps] update `babel-preset-airbnb`, `tape` --- packages/eslint-config-airbnb-base/package.json | 4 ++-- packages/eslint-config-airbnb/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index a4b83cda9c..9327414f6c 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -49,7 +49,7 @@ }, "homepage": "https://github.com/airbnb/javascript", "devDependencies": { - "babel-preset-airbnb": "^2.4.0", + "babel-preset-airbnb": "^2.5.1", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", @@ -57,7 +57,7 @@ "eslint-plugin-import": "^2.12.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", - "tape": "^4.9.0" + "tape": "^4.9.1" }, "peerDependencies": { "eslint": "^4.19.1", diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index faee46ec90..95cc0adcf8 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -54,7 +54,7 @@ "object.entries": "^1.0.4" }, "devDependencies": { - "babel-preset-airbnb": "^2.4.0", + "babel-preset-airbnb": "^2.5.1", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", @@ -65,7 +65,7 @@ "in-publish": "^2.0.0", "react": ">= 0.13.0", "safe-publish-latest": "^1.1.1", - "tape": "^4.9.0" + "tape": "^4.9.1" }, "peerDependencies": { "eslint": "^4.19.1", From 2668495fee10b4b70f72ba623b4f319ad539700a Mon Sep 17 00:00:00 2001 From: minimooooz Date: Thu, 12 Oct 2017 11:17:22 +0700 Subject: [PATCH 066/408] add ES2015-2018 in npm package keywords --- package.json | 3 +++ packages/eslint-config-airbnb-base/package.json | 6 +++++- packages/eslint-config-airbnb/package.json | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b50dd7a121..d907751ccc 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,9 @@ "airbnb", "es6", "es2015", + "es2016", + "es2017", + "es2018", "react", "jsx" ], diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 9327414f6c..bd2ef922c3 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -25,7 +25,11 @@ "config", "airbnb", "javascript", - "styleguide" + "styleguide", + "es2015", + "es2016", + "es2017", + "es2018" ], "author": "Jake Teton-Landis (https://twitter.com/@jitl)", "contributors": [ diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 95cc0adcf8..97e1579393 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -25,7 +25,11 @@ "config", "airbnb", "javascript", - "styleguide" + "styleguide", + "es2015", + "es2016", + "es2017", + "es2018" ], "author": "Jake Teton-Landis (https://twitter.com/@jitl)", "contributors": [ From b3bbd1ccbc2495762ed3b2ec47e776135e532d76 Mon Sep 17 00:00:00 2001 From: Josh Wells Date: Wed, 11 Apr 2018 13:46:34 +0100 Subject: [PATCH 067/408] [eslint config] [base] [breaking] order of import statements is ignored for unassigned imports --- packages/eslint-config-airbnb-base/rules/imports.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index a8502d554a..c48959e14f 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -115,7 +115,7 @@ module.exports = { // disallow non-import statements appearing before import statements // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md - 'import/first': ['error', 'absolute-first'], + 'import/first': 'error', // disallow non-import statements appearing before import statements // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md @@ -139,13 +139,10 @@ module.exports = { jsx: 'never', }], - // Enforce a convention in module import order + // ensure absolute imports are above relative imports and that unassigned imports are ignored // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md - // TODO: enable? - 'import/order': ['off', { - groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'], - 'newlines-between': 'never', - }], + // TODO: enforce a stricter convention in module import order? + 'import/order': ['error', { groups: [['builtin', 'external', 'internal']] }], // Require a newline after the last import/require in a group // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md From 068d6b69bf70c83d16eba25c9c517a4859c96ea4 Mon Sep 17 00:00:00 2001 From: Moritz Kneilmann Date: Tue, 15 May 2018 23:54:09 +0200 Subject: [PATCH 068/408] [eslint config] [base] [patch] Adjust imports for vue-cli Allows the vue-cli config file `vue.config.js` to import `devDependencies` by altering the rule `import/no-extraneous-dependencies`. --- packages/eslint-config-airbnb-base/rules/imports.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index c48959e14f..91d82df1cb 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -79,6 +79,7 @@ module.exports = { 'test-*.{js,jsx}', // repos with multiple top-level test files '**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test '**/jest.config.js', // jest config + '**/vue.config.js', // vue-cli config '**/webpack.config.js', // webpack config '**/webpack.config.*.js', // webpack config '**/rollup.config.js', // rollup config From 25e711cedd78e3329e8a8508d723996080d8336f Mon Sep 17 00:00:00 2001 From: Gaurav Paliwal Date: Wed, 20 Jun 2018 17:31:00 +0530 Subject: [PATCH 069/408] [eslint config] [patch] Add new methods introduced in react@16.3 --- packages/eslint-config-airbnb/rules/react.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index f5a807faac..a2a21c141f 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -23,13 +23,17 @@ module.exports = { 'getDefaultProps', 'getChildContext', 'componentWillMount', + 'UNSAFE_componentWillMount', 'componentDidMount', 'componentWillReceiveProps', + 'UNSAFE_componentWillReceiveProps', 'shouldComponentUpdate', 'componentWillUpdate', + 'UNSAFE_componentWillUpdate', 'componentDidUpdate', 'componentWillUnmount', 'componentDidCatch', + 'getSnapshotBeforeUpdate' ], }], From 951825c6d216ef2b3017472ae66e9b3360b089ae Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Jun 2018 14:22:54 -0700 Subject: [PATCH 070/408] [eslint config] set `forbid-foreign-prop-types` to "warn" --- packages/eslint-config-airbnb/rules/react.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index a2a21c141f..20971d1622 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -375,8 +375,9 @@ module.exports = { // Forbids using non-exported propTypes // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md - // TODO: enable? - 'react/forbid-foreign-prop-types': ['off', { allowInPropTypes: true }], + // this is intentionally set to "warn". it would be "error", but it's only critical if you're using + // a babel transform to strip propTypes in production. + 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }], // Prevent void DOM elements from receiving children // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/void-dom-elements-no-children.md From fdb998b38adda8777022fe33b86b2f8092ac83a0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Jun 2018 14:39:07 -0700 Subject: [PATCH 071/408] [eslint config] [base] fix tests --- packages/eslint-config-airbnb-base/whitespace.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb-base/whitespace.js b/packages/eslint-config-airbnb-base/whitespace.js index 66a05e52b9..d215d4ae6a 100644 --- a/packages/eslint-config-airbnb-base/whitespace.js +++ b/packages/eslint-config-airbnb-base/whitespace.js @@ -1,8 +1,9 @@ -const baseConfig = require('.'); const assign = require('object.assign'); const entries = require('object.entries'); const CLIEngine = require('eslint').CLIEngine; +const baseConfig = require('.'); + function onlyErrorOnRules(rulesToError, config) { const errorsOnly = assign({}, config); const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); From 8be089eb1138c6e5dbdc27146248525c0633ba47 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Jun 2018 14:46:24 -0700 Subject: [PATCH 072/408] [eslint config] fix tests --- packages/eslint-config-airbnb/rules/react.js | 4 ++-- packages/eslint-config-airbnb/whitespace.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 20971d1622..62675c1cf0 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -375,8 +375,8 @@ module.exports = { // Forbids using non-exported propTypes // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md - // this is intentionally set to "warn". it would be "error", but it's only critical if you're using - // a babel transform to strip propTypes in production. + // this is intentionally set to "warn". it would be "error", + // but it's only critical if you're stripping propTypes in production. 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }], // Prevent void DOM elements from receiving children diff --git a/packages/eslint-config-airbnb/whitespace.js b/packages/eslint-config-airbnb/whitespace.js index ba36569a99..414f9c37a1 100644 --- a/packages/eslint-config-airbnb/whitespace.js +++ b/packages/eslint-config-airbnb/whitespace.js @@ -1,8 +1,9 @@ -const baseConfig = require('.'); const assign = require('object.assign'); const entries = require('object.entries'); const CLIEngine = require('eslint').CLIEngine; +const baseConfig = require('.'); + function onlyErrorOnRules(rulesToError, config) { const errorsOnly = assign({}, config); const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); From afe340773f082b262955abf243efbd60e2d87ee4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Jun 2018 14:46:43 -0700 Subject: [PATCH 073/408] [eslint config] [base] v13.0.0 --- .../eslint-config-airbnb-base/CHANGELOG.md | 34 +++++++++++++++++++ .../eslint-config-airbnb-base/package.json | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb-base/CHANGELOG.md b/packages/eslint-config-airbnb-base/CHANGELOG.md index 6dd34427fc..daff7f51a7 100644 --- a/packages/eslint-config-airbnb-base/CHANGELOG.md +++ b/packages/eslint-config-airbnb-base/CHANGELOG.md @@ -1,3 +1,37 @@ +13.0.0 / 2018-06-21 +================== + - [breaking] order of import statements is ignored for unassigned imports (#1782) + - [breaking] enable `import/no-cycle`: warn on cyclical dependencies (#1779) + - [breaking] Change import/no-self-import from "off" to "error" (#1770) + - [breaking] Update `object-curly-newline` to match eslint 4.18.0 (#1761) + - [breaking] enable `no-useless-path-segments` (#1743) + - [breaking] Prevent line breaks before and after `=` (#1710) + - [breaking] Add .mjs extension support (#1634) + - [breaking] enable `implicit-arrow-linebreak` + - [breaking] Enables `nonblock-statement-body-position` rule and adds link to guide (#1618) + - [breaking] `no-mixed-operators`: only warn on `**` and `%` mixed with arithmetic operators; removes violation against mixing common math operators. (#1611) + - [breaking] `import/named`: enable + - [breaking] `lines-between-class-members`: set to “always” + - [breaking] `no-else-return`: disallow else-if (#1595) + - [breaking] Enables eslint rule for operator-linebreak + - [new] Adds config entry point with only whitespace rules enabled (#1749, #1751) + - [minor] only allow one newline at the end (#1794) + - [patch] Adjust imports for vue-cli (#1809) + - [patch] Allow devDependencies for `foo_spec.js` naming style (#1732) + - [patch] `function-paren-newline`: change to "consistent" + - [patch] avoid `__mocks__` `no-extraneous-dependencies` check (#1772) + - [patch] Include 'accumulator' exception for `no-param-reassign` (#1768) + - [patch] Set import/extensions to ignorePackages (#1652) + - [patch] properly ignore indentation on jsx + - [patch] `array-callback-return`: enable `allowImplicit` option (#1668) + - [deps] update `eslint`, `eslint-plugin-import` + - [dev deps] update `babel-preset-airbnb`, `tape`, `eslint-find-rules` + - [meta] add ES2015-2018 in npm package keywords (#1587) + - [meta] Add licenses to sub packages (#1746) + - [docs] add `npx` shortcut (#1694) + - [docs] Use HTTPS for links to ESLint documentation (#1628) + - [tests] ensure all entry points parse + 12.1.0 / 2017-10-16 ================== - [deps] update `eslint` to `v4.9` diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index bd2ef922c3..bd072bf850 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb-base", - "version": "12.1.0", + "version": "13.0.0", "description": "Airbnb's base JS ESLint config, following our styleguide", "main": "index.js", "scripts": { From d14ed5daa7625eab6e03fb290b0a18ed11b229fc Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Jun 2018 15:16:52 -0700 Subject: [PATCH 074/408] [eslint config] [breaking] update `eslint-config-airbnb-base` --- 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 97e1579393..313e61a3bb 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -26,7 +26,7 @@ "airbnb", "javascript", "styleguide", - "es2015", + "es2015", "es2016", "es2017", "es2018" @@ -53,7 +53,7 @@ }, "homepage": "https://github.com/airbnb/javascript", "dependencies": { - "eslint-config-airbnb-base": "^12.1.0", + "eslint-config-airbnb-base": "^13.0.0", "object.assign": "^4.1.0", "object.entries": "^1.0.4" }, From cae920fc308325b40f49c5e8f76bbeb5d8663fc5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Jun 2018 15:22:10 -0700 Subject: [PATCH 075/408] [eslint config] v17.0.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 19 +++++++++++++++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index d19acfc7f2..14f9e6748a 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,22 @@ +17.0.0 / 2018-06-21 +================== +- [breaking] update `eslint-config-airbnb-base` to v13 +- [breaking] enable `no-useless-path-segments` (#1743) +- [breaking] update `eslint-plugin-react` to `v7.6`; update rule configs (#1737) +- [breaking] bump react pragma to v16; update `class-methods-use-this`'s `exceptMethods` to include `componentDidCatch` (#1704) +- [new] Adds config entry point with only whitespace rules enabled (#1749, #1751) +- [patch] set `forbid-foreign-prop-types` to "warn" +- [patch] Add new methods introduced in react@16.3 (#1831) +- [patch] `label-has-for`: Remove redundant component (#1802) +- [patch] Add 'to' as a specialLink to the 'anchor-is-valid' a11y rule (#1648) +- [patch] disable `no-did-mount-set-state`, since it’s necessary for server-rendering. +- [deps] update `eslint`, `eslint-plugin-react`, `eslint-plugin-import`, +- [dev deps] update `babel-preset-airbnb`, `tape`, `eslint-find-rules` +- [meta] add ES2015-2018 in npm package keywords (#1587) +- [meta] Add licenses to sub packages (#1746) +- [docs] add `npx` shortcut (#1694) +- [docs] Use HTTPS for links to ESLint documentation (#1628) + 16.1.0 / 2017-10-16 ================== - [deps] update `eslint-config-airbnb-base`, `eslint` to v4.9 diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 313e61a3bb..160a44b823 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "16.1.0", + "version": "17.0.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 2161ddf8d6b608fbb91466e741f68b6a50608d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Mon, 25 Jun 2018 02:08:15 +0800 Subject: [PATCH 076/408] Build: add node 10 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bc8324b755..0f4ecc3fb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: + - "10" - "9" - "8" - "7" From 8de558b7500c91e8e77e4c2446e9888844bcba77 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 24 Jun 2018 19:41:27 -0700 Subject: [PATCH 077/408] [eslint config] [*] [deps] update `eslint-plugin-import` --- packages/eslint-config-airbnb-base/package.json | 4 ++-- packages/eslint-config-airbnb-base/rules/imports.js | 4 ++++ packages/eslint-config-airbnb/package.json | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index bd072bf850..4fced65b6d 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -58,14 +58,14 @@ "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", "eslint-find-rules": "^3.2.3", - "eslint-plugin-import": "^2.12.0", + "eslint-plugin-import": "^2.13.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", "tape": "^4.9.1" }, "peerDependencies": { "eslint": "^4.19.1", - "eslint-plugin-import": "^2.12.0" + "eslint-plugin-import": "^2.13.0" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb-base/rules/imports.js b/packages/eslint-config-airbnb-base/rules/imports.js index 91d82df1cb..fbeca8dc83 100644 --- a/packages/eslint-config-airbnb-base/rules/imports.js +++ b/packages/eslint-config-airbnb-base/rules/imports.js @@ -239,5 +239,9 @@ module.exports = { importFunctions: [], webpackChunknameFormat: '[0-9a-zA-Z-_/.]+', }], + + // Use this rule to prevent imports to folders in relative parent paths. + // https://github.com/benmosher/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md + 'import/no-relative-parent-imports': 'off', }, }; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 160a44b823..f0f16ccc02 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -63,7 +63,7 @@ "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", "eslint-find-rules": "^3.2.3", - "eslint-plugin-import": "^2.12.0", + "eslint-plugin-import": "^2.13.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.9.1", "in-publish": "^2.0.0", @@ -73,7 +73,7 @@ }, "peerDependencies": { "eslint": "^4.19.1", - "eslint-plugin-import": "^2.12.0", + "eslint-plugin-import": "^2.13.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.9.1" }, From 6a593069e1055a082d3891cc50579a6d586bf3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Mon, 25 Jun 2018 02:09:32 +0800 Subject: [PATCH 078/408] [dev deps] update `markdownlint-cli` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d907751ccc..1fdcd7be15 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,6 @@ }, "homepage": "https://github.com/airbnb/javascript", "devDependencies": { - "markdownlint-cli": "^0.3.1" + "markdownlint-cli": "^0.10.0" } } From 363bb077658906ccc809419b1ce3cb2f75b29e90 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 24 Jun 2018 22:57:06 -0700 Subject: [PATCH 079/408] [eslint config] [deps] update `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- packages/eslint-config-airbnb/rules/react.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index f0f16ccc02..9e3deaa716 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -65,7 +65,7 @@ "eslint-find-rules": "^3.2.3", "eslint-plugin-import": "^2.13.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.9.1", + "eslint-plugin-react": "^7.10.0", "in-publish": "^2.0.0", "react": ">= 0.13.0", "safe-publish-latest": "^1.1.1", @@ -75,7 +75,7 @@ "eslint": "^4.19.1", "eslint-plugin-import": "^2.13.0", "eslint-plugin-jsx-a11y": "^6.0.3", - "eslint-plugin-react": "^7.9.1" + "eslint-plugin-react": "^7.10.0" }, "engines": { "node": ">= 4" diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 62675c1cf0..dcd3ac95be 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -445,6 +445,10 @@ module.exports = { // Disallow multiple spaces between inline JSX props // https://github.com/yannickcr/eslint-plugin-react/blob/ac102885765be5ff37847a871f239c6703e1c7cc/docs/rules/jsx-props-no-multi-spaces.md 'react/jsx-props-no-multi-spaces': 'error', + + // Prevent usage of UNSAFE_ methods + // https://github.com/yannickcr/eslint-plugin-react/blob/157cc932be2cfaa56b3f5b45df6f6d4322a2f660/docs/rules/no-unsafe.md + 'react/no-unsafe': 'off', }, settings: { From 47021150388d1cea54c529463fe20299f1de9bb5 Mon Sep 17 00:00:00 2001 From: liyuhang Date: Mon, 25 Jun 2018 16:08:50 +0800 Subject: [PATCH 080/408] Fix: Typo --- linters/.markdownlint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linters/.markdownlint.json b/linters/.markdownlint.json index e7a019fed8..8731243cf7 100644 --- a/linters/.markdownlint.json +++ b/linters/.markdownlint.json @@ -31,7 +31,7 @@ "comment": "MD009: Disallow trailing spaces", "no-trailing-spaces": { - "br-spaces": 0, + "br_spaces": 0, "comment": "Empty lines inside list items should not be indented", "list_item_empty_lines": false }, From d951220399c75099838fc79577033b00530b2b90 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 Jun 2018 13:40:38 -0700 Subject: [PATCH 081/408] [eslint config] [*] [dev deps] update `eslint-find-rules` --- packages/eslint-config-airbnb-base/package.json | 2 +- packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 4fced65b6d..cb9efcf519 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -57,7 +57,7 @@ "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", - "eslint-find-rules": "^3.2.3", + "eslint-find-rules": "^3.3.1", "eslint-plugin-import": "^2.13.0", "in-publish": "^2.0.0", "safe-publish-latest": "^1.1.1", diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 9e3deaa716..81f50cbed4 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -62,7 +62,7 @@ "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", - "eslint-find-rules": "^3.2.3", + "eslint-find-rules": "^3.3.1", "eslint-plugin-import": "^2.13.0", "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.10.0", From 27e5e20b70a042945a63c37ac1d9ad834fc3acd0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 Jun 2018 14:14:01 -0700 Subject: [PATCH 082/408] [eslint config] [base] [new] update base ecmaVersion to 2018; remove deprecated experimentalObjectRestSpread option --- packages/eslint-config-airbnb-base/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb-base/index.js b/packages/eslint-config-airbnb-base/index.js index 4de657b075..16b423f35d 100644 --- a/packages/eslint-config-airbnb-base/index.js +++ b/packages/eslint-config-airbnb-base/index.js @@ -9,11 +9,8 @@ module.exports = { './rules/imports', ].map(require.resolve), parserOptions: { - ecmaVersion: 2017, + ecmaVersion: 2018, sourceType: 'module', - ecmaFeatures: { - experimentalObjectRestSpread: true, - }, }, rules: { strict: 'error', From 77fdae6a74a718d1ec32455088dbb5f964f5d271 Mon Sep 17 00:00:00 2001 From: Noah Benham Date: Mon, 2 Jul 2018 09:17:21 -0500 Subject: [PATCH 083/408] Add Cerner to In The Wild [Cerner](https://github.com/cerner/) uses Airbnb for our JS projects. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e486ae170e..7912c73cfc 100644 --- a/README.md +++ b/README.md @@ -3711,6 +3711,7 @@ Other Style Guides - **Bonhomme**: [bonhommeparis/javascript](https://github.com/bonhommeparis/javascript) - **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript) - **CaseNine**: [CaseNine/javascript](https://github.com/CaseNine/javascript) + - **Cerner**: [Cerner](https://github.com/cerner/) - **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) From fe8de599774bf8d312b2b94e93172e873c36df8f Mon Sep 17 00:00:00 2001 From: Ahmed Tarek Date: Tue, 3 Jul 2018 21:18:11 +0200 Subject: [PATCH 084/408] [eslint-config] [*] [docs] :pencil2: fix typo in Readme --- packages/eslint-config-airbnb-base/README.md | 2 +- packages/eslint-config-airbnb/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb-base/README.md b/packages/eslint-config-airbnb-base/README.md index fa0152eb04..3c1a9ce914 100644 --- a/packages/eslint-config-airbnb-base/README.md +++ b/packages/eslint-config-airbnb-base/README.md @@ -86,7 +86,7 @@ See [Airbnb's overarching ESLint config](https://npmjs.com/eslint-config-airbnb) ### eslint-config-airbnb-base/whitespace -This entry point that only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/whitespace.js). +This entry point only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/whitespace.js). ## Improving this config diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index 2f341ec187..f679682936 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -57,7 +57,7 @@ If you use yarn, run `npm info "eslint-config-airbnb@latest" peerDependencies` t ### eslint-config-airbnb/whitespace -This entry point that only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/whitespace.js). +This entry point only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/whitespace.js). ### eslint-config-airbnb/base From 5d1f4b9a49ee7def65343f5efccfcce7723b9b4b Mon Sep 17 00:00:00 2001 From: Mauro Zenoni <25953912+maurozenoni@users.noreply.github.com> Date: Tue, 3 Jul 2018 11:51:37 +0200 Subject: [PATCH 085/408] [guide] Updated Arrays Section - corrected paragraph 4.4 (conversion from iterable to array) - added paragraph 4.5 (conversion from array-like to array) --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7912c73cfc..54cb2c0d4c 100644 --- a/README.md +++ b/README.md @@ -369,8 +369,9 @@ Other Style Guides const itemsCopy = [...items]; ``` - - - [4.4](#arrays--from) To convert an array-like object to an array, use spreads `...` instead of [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from). + + + - [4.4](#arrays--from-iterable) To convert an iterable object to an array, use spreads `...` instead of [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from). ```javascript const foo = document.querySelectorAll('.foo'); @@ -382,8 +383,21 @@ Other Style Guides const nodes = [...foo]; ``` + + - [4.5](#arrays--from-array-like) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) for converting an array-like object to an array. + + ```javascript + const arrLike = { 0: 'foo', 1: 'bar', 2: 'baz', length: 3 }; + + // bad + const arr = Array.prototype.slice.call(arrLike); + + // good + const arr = Array.from(arrLike); + ``` + - - [4.5](#arrays--mapping) Use [Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables, because it avoids creating an intermediate array. + - [4.6](#arrays--mapping) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables, because it avoids creating an intermediate array. ```javascript // bad @@ -394,7 +408,7 @@ Other Style Guides ``` - - [4.6](#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 returning an expression without side effects, following [8.2](#arrows--implicit-return). eslint: [`array-callback-return`](https://eslint.org/docs/rules/array-callback-return) + - [4.7](#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 returning an expression without side effects, following [8.2](#arrows--implicit-return). eslint: [`array-callback-return`](https://eslint.org/docs/rules/array-callback-return) ```javascript // good @@ -441,7 +455,7 @@ Other Style Guides ``` - - [4.7](#arrays--bracket-newline) Use line breaks after open and before close array brackets if an array has multiple lines + - [4.8](#arrays--bracket-newline) Use line breaks after open and before close array brackets if an array has multiple lines ```javascript // bad From 7dda84a335f5903d72c9423dc17f33f2c9813d2a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 4 Jul 2018 22:33:27 -0700 Subject: [PATCH 086/408] [eslint config] [deps] [minor] update `jsx-a11y` plugin; enable `label-has-associated-control` rule This is semver-minor, because the `label-has-associated-control` rule is the same as the `label-has-for` rule, theoretically. Both remain enabled, but `label-has-for` will be disabled in the future if this rule proves out. --- packages/eslint-config-airbnb/package.json | 4 ++-- packages/eslint-config-airbnb/rules/react-a11y.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 81f50cbed4..53079d4a07 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -64,7 +64,7 @@ "eslint": "^4.19.1", "eslint-find-rules": "^3.3.1", "eslint-plugin-import": "^2.13.0", - "eslint-plugin-jsx-a11y": "^6.0.3", + "eslint-plugin-jsx-a11y": "^6.1.0", "eslint-plugin-react": "^7.10.0", "in-publish": "^2.0.0", "react": ">= 0.13.0", @@ -74,7 +74,7 @@ "peerDependencies": { "eslint": "^4.19.1", "eslint-plugin-import": "^2.13.0", - "eslint-plugin-jsx-a11y": "^6.0.3", + "eslint-plugin-jsx-a11y": "^6.1.0", "eslint-plugin-react": "^7.10.0" }, "engines": { diff --git a/packages/eslint-config-airbnb/rules/react-a11y.js b/packages/eslint-config-airbnb/rules/react-a11y.js index f53b3d22f6..dbb073fa67 100644 --- a/packages/eslint-config-airbnb/rules/react-a11y.js +++ b/packages/eslint-config-airbnb/rules/react-a11y.js @@ -56,6 +56,16 @@ module.exports = { allowChildren: false, }], + // Enforce that a label tag has a text label and an associated control. + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/b800f40a2a69ad48015ae9226fbe879f946757ed/docs/rules/label-has-associated-control.md + 'jsx-a11y/label-has-associated-control': ['error', { + labelComponents: [], + labelAttributes: [], + controlComponents: [], + assert: 'both', + depth: 25 + }], + // require that mouseover/out come with focus/blur, for keyboard-only users // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md 'jsx-a11y/mouse-events-have-key-events': 'error', From 2037fd82b9260db71758aedc513e86b7df23c01e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 Jun 2018 15:48:07 -0700 Subject: [PATCH 087/408] [Tests] link eslint from the base config as well --- packages/eslint-config-airbnb/package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 53079d4a07..fd25457d7b 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -11,9 +11,10 @@ "prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test) && safe-publish-latest", "pretest": "npm run --silent lint", "test": "npm run --silent tests-only", - "pretravis": "cd ../eslint-config-airbnb-base && npm install && npm link && cd - && npm link --no-save eslint-config-airbnb-base", + "link:eslint": "cd node_modules/eslint && npm link && cd -", + "pretravis": "npm run link:eslint && cd ../eslint-config-airbnb-base && npm link eslint && npm install && npm link && cd - && npm link --no-save eslint-config-airbnb-base", "travis": "npm run --silent test", - "posttravis": "npm unlink --no-save eslint-config-airbnb-base >/dev/null &" + "posttravis": "npm unlink --no-save eslint-config-airbnb-base eslint >/dev/null &" }, "repository": { "type": "git", From a510095acf20e3d96a94e6d0d0b26cfac71d2c7f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 Jun 2018 15:06:18 -0700 Subject: [PATCH 088/408] [eslint config] [*] [new] add eslint v5 support --- .travis.yml | 23 ++++++++++++++++--- .../eslint-config-airbnb-base/package.json | 4 ++-- .../rules/best-practices.js | 10 +++++++- .../eslint-config-airbnb-base/rules/style.js | 16 +++++++++++++ packages/eslint-config-airbnb/package.json | 4 ++-- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0f4ecc3fb1..2fcc94de67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,20 +18,37 @@ script: sudo: false env: matrix: - - 'TEST=true ESLINT=4 PACKAGE=eslint-config-airbnb' + - 'TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base' + - 'TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb' - 'TEST=true ESLINT=4 PACKAGE=eslint-config-airbnb-base' + - 'TEST=true ESLINT=4 PACKAGE=eslint-config-airbnb' matrix: fast_finish: true include: - node_js: "lts/*" - env: PREPUBLISH=true ESLINT=4 PACKAGE=eslint-config-airbnb + env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-base + - node_js: "lts/*" + env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb - node_js: "lts/*" env: PREPUBLISH=true ESLINT=4 PACKAGE=eslint-config-airbnb-base + - node_js: "lts/*" + env: PREPUBLISH=true ESLINT=4 PACKAGE=eslint-config-airbnb - node_js: "lts/*" env: LINT=true + exclude: + - node_js: "5" + env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base + - node_js: "5" + env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb + - node_js: "4" + env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base + - node_js: "4" + env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb allow_failures: - node_js: "9" - node_js: "7" - node_js: "5" - - env: PREPUBLISH=true ESLINT=4 PACKAGE=eslint-config-airbnb + - env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-base + - env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb - env: PREPUBLISH=true ESLINT=4 PACKAGE=eslint-config-airbnb-base + - env: PREPUBLISH=true ESLINT=4 PACKAGE=eslint-config-airbnb diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index cb9efcf519..1bdfc3b2ff 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -56,7 +56,7 @@ "babel-preset-airbnb": "^2.5.1", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.19.1", + "eslint": "^4.19.1 || ^5.0.1", "eslint-find-rules": "^3.3.1", "eslint-plugin-import": "^2.13.0", "in-publish": "^2.0.0", @@ -64,7 +64,7 @@ "tape": "^4.9.1" }, "peerDependencies": { - "eslint": "^4.19.1", + "eslint": "^4.19.1 || ^5.0.1", "eslint-plugin-import": "^2.13.0" }, "engines": { diff --git a/packages/eslint-config-airbnb-base/rules/best-practices.js b/packages/eslint-config-airbnb-base/rules/best-practices.js index b5712d00b2..421b591488 100644 --- a/packages/eslint-config-airbnb-base/rules/best-practices.js +++ b/packages/eslint-config-airbnb-base/rules/best-practices.js @@ -42,6 +42,11 @@ module.exports = { // make sure for-in loops have an if statement 'guard-for-in': 'error', + // enforce a maximum number of classes per file + // https://eslint.org/docs/rules/max-classes-per-file + // TODO: semver-major (eslint 5): enable + 'max-classes-per-file': ['off', 1], + // disallow the use of alert, confirm, and prompt 'no-alert': 'warn', @@ -243,7 +248,10 @@ module.exports = { // disallow self assignment // https://eslint.org/docs/rules/no-self-assign - 'no-self-assign': 'error', + // TODO: semver-major: props -> true + 'no-self-assign': ['error', { + props: false, + }], // disallow comparisons where both sides are exactly the same 'no-self-compare': 'error', diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index ca8fc07ae6..ee5408f81c 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -21,6 +21,7 @@ module.exports = { 'brace-style': ['error', '1tbs', { allowSingleLine: true }], // require camel case names + // TODO: semver-major (eslint 5): add ignoreDestructuring: false option camelcase: ['error', { properties: 'never' }], // enforce or disallow capitalization of the first letter of a comment @@ -83,6 +84,7 @@ module.exports = { // requires function names to match the name of the variable or property to which they are // assigned // https://eslint.org/docs/rules/func-name-matching + // TODO: semver-major (eslint 5): add considerPropertyDescriptor: true 'func-name-matching': ['off', 'always', { includeCommonJSModuleExports: false }], @@ -208,6 +210,15 @@ module.exports = { skipComments: true }], + // enforce a maximum function length + // https://eslint.org/docs/rules/max-lines-per-function + 'max-lines-per-function': ['off', { + max: 50, + skipBlankLines: true, + skipComments: true, + IIFEs: true, + }], + // specify the maximum depth callbacks can be nested 'max-nested-callbacks': 'off', @@ -416,6 +427,11 @@ module.exports = { // https://eslint.org/docs/rules/padding-line-between-statements 'padding-line-between-statements': 'off', + // Prefer use of an object spread over Object.assign + // https://eslint.org/docs/rules/prefer-object-spread + // TODO: semver-major (eslint 5): enable + 'prefer-object-spread': 'off', + // require quotes around object literal property names // https://eslint.org/docs/rules/quote-props.html 'quote-props': ['error', 'as-needed', { keywords: false, unnecessary: true, numbers: false }], diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index fd25457d7b..63dbe709eb 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -62,7 +62,7 @@ "babel-preset-airbnb": "^2.5.1", "babel-tape-runner": "^2.0.1", "editorconfig-tools": "^0.1.1", - "eslint": "^4.19.1", + "eslint": "^4.19.1 || ^5.0.1", "eslint-find-rules": "^3.3.1", "eslint-plugin-import": "^2.13.0", "eslint-plugin-jsx-a11y": "^6.1.0", @@ -73,7 +73,7 @@ "tape": "^4.9.1" }, "peerDependencies": { - "eslint": "^4.19.1", + "eslint": "^4.19.1 || ^5.0.1", "eslint-plugin-import": "^2.13.0", "eslint-plugin-jsx-a11y": "^6.1.0", "eslint-plugin-react": "^7.10.0" From 96317f8c79d6c5a6e9478a49eb89770863c4e6e1 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 5 Jul 2018 16:48:26 +0300 Subject: [PATCH 089/408] [guide] fix anchor tag in README.md Currently, this anchor with missing end tag breaks rendering: https://github.com/airbnb/javascript/blob/5d1f4b9a49ee7def65343f5efccfcce7723b9b4b/README.md#arrays--from-iterable --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54cb2c0d4c..ae13bca33a 100644 --- a/README.md +++ b/README.md @@ -369,7 +369,7 @@ Other Style Guides const itemsCopy = [...items]; ``` - + - [4.4](#arrays--from-iterable) To convert an iterable object to an array, use spreads `...` instead of [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from). From b6a268f780177e03b573a4f0df95ecc0d2e8783e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 9 Jul 2018 23:16:25 -0700 Subject: [PATCH 090/408] [eslint config] [react] disable two buggy rules, temporarily --- packages/eslint-config-airbnb/rules/react.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index dcd3ac95be..7d82df1302 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -413,11 +413,13 @@ module.exports = { // One JSX Element Per Line // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-one-expression-per-line.md - 'react/jsx-one-expression-per-line': 'error', + // TODO: re-enable when an option for text children is available + 'react/jsx-one-expression-per-line': 'off', // Enforce consistent usage of destructuring assignment of props, state, and context // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/destructuring-assignment.md - 'react/destructuring-assignment': ['error', 'always'], + // TODO: re-enable when component detection is fixed + 'react/destructuring-assignment': ['off', 'always'], // Prevent using this.state within a this.setState // https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-access-state-in-setstate.md From a12dec90d173464a3fc4e4536b8c6f639fb93236 Mon Sep 17 00:00:00 2001 From: Andrew Scheuermann Date: Wed, 11 Jul 2018 16:26:22 -0700 Subject: [PATCH 091/408] [guide] [react] boolean in jsx alignment --- react/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/react/README.md b/react/README.md index c4fcf76d56..340e780c01 100644 --- a/react/README.md +++ b/react/README.md @@ -193,6 +193,25 @@ This style guide is mostly based on the standards that are currently prevalent i > + + // bad + {showButton && +