From 5fd7c6f08c0650ed67297fc83c8a0590c9a92cc8 Mon Sep 17 00:00:00 2001 From: Estelle Date: Mon, 23 Mar 2015 18:48:19 -0700 Subject: [PATCH 0001/1167] 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 c2fd8fbbd6cf058244024db3ab791ddba15567a1 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Thu, 14 Jan 2016 17:01:31 +0100 Subject: [PATCH 0002/1167] Add missing ES6 rules to ESLint config. `arrow-body-style` (8.2) and `prefer-template` (6.4) are described in the Style Guide. --- packages/eslint-config-airbnb/rules/es6.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index b913fb281c..e34684346d 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -22,6 +22,9 @@ module.exports = { 'jsx': true }, 'rules': { + // enforces no braces where they can be omitted + // http://eslint.org/docs/rules/arrow-body-style + 'arrow-body-style': [2, 'as-needed'], // require parens in arrow function arguments 'arrow-parens': 0, // require space before/after arrow function's arrow @@ -50,6 +53,9 @@ module.exports = { 'prefer-spread': 0, // suggest using Reflect methods where applicable 'prefer-reflect': 0, + // suggest using template literals instead of string concatenation + // http://eslint.org/docs/rules/prefer-template + 'prefer-template': 2, // disallow generator functions that do not have yield 'require-yield': 0 } From 4ef335e24276a6c2a46fe7a0674f49cfcff79796 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 10 Jan 2016 15:11:05 -0800 Subject: [PATCH 0003/1167] [eslint config] [breaking] require outer IIFE wrapping; flesh out guide section. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was lots of discussion [here](https://github.com/airbnb/javascript/issues/21#issuecomment-10203921), but now that we have both a modern build system and an eslint rule requiring terminating semicolons, the concerns with the “crockford” style no longer apply. --- README.md | 10 +++++++--- packages/eslint-config-airbnb/rules/best-practices.js | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b465162e05..8654faf1c3 100644 --- a/README.md +++ b/README.md @@ -506,13 +506,17 @@ Other Style Guides } ``` - - [7.2](#7.2) Function expressions: + - [7.2](#7.2) Immediately invoked function expressions: + + > 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. + + eslint rules: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html). ```javascript // immediately-invoked function expression (IIFE) - (() => { + (function () { console.log('Welcome to the Internet. Please follow me.'); - })(); + }()); ``` - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 82e5f9e289..1b64cdeb8e 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -108,7 +108,8 @@ module.exports = { // requires to declare all vars on top of their containing scope 'vars-on-top': 2, // require immediate function invocation to be wrapped in parentheses - 'wrap-iife': [2, 'any'], + // http://eslint.org/docs/rules/wrap-iife.html + 'wrap-iife': [2, 'outside'], // require or disallow Yoda conditions 'yoda': 2 } From 59a0bccd9248b5fb20a88b0306cc33f9e8e37a26 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 13 Jan 2016 12:25:32 +0100 Subject: [PATCH 0004/1167] 7.3: Add Link to eslint rule. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 390343fb9f..acedcd720c 100644 --- a/README.md +++ b/README.md @@ -517,6 +517,8 @@ Other Style Guides - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. + eslint rules: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html). + - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). ```javascript From 54b4dea0f94e5b647ec36ef4f6feba5bc383fc1b Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 13 Jan 2016 17:32:30 +0100 Subject: [PATCH 0005/1167] Add `prefer-arrow-callback` to ES6 Rules. This prefers arrow functions as described in https://github.com/airbnb/javascript#8.1 --- packages/eslint-config-airbnb/rules/es6.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 3c277064b6..b913fb281c 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -42,6 +42,8 @@ module.exports = { // require method and property shorthand syntax for object literals // https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md 'object-shorthand': [2, 'always'], + // suggest using arrow functions as callbacks + 'prefer-arrow-callback': 2, // suggest using of const declaration for variables that are never modified after declared 'prefer-const': 2, // suggest using the spread operator instead of .apply() From 90e6cd1c987e308e4b60f97483ae92dfeabe717f Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Wed, 13 Jan 2016 13:02:08 +0100 Subject: [PATCH 0006/1167] 22.3: Add Link to eslint rule. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index acedcd720c..7bcf0ef8d7 100644 --- a/README.md +++ b/README.md @@ -2004,6 +2004,8 @@ Other Style Guides ``` - [22.3](#22.3) Use PascalCase when naming constructors or classes. + + eslint rules: [`new-cap`](http://eslint.org/docs/rules/new-cap.html). ```javascript // bad From 397f5bbd14d2118c0183b6a3fe5ceda6b1c81832 Mon Sep 17 00:00:00 2001 From: Eddie Monge Date: Mon, 4 Jan 2016 14:10:48 -0800 Subject: [PATCH 0007/1167] assign variables: give a reason for the assignment The variable assignment wasn't necessary. This gives a reason to have it there --- README.md | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7bcf0ef8d7..e7b3e37227 100644 --- a/README.md +++ b/README.md @@ -1102,45 +1102,36 @@ Other Style Guides > Why? `let` and `const` are block scoped and not function scoped. ```javascript - // good - function () { - test(); - console.log('doing stuff..'); - - //..other stuff.. - + // bad - unnecessary function call + function checkName(hasName) { const name = getName(); - if (name === 'test') { + if (hasName === 'test') { return false; } - return name; - } - - // bad - unnecessary function call - function (hasName) { - const name = getName(); - - if (!hasName) { + if (name === 'test') { + this.setName(''); return false; } - this.setFirstName(name); - - return true; + return name; } // good - function (hasName) { - if (!hasName) { + function checkName(hasName) { + if (hasName === 'test') { return false; } const name = getName(); - this.setFirstName(name); - return true; + if (name === 'test') { + this.setName(''); + return false; + } + + return name; } ``` From 9498b3f7c485f56aa22549b95428aea5d2aa53fd Mon Sep 17 00:00:00 2001 From: Peter Geiss Date: Wed, 13 Jan 2016 23:12:06 -0500 Subject: [PATCH 0008/1167] Clearly show that [] is truthy --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e7b3e37227..b465162e05 100644 --- a/README.md +++ b/README.md @@ -1250,9 +1250,9 @@ Other Style Guides + **Strings** evaluate to **false** if an empty string `''`, otherwise **true** ```javascript - if ([0]) { + if ([0] && []) { // true - // An array is an object, objects evaluate to true + // An array (even an empty one) is an object, objects will evaluate to true } ``` From c778ade84166ab8061d408696f2ce8614491545f Mon Sep 17 00:00:00 2001 From: Jeff Shen Date: Thu, 14 Jan 2016 23:30:08 -0800 Subject: [PATCH 0009/1167] Fix case type on line 3 comment Update case type to resemble other comments --- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 82e5f9e289..d394f67d1a 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -1,6 +1,6 @@ module.exports = { 'rules': { - // Enforces getter/setter pairs in objects + // enforces getter/setter pairs in objects 'accessor-pairs': 0, // treat var statements as if they were block scoped 'block-scoped-var': 2, From a4845a82cf41d8589bb28283761ea096346c621c Mon Sep 17 00:00:00 2001 From: Prayag Verma Date: Sat, 16 Jan 2016 17:33:50 +0530 Subject: [PATCH 0010/1167] Update license year range to 2016 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8654faf1c3..ab5f428cbd 100644 --- a/README.md +++ b/README.md @@ -2504,7 +2504,7 @@ Other Style Guides (The MIT License) -Copyright (c) 2014 Airbnb +Copyright (c) 2014-2016 Airbnb Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From ab58d3b68eff9fd45db9bc8c78b99e61016e39f9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 15 Jan 2016 10:31:00 -0800 Subject: [PATCH 0011/1167] [Tests] run `npm run lint` as part of tests; fix errors. hat tip to https://github.com/airbnb/javascript/pull/678#issuecomment-172017623 --- packages/eslint-config-airbnb/base.js | 4 ++-- packages/eslint-config-airbnb/index.js | 2 +- packages/eslint-config-airbnb/legacy.js | 20 +++++++++---------- packages/eslint-config-airbnb/package.json | 3 ++- .../eslint-config-airbnb/rules/.eslintrc.json | 5 +++++ .../rules/best-practices.js | 2 +- packages/eslint-config-airbnb/rules/react.js | 20 +++++++++---------- packages/eslint-config-airbnb/rules/style.js | 19 +++++++++--------- .../eslint-config-airbnb/rules/variables.js | 2 +- .../test/test-react-order.js | 3 +-- 10 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 packages/eslint-config-airbnb/rules/.eslintrc.json diff --git a/packages/eslint-config-airbnb/base.js b/packages/eslint-config-airbnb/base.js index 093bd541be..1cfea52161 100644 --- a/packages/eslint-config-airbnb/base.js +++ b/packages/eslint-config-airbnb/base.js @@ -1,7 +1,7 @@ module.exports = { - 'extends': [ + extends: [ 'eslint-config-airbnb/legacy', 'eslint-config-airbnb/rules/es6', ].map(require.resolve), - 'rules': {} + rules: {} }; diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index 5a5c535e74..e9ce995ae5 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -1,5 +1,5 @@ module.exports = { - 'extends': [ + extends: [ 'eslint-config-airbnb/base', 'eslint-config-airbnb/rules/strict', 'eslint-config-airbnb/rules/react', diff --git a/packages/eslint-config-airbnb/legacy.js b/packages/eslint-config-airbnb/legacy.js index 257b9dd868..b404cf7c88 100644 --- a/packages/eslint-config-airbnb/legacy.js +++ b/packages/eslint-config-airbnb/legacy.js @@ -1,5 +1,5 @@ module.exports = { - 'extends': [ + extends: [ 'eslint-config-airbnb/rules/best-practices', 'eslint-config-airbnb/rules/errors', 'eslint-config-airbnb/rules/legacy', @@ -7,14 +7,14 @@ module.exports = { 'eslint-config-airbnb/rules/style', 'eslint-config-airbnb/rules/variables' ].map(require.resolve), - 'env': { - 'browser': true, - 'node': true, - 'amd': false, - 'mocha': false, - 'jasmine': false + env: { + browser: true, + node: true, + amd: false, + mocha: false, + jasmine: false }, - 'ecmaFeatures': {}, - 'globals': {}, - 'rules': {} + ecmaFeatures: {}, + globals: {}, + rules: {} }; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 016b02098a..eb3eaa8fe5 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "lint": "eslint .", - "test": "babel-tape-runner ./test/test-*.js" + "tests-only": "babel-tape-runner ./test/test-*.js", + "test": "npm run lint && npm run tests-only" }, "repository": { "type": "git", diff --git a/packages/eslint-config-airbnb/rules/.eslintrc.json b/packages/eslint-config-airbnb/rules/.eslintrc.json new file mode 100644 index 0000000000..de68aa25ca --- /dev/null +++ b/packages/eslint-config-airbnb/rules/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "quote-props": 0 + } +} diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 1b64cdeb8e..dfc5ff5622 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -13,7 +13,7 @@ module.exports = { // require default case in switch statements 'default-case': 2, // encourages use of dot notation whenever possible - 'dot-notation': [2, { 'allowKeywords': true}], + 'dot-notation': [2, { 'allowKeywords': true }], // enforces consistent newlines before or after dots 'dot-location': 0, // require the use of === and !== diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index c17328ebe8..e1e1c25993 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -10,10 +10,10 @@ module.exports = { 'rules': { // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - 'react/display-name': [0, {'acceptTranspilerName': false}], + 'react/display-name': [0, { 'acceptTranspilerName': false }], // Forbid certain propTypes (any, array, object) // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md - 'react/forbid-prop-types': [0, {'forbid': ['any', 'array', 'object']}], + 'react/forbid-prop-types': [0, { 'forbid': ['any', 'array', 'object'] }], // Enforce boolean attributes notation in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md 'react/jsx-boolean-value': [2, 'never'], @@ -22,7 +22,7 @@ module.exports = { 'react/jsx-closing-bracket-location': [2, 'line-aligned'], // Enforce or disallow spaces inside of curly braces in JSX attributes // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md - 'react/jsx-curly-spacing': [0, 'never', {'allowMultiline': true}], + 'react/jsx-curly-spacing': [0, 'never', { 'allowMultiline': true }], // Enforce event handler naming conventions in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md 'react/jsx-handler-names': [0, { @@ -37,13 +37,13 @@ module.exports = { 'react/jsx-key': 0, // Limit maximum of props on a single line in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md - 'react/jsx-max-props-per-line': [0, {'maximum': 1}], + 'react/jsx-max-props-per-line': [0, { 'maximum': 1 }], // Prevent usage of .bind() and arrow functions in JSX props // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md 'react/jsx-no-bind': 2, // Prevent duplicate props in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md - 'react/jsx-no-duplicate-props': [0, {'ignoreCase': false}], + 'react/jsx-no-duplicate-props': [0, { 'ignoreCase': false }], // Prevent usage of unwrapped JSX strings // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md 'react/jsx-no-literals': 0, @@ -67,7 +67,7 @@ module.exports = { }], // 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': [2, {'pragma': 'React'}], + 'react/jsx-uses-react': [2, { 'pragma': 'React' }], // Prevent variables used in JSX to be incorrectly marked as unused // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md 'react/jsx-uses-vars': 2, @@ -76,7 +76,7 @@ module.exports = { 'react/no-danger': 0, // Prevent usage of deprecated methods // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md - 'react/no-deprecated': [1, {"react": "0.14.0"}], + 'react/no-deprecated': [1, { 'react': '0.14.0' }], // Prevent usage of setState in componentDidMount // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md 'react/no-did-mount-set-state': [2, 'allow-in-func'], @@ -91,7 +91,7 @@ module.exports = { 'react/no-is-mounted': 2, // Prevent multiple component definition per file // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md - 'react/no-multi-comp': [2, {'ignoreStateless': true}], + 'react/no-multi-comp': [2, { 'ignoreStateless': true }], // Prevent usage of setState // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-set-state.md 'react/no-set-state': 0, @@ -106,13 +106,13 @@ module.exports = { 'react/prefer-es6-class': [2, 'always'], // Prevent missing props validation in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md - 'react/prop-types': [2, {'ignore': [], customValidators: []}], + 'react/prop-types': [2, { 'ignore': [], customValidators: [] }], // Prevent missing React when using JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md 'react/react-in-jsx-scope': 2, // Restrict file extensions that may be required // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-extension.md - 'react/require-extension': [0, {'extensions': ['.jsx']}], + 'react/require-extension': [0, { 'extensions': ['.jsx'] }], // Prevent extra closing tags for components without children // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md 'react/self-closing-comp': 2, diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index ec68b16e5d..2e3e3cae1b 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -3,11 +3,11 @@ module.exports = { // enforce spacing inside array brackets 'array-bracket-spacing': [2, 'never'], // enforce one true brace style - 'brace-style': [2, '1tbs', {'allowSingleLine': true }], + 'brace-style': [2, '1tbs', { 'allowSingleLine': true }], // require camel case names - 'camelcase': [2, {'properties': 'never'}], + 'camelcase': [2, { 'properties': 'never' }], // enforce spacing before and after comma - 'comma-spacing': [2, {'before': false, 'after': true}], + 'comma-spacing': [2, { 'before': false, 'after': true }], // enforce one true comma style 'comma-style': [2, 'last'], // disallow padding inside computed properties @@ -20,16 +20,17 @@ module.exports = { 'func-names': 1, // enforces use of function declarations or expressions 'func-style': 0, - // this option enforces minimum and maximum identifier lengths (variable names, property names etc.) + // this option enforces minimum and maximum identifier lengths + // (variable names, property names etc.) 'id-length': 0, // this option sets a specific tab width for your code // https://github.com/eslint/eslint/blob/master/docs/rules/indent.md - 'indent': [2, 2, { "SwitchCase": 1, "VariableDeclarator": 1 }], + 'indent': [2, 2, { 'SwitchCase': 1, 'VariableDeclarator': 1 }], // specify whether double or single quotes should be used in JSX attributes // http://eslint.org/docs/rules/jsx-quotes 'jsx-quotes': [2, 'prefer-double'], // enforces spacing between keys and values in object literal properties - 'key-spacing': [2, {'beforeColon': false, 'afterColon': true}], + 'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }], // enforces empty lines around comments 'lines-around-comment': 0, // disallow mixed 'LF' and 'CRLF' as linebreaks @@ -43,7 +44,7 @@ module.exports = { // specify the maximum depth callbacks can be nested 'max-nested-callbacks': 0, // require a capital letter for constructors - 'new-cap': [2, {'newIsCap': true}], + 'new-cap': [2, { 'newIsCap': true }], // disallow the omission of parentheses when invoking a constructor with no arguments 'new-parens': 0, // allow/disallow an empty newline after var statement @@ -59,7 +60,7 @@ module.exports = { // disallow mixed spaces and tabs for indentation 'no-mixed-spaces-and-tabs': 2, // disallow multiple empty lines and only one newline at the end - 'no-multiple-empty-lines': [2, {'max': 2, 'maxEOF': 1}], + 'no-multiple-empty-lines': [2, { 'max': 2, 'maxEOF': 1 }], // disallow nested ternary expressions 'no-nested-ternary': 2, // disallow use of the Object constructor @@ -92,7 +93,7 @@ module.exports = { // require identifiers to match the provided regular expression 'id-match': 0, // enforce spacing before and after semicolons - 'semi-spacing': [2, {'before': false, 'after': true}], + 'semi-spacing': [2, { 'before': false, 'after': true }], // require or disallow use of semicolons instead of ASI 'semi': [2, 'always'], // sort variables within the same declaration block diff --git a/packages/eslint-config-airbnb/rules/variables.js b/packages/eslint-config-airbnb/rules/variables.js index 3da93fe826..59914313f9 100644 --- a/packages/eslint-config-airbnb/rules/variables.js +++ b/packages/eslint-config-airbnb/rules/variables.js @@ -19,7 +19,7 @@ module.exports = { // disallow use of undefined variable 'no-undefined': 0, // disallow declaration of variables that are not used in the code - 'no-unused-vars': [2, {'vars': 'local', 'args': 'after-used'}], + 'no-unused-vars': [2, { 'vars': 'local', 'args': 'after-used' }], // disallow use of variables before they are defined 'no-use-before-define': 2 } diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index 1a84b59230..77448cf86a 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -1,7 +1,6 @@ import test from 'tape'; import { CLIEngine } from 'eslint'; import eslintrc from '../'; -import baseConfig from '../base'; import reactRules from '../rules/react'; const cli = new CLIEngine({ @@ -9,7 +8,7 @@ const cli = new CLIEngine({ baseConfig: eslintrc, // This rule fails when executing on text. - rules: {indent: 0}, + rules: { indent: 0 }, }); function lint(text) { From 396e4611c42416aa3b2af6ed193c3684251d9f68 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 16 Jan 2016 11:02:04 -0800 Subject: [PATCH 0012/1167] [Tests] use `parallelshell` to parallelize npm run-scripts --- 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 eb3eaa8fe5..56b15f54f5 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -6,7 +6,7 @@ "scripts": { "lint": "eslint .", "tests-only": "babel-tape-runner ./test/test-*.js", - "test": "npm run lint && npm run tests-only" + "test": "parallelshell 'npm run lint' 'npm run tests-only'" }, "repository": { "type": "git", @@ -42,7 +42,8 @@ "eslint": "^1.10.3", "eslint-plugin-react": "^3.12.0", "react": "^0.13.3", - "tape": "^4.2.2" + "tape": "^4.2.2", + "parallelshell": "^2.0.0" }, "peerDependencies": { "eslint": ">=1.0.0" From 2bd22f0475b0f3617e4df5d5bf93af72e592717a Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Sat, 16 Jan 2016 21:46:35 -0500 Subject: [PATCH 0013/1167] Document corresponding jscs rules --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ab5f428cbd..209840be36 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,9 @@ Other Style Guides > Why? `let` is block-scoped rather than function-scoped like `var`. eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html). - + + jscs rules: [`disallowVar`](http://jscs.info/rule/disallowVar). + ```javascript // bad var count = 1; @@ -153,6 +155,8 @@ Other Style Guides - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. + jscs rules: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames). + ```javascript // bad const superman = { @@ -169,6 +173,8 @@ Other Style Guides - [3.3](#3.3) Use readable synonyms in place of reserved words. + jscs rules: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames). + ```javascript // bad const superman = { @@ -216,6 +222,8 @@ Other Style Guides - [3.5](#3.5) Use object method shorthand. eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). + + jscs rules: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals). ```javascript // bad @@ -243,7 +251,9 @@ Other Style Guides > Why? It is shorter to write and descriptive. eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). - + + jscs rules: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals). + ```javascript const lukeSkywalker = 'Luke Skywalker'; @@ -292,7 +302,9 @@ Other Style Guides > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. eslint rules: [`quote-props`](http://eslint.org/docs/rules/quote-props.html). - + + jscs rules: [`disallowQuotedKeysInObjects: "allExcept": ["reserved"]`](http://jscs.info/rule/disallowQuotedKeysInObjects). + ```javascript // bad const bad = { @@ -367,6 +379,8 @@ Other Style Guides - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. > Why? Destructuring saves you from creating temporary references for those properties. + + jscs rules: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring). ```javascript // bad @@ -391,6 +405,8 @@ Other Style Guides - [5.2](#5.2) Use array destructuring. + jscs rules: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring). + ```javascript const arr = [1, 2, 3, 4]; @@ -434,7 +450,9 @@ Other Style Guides - [6.1](#6.1) Use single quotes `''` for strings. eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html). - + + jscs rules: [`validateQuoteMarks: "'"`](http://jscs.info/rule/validateQuoteMarks). + ```javascript // bad const name = "Capt. Janeway"; @@ -468,6 +486,8 @@ Other Style Guides > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html). + + jscs rules: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings). ```javascript // bad @@ -495,6 +515,8 @@ Other Style Guides - [7.1](#7.1) Use function declarations instead of function expressions. > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. + + jscs rules: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations). ```javascript // bad @@ -512,6 +534,8 @@ Other Style Guides eslint rules: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html). + jscs rules: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE). + ```javascript // immediately-invoked function expression (IIFE) (function () { @@ -712,6 +736,8 @@ Other Style Guides > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration. eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html). + + jscs rules: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions). ```javascript // bad @@ -734,6 +760,8 @@ Other Style Guides > Why not? If you plan on returning an object. eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html). + + jscs rules: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions). ```javascript // good @@ -776,7 +804,9 @@ Other Style Guides > Why? Less visual clutter. eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html). - + + jscs rules: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam). + ```js // bad [1, 2, 3].map((x) => x * x); @@ -1008,6 +1038,8 @@ Other Style Guides - [12.1](#12.1) Use dot notation when accessing properties. eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html). + + jscs rules: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation). ```javascript const luke = { @@ -1057,6 +1089,8 @@ Other Style Guides > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html). + + jscs rules: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl). ```javascript // bad @@ -1320,6 +1354,8 @@ Other Style Guides eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html). + jscs rules: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements). + ```javascript // bad if (test) { @@ -1451,6 +1487,8 @@ Other Style Guides - [18.1](#18.1) Use soft tabs set to 2 spaces. eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html). + + jscs rules: [`validateIndentation: 2`](http://jscs.info/rule/validateIndentation). ```javascript // bad @@ -1473,6 +1511,8 @@ Other Style Guides eslint rules: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html). + jscs rules: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements). + ```javascript // bad function test(){ @@ -1501,6 +1541,8 @@ Other Style Guides eslint rules: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html). + jscs rules: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords). + ```javascript // bad if(isJedi) { @@ -1526,6 +1568,8 @@ Other Style Guides - [18.4](#18.4) Set off operators with spaces. eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html). + + jscs rules: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators). ```javascript // bad @@ -1601,6 +1645,8 @@ Other Style Guides - [18.7](#18.7) Leave a blank line after blocks and before the next statement. + jscs rules: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks). + ```javascript // bad if (foo) { @@ -1659,6 +1705,8 @@ Other Style Guides - [18.8](#18.8) Do not pad your blocks with blank lines. eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html). + + jscs rules: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks). ```javascript // bad @@ -1693,6 +1741,8 @@ Other Style Guides - [18.9](#18.9) Do not add spaces inside parentheses. eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html). + + jscs rules: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses). ```javascript // bad @@ -1719,6 +1769,8 @@ Other Style Guides - [18.10](#18.10) Do not add spaces inside brackets. eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html). + + jscs rules: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets). ```javascript // bad @@ -1733,6 +1785,8 @@ Other Style Guides - [18.11](#18.11) Add spaces inside curly braces. eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html). + + jscs rules: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets). ```javascript // bad @@ -1747,6 +1801,8 @@ Other Style Guides > Why? This ensures readability and maintainability. eslint rules: [`max-len`](http://eslint.org/docs/rules/max-len.html). + + jscs rules: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength). ```javascript // bad @@ -1776,6 +1832,8 @@ Other Style Guides - [19.1](#19.1) Leading commas: **Nope.** eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html). + + jscs rules: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak). ```javascript // bad @@ -1812,6 +1870,8 @@ Other Style Guides - [19.2](#19.2) Additional trailing comma: **Yup.** eslint rules: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html). + + jscs rules: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma). > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. @@ -1862,6 +1922,8 @@ Other Style Guides - [20.1](#20.1) **Yup.** eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html). + + jscs rules: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons). ```javascript // bad @@ -1986,6 +2048,8 @@ Other Style Guides - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html). + + jscs rules: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers). ```javascript // bad @@ -2001,6 +2065,8 @@ Other Style Guides - [22.3](#22.3) Use PascalCase when naming constructors or classes. eslint rules: [`new-cap`](http://eslint.org/docs/rules/new-cap.html). + + jscs rules: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors). ```javascript // bad @@ -2027,6 +2093,8 @@ Other Style Guides - [22.4](#22.4) Use a leading underscore `_` when naming private properties. eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html). + + jscs rules: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores). ```javascript // bad @@ -2039,6 +2107,8 @@ Other Style Guides - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. + jscs rules: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes). + ```javascript // bad function foo() { @@ -2197,6 +2267,8 @@ Other Style Guides ## jQuery - [25.1](#25.1) Prefix jQuery object variables with a `$`. + + jscs rules: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment). ```javascript // bad From 56ea6c7351819e51dfe80c0cbb9e9c2eab093090 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Sat, 16 Jan 2016 22:27:41 -0500 Subject: [PATCH 0014/1167] remove specific rule values in text --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 209840be36..6def9f3adb 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,7 @@ Other Style Guides eslint rules: [`quote-props`](http://eslint.org/docs/rules/quote-props.html). - jscs rules: [`disallowQuotedKeysInObjects: "allExcept": ["reserved"]`](http://jscs.info/rule/disallowQuotedKeysInObjects). + jscs rules: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects). ```javascript // bad @@ -451,7 +451,7 @@ Other Style Guides eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html). - jscs rules: [`validateQuoteMarks: "'"`](http://jscs.info/rule/validateQuoteMarks). + jscs rules: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks). ```javascript // bad @@ -1488,7 +1488,7 @@ Other Style Guides eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html). - jscs rules: [`validateIndentation: 2`](http://jscs.info/rule/validateIndentation). + jscs rules: [`validateIndentation`](http://jscs.info/rule/validateIndentation). ```javascript // bad From 93a957f4f63c076992c6cc487dcb1cc79c31f79d Mon Sep 17 00:00:00 2001 From: Kevin Ivan Date: Sun, 17 Jan 2016 14:55:16 +0100 Subject: [PATCH 0015/1167] fix typo --- react/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index ba23784e1a..eaddfceb2c 100644 --- a/react/README.md +++ b/react/README.md @@ -268,7 +268,7 @@ - Bind event handlers for the render method in the constructor. - > Why? A bind call in a the render path creates a brand new function on every single render. + > Why? A bind call in the render path creates a brand new function on every single render. eslint rules: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md). From 586b7d9dfa95457da237318e7d83cbfa2d620921 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 17 Jan 2016 18:10:42 -0800 Subject: [PATCH 0016/1167] [docs] remove trailing whitespace --- README.md | 72 +++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 6def9f3adb..8b6feb7f12 100644 --- a/README.md +++ b/README.md @@ -108,9 +108,9 @@ Other Style Guides > Why? `let` is block-scoped rather than function-scoped like `var`. eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html). - + jscs rules: [`disallowVar`](http://jscs.info/rule/disallowVar). - + ```javascript // bad var count = 1; @@ -222,7 +222,7 @@ Other Style Guides - [3.5](#3.5) Use object method shorthand. eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). - + jscs rules: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals). ```javascript @@ -251,9 +251,9 @@ Other Style Guides > Why? It is shorter to write and descriptive. eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). - + jscs rules: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals). - + ```javascript const lukeSkywalker = 'Luke Skywalker'; @@ -302,9 +302,9 @@ Other Style Guides > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. eslint rules: [`quote-props`](http://eslint.org/docs/rules/quote-props.html). - + jscs rules: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects). - + ```javascript // bad const bad = { @@ -379,7 +379,7 @@ Other Style Guides - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. > Why? Destructuring saves you from creating temporary references for those properties. - + jscs rules: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring). ```javascript @@ -406,7 +406,7 @@ Other Style Guides - [5.2](#5.2) Use array destructuring. jscs rules: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring). - + ```javascript const arr = [1, 2, 3, 4]; @@ -450,9 +450,9 @@ Other Style Guides - [6.1](#6.1) Use single quotes `''` for strings. eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html). - + jscs rules: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks). - + ```javascript // bad const name = "Capt. Janeway"; @@ -486,7 +486,7 @@ Other Style Guides > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html). - + jscs rules: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings). ```javascript @@ -515,7 +515,7 @@ Other Style Guides - [7.1](#7.1) Use function declarations instead of function expressions. > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. - + jscs rules: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations). ```javascript @@ -535,7 +535,7 @@ Other Style Guides eslint rules: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html). jscs rules: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE). - + ```javascript // immediately-invoked function expression (IIFE) (function () { @@ -736,7 +736,7 @@ Other Style Guides > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration. eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html). - + jscs rules: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions). ```javascript @@ -760,7 +760,7 @@ Other Style Guides > Why not? If you plan on returning an object. eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html). - + jscs rules: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions). ```javascript @@ -804,9 +804,9 @@ Other Style Guides > Why? Less visual clutter. eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html). - + jscs rules: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam). - + ```js // bad [1, 2, 3].map((x) => x * x); @@ -1038,7 +1038,7 @@ Other Style Guides - [12.1](#12.1) Use dot notation when accessing properties. eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html). - + jscs rules: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation). ```javascript @@ -1089,7 +1089,7 @@ Other Style Guides > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html). - + jscs rules: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl). ```javascript @@ -1355,7 +1355,7 @@ Other Style Guides eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html). jscs rules: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements). - + ```javascript // bad if (test) { @@ -1487,7 +1487,7 @@ Other Style Guides - [18.1](#18.1) Use soft tabs set to 2 spaces. eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html). - + jscs rules: [`validateIndentation`](http://jscs.info/rule/validateIndentation). ```javascript @@ -1568,7 +1568,7 @@ Other Style Guides - [18.4](#18.4) Set off operators with spaces. eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html). - + jscs rules: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators). ```javascript @@ -1705,7 +1705,7 @@ Other Style Guides - [18.8](#18.8) Do not pad your blocks with blank lines. eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html). - + jscs rules: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks). ```javascript @@ -1741,7 +1741,7 @@ Other Style Guides - [18.9](#18.9) Do not add spaces inside parentheses. eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html). - + jscs rules: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses). ```javascript @@ -1769,7 +1769,7 @@ Other Style Guides - [18.10](#18.10) Do not add spaces inside brackets. eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html). - + jscs rules: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets). ```javascript @@ -1785,7 +1785,7 @@ Other Style Guides - [18.11](#18.11) Add spaces inside curly braces. eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html). - + jscs rules: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets). ```javascript @@ -1801,7 +1801,7 @@ Other Style Guides > Why? This ensures readability and maintainability. eslint rules: [`max-len`](http://eslint.org/docs/rules/max-len.html). - + jscs rules: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength). ```javascript @@ -1832,7 +1832,7 @@ Other Style Guides - [19.1](#19.1) Leading commas: **Nope.** eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html). - + jscs rules: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak). ```javascript @@ -1870,7 +1870,7 @@ Other Style Guides - [19.2](#19.2) Additional trailing comma: **Yup.** eslint rules: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html). - + jscs rules: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma). > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. @@ -1922,7 +1922,7 @@ Other Style Guides - [20.1](#20.1) **Yup.** eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html). - + jscs rules: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons). ```javascript @@ -2048,7 +2048,7 @@ Other Style Guides - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html). - + jscs rules: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers). ```javascript @@ -2063,9 +2063,9 @@ Other Style Guides ``` - [22.3](#22.3) Use PascalCase when naming constructors or classes. - + eslint rules: [`new-cap`](http://eslint.org/docs/rules/new-cap.html). - + jscs rules: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors). ```javascript @@ -2093,7 +2093,7 @@ Other Style Guides - [22.4](#22.4) Use a leading underscore `_` when naming private properties. eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html). - + jscs rules: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores). ```javascript @@ -2267,7 +2267,7 @@ Other Style Guides ## jQuery - [25.1](#25.1) Prefix jQuery object variables with a `$`. - + jscs rules: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment). ```javascript From 018dd6e35940900f277e89008a5c523b7b27f3b3 Mon Sep 17 00:00:00 2001 From: Svein Halvor Halvorsen Date: Tue, 19 Jan 2016 13:07:37 +0100 Subject: [PATCH 0017/1167] arrow-parens --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b6feb7f12..c4e2a278ba 100644 --- a/README.md +++ b/README.md @@ -1018,7 +1018,7 @@ Other Style Guides // good let sum = 0; - numbers.forEach((num) => sum += num); + numbers.forEach(num => sum += num); sum === 15; // best (use the functional force) From fb65b9ae04d6215db4825fc07e4f90eac07b4ed7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 19 Jan 2016 10:15:36 -0800 Subject: [PATCH 0018/1167] [guide] fix a few IIFE examples --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c4e2a278ba..b5b4494d06 100644 --- a/README.md +++ b/README.md @@ -1936,13 +1936,13 @@ Other Style Guides (() => { const name = 'Skywalker'; return name; - })(); + }()); // good (guards against the function becoming an argument when two files with IIFEs are concatenated) ;(() => { const name = 'Skywalker'; return name; - })(); + }()); ``` [Read more](http://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214%237365214). From 45834dde1cf87f47759fa1d404b32d174c0d9c0a Mon Sep 17 00:00:00 2001 From: Juan Lulkin Date: Wed, 20 Jan 2016 16:53:59 +0200 Subject: [PATCH 0019/1167] Favour stateless functions over classes when there's no state --- react/README.md | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/react/README.md b/react/README.md index eaddfceb2c..4c48209ae1 100644 --- a/react/README.md +++ b/react/README.md @@ -5,7 +5,7 @@ ## Table of Contents 1. [Basic Rules](#basic-rules) - 1. [Class vs `React.createClass`](#class-vs-reactcreateclass) + 1. [Class vs `React.createClass` vs stateless](#class-vs-reactcreateclass-vs-stateless) 1. [Naming](#naming) 1. [Declaration](#declaration) 1. [Alignment](#alignment) @@ -27,25 +27,44 @@ ## Class vs `React.createClass` - - Use `class extends React.Component` unless you have a very good reason to use mixins. + - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint rules: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md). ```javascript // bad const Listing = React.createClass({ - render() { - return
; + // ... + render: function() { + return
{ this.state.hello }
; } }); // good class Listing extends React.Component { + // ... render() { - return
; + return
{ this.state.hello }
; } } ``` + + And if you don't have state or refs, prefer functions over classes: + + ```javascript + + // bad + class Listing extends React.Component { + render() { + return
{ this.props.hello }
; + } + } + + // good + function Listing({ hello }){ + return
{ hello }
; + } + ``` ## Naming From a568c7cf18f444cc4039fd6866d39b793926e54c Mon Sep 17 00:00:00 2001 From: Juan Lulkin Date: Wed, 20 Jan 2016 19:10:20 +0200 Subject: [PATCH 0020/1167] Remove space from jsx literal and add space to function definition According to PR comments. --- react/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/react/README.md b/react/README.md index 4c48209ae1..7cc499313e 100644 --- a/react/README.md +++ b/react/README.md @@ -36,7 +36,7 @@ const Listing = React.createClass({ // ... render: function() { - return
{ this.state.hello }
; + return
{this.state.hello}
; } }); @@ -44,7 +44,7 @@ class Listing extends React.Component { // ... render() { - return
{ this.state.hello }
; + return
{this.state.hello}
; } } ``` @@ -56,13 +56,13 @@ // bad class Listing extends React.Component { render() { - return
{ this.props.hello }
; + return
{this.props.hello}
; } } // good - function Listing({ hello }){ - return
{ hello }
; + function Listing ({ hello }) { + return
{hello}
; } ``` From 4d2578cc83affc21fbddfa3c7753b0c05e0205fb Mon Sep 17 00:00:00 2001 From: Juan Lulkin Date: Wed, 20 Jan 2016 22:36:11 +0200 Subject: [PATCH 0021/1167] Fix PR comments - Space between function name and args; - use `render(){}` syntax in object literal; - Fix link to section; --- react/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/react/README.md b/react/README.md index 7cc499313e..e551172952 100644 --- a/react/README.md +++ b/react/README.md @@ -25,7 +25,7 @@ - Always use JSX syntax. - Do not use `React.createElement` unless you're initializing the app from a file that is not JSX. -## Class vs `React.createClass` +## Class vs `React.createClass` vs stateless - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. @@ -35,7 +35,7 @@ // bad const Listing = React.createClass({ // ... - render: function() { + render() { return
{this.state.hello}
; } }); @@ -61,7 +61,7 @@ } // good - function Listing ({ hello }) { + function Listing({ hello }) { return
{hello}
; } ``` From 36765e4d88ca4d20bb614f538f324c1319bc3f56 Mon Sep 17 00:00:00 2001 From: Brett Jurgens Date: Wed, 20 Jan 2016 15:13:31 -0600 Subject: [PATCH 0022/1167] add avant to users --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b5b4494d06..73c1a73997 100644 --- a/README.md +++ b/README.md @@ -2482,6 +2482,7 @@ Other Style Guides - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript) - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript) - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript) + - **Avant**: [avantcredit/javascript](https://github.com/avantcredit/javascript) - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/) - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript) From fb3c4cac200861f2e6dd77e8bf7f29ce9be02d5e Mon Sep 17 00:00:00 2001 From: Rick Yeh Date: Thu, 21 Jan 2016 22:54:27 -0800 Subject: [PATCH 0023/1167] Fixed minor capitalization change in Hoisting Not sure if it's an actual fix, but just noticed this was the only comment that had capitalization that wasn't a proper noun --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 73c1a73997..5fefffe5b7 100644 --- a/README.md +++ b/README.md @@ -1196,7 +1196,7 @@ Other Style Guides var declaredButNotAssigned = true; } - // The interpreter is hoisting the variable + // the interpreter is hoisting the variable // declaration to the top of the scope, // which means our example could be rewritten as: function example() { From 2c9833fbc2fdc455bcdd4781de389c03f635d51e Mon Sep 17 00:00:00 2001 From: David Sorrentino Date: Fri, 22 Jan 2016 11:45:56 +0100 Subject: [PATCH 0024/1167] add WeBox Studio to the organizations list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5fefffe5b7..1d5e4982ea 100644 --- a/README.md +++ b/README.md @@ -2535,6 +2535,7 @@ Other Style Guides - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide) + - **WeBox Studio**: [weboxstudio/javascript](https://github.com/weboxstudio/javascript) - **Weggo**: [Weggo/javascript](https://github.com/Weggo/javascript) - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript) - **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript) From c25dbac620b258c4421251bc403fffa1051de61e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 22 Jan 2016 16:27:43 -0800 Subject: [PATCH 0025/1167] v4.0.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 8 ++++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 0cbe0e1357..e9d0220666 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,11 @@ +4.0.0 / 2016-01-22 +================== + - [breaking] require outer IIFE wrapping; flesh out guide section + - [minor] Add missing `arrow-body-style`, `prefer-template` rules (#678) + - [minor] Add `prefer-arrow-callback` to ES6 rules (to match the guide) (#677) + - [Tests] run `npm run lint` as part of tests; fix errors + - [Tests] use `parallelshell` to parallelize npm run-scripts + 3.1.0 / 2016-01-07 ================== - [minor] Allow multiple stateless components in a single file diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 56b15f54f5..63439f6b62 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "3.1.0", + "version": "4.0.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 02e1b4e3959f0580ef5d1921169f3d2fbfab3c41 Mon Sep 17 00:00:00 2001 From: Daniel Russell Date: Sun, 24 Jan 2016 20:52:24 -0800 Subject: [PATCH 0026/1167] Fixed capitalization Bitshift changed to bitshift --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d5e4982ea..e26f871164 100644 --- a/README.md +++ b/README.md @@ -2003,7 +2003,7 @@ Other Style Guides const val = inputValue >> 0; ``` - - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: + - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: ```javascript 2147483647 >> 0 //=> 2147483647 From 2c06d87d86d7a52d8807c9fc045f9966ef433cc4 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Mon, 25 Jan 2016 21:46:23 -0800 Subject: [PATCH 0027/1167] [rule links] reduce visual clutter --- README.md | 238 +++++++++++------------------------------------------- 1 file changed, 46 insertions(+), 192 deletions(-) diff --git a/README.md b/README.md index e26f871164..bb371499ad 100644 --- a/README.md +++ b/README.md @@ -87,12 +87,10 @@ Other Style Guides ## References - - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. + - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html) > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. - eslint rules: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html). - ```javascript // bad var a = 1; @@ -103,14 +101,10 @@ Other Style Guides const b = 2; ``` - - [2.2](#2.2) If you must reassign references, use `let` instead of `var`. + - [2.2](#2.2) If you must reassign references, use `let` instead of `var`. [`no-var`](http://eslint.org/docs/rules/no-var.html), [`disallowVar`](http://jscs.info/rule/disallowVar) > Why? `let` is block-scoped rather than function-scoped like `var`. - eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html). - - jscs rules: [`disallowVar`](http://jscs.info/rule/disallowVar). - ```javascript // bad var count = 1; @@ -141,9 +135,7 @@ Other Style Guides ## Objects - - [3.1](#3.1) Use the literal syntax for object creation. - - eslint rules: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html). + - [3.1](#3.1) Use the literal syntax for object creation. [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html) ```javascript // bad @@ -153,9 +145,7 @@ Other Style Guides const item = {}; ``` - - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. - - jscs rules: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames). + - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -171,9 +161,7 @@ Other Style Guides }; ``` - - [3.3](#3.3) Use readable synonyms in place of reserved words. - - jscs rules: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames). + - [3.3](#3.3) Use readable synonyms in place of reserved words. [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -219,11 +207,7 @@ Other Style Guides ``` - - [3.5](#3.5) Use object method shorthand. - - eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). - - jscs rules: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals). + - [3.5](#3.5) Use object method shorthand. [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html), [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) ```javascript // bad @@ -246,14 +230,10 @@ Other Style Guides ``` - - [3.6](#3.6) Use property value shorthand. + - [3.6](#3.6) Use property value shorthand. [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html), [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) > Why? It is shorter to write and descriptive. - eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). - - jscs rules: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals). - ```javascript const lukeSkywalker = 'Luke Skywalker'; @@ -297,14 +277,10 @@ Other Style Guides }; ``` - - [3.8](#3.8) Only quote properties that are invalid identifiers. + - [3.8](#3.8) Only quote properties that are invalid identifiers. [`quote-props`](http://eslint.org/docs/rules/quote-props.html), [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. - eslint rules: [`quote-props`](http://eslint.org/docs/rules/quote-props.html). - - jscs rules: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects). - ```javascript // bad const bad = { @@ -325,9 +301,7 @@ Other Style Guides ## Arrays - - [4.1](#4.1) Use the literal syntax for array creation. - - eslint rules: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html). + - [4.1](#4.1) Use the literal syntax for array creation. [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html) ```javascript // bad @@ -376,12 +350,10 @@ Other Style Guides ## Destructuring - - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. + - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) > Why? Destructuring saves you from creating temporary references for those properties. - jscs rules: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring). - ```javascript // bad function getFullName(user) { @@ -403,9 +375,7 @@ Other Style Guides } ``` - - [5.2](#5.2) Use array destructuring. - - jscs rules: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring). + - [5.2](#5.2) Use array destructuring. [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) ```javascript const arr = [1, 2, 3, 4]; @@ -447,11 +417,7 @@ Other Style Guides ## Strings - - [6.1](#6.1) Use single quotes `''` for strings. - - eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html). - - jscs rules: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks). + - [6.1](#6.1) Use single quotes `''` for strings. [`quotes`](http://eslint.org/docs/rules/quotes.html), [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) ```javascript // bad @@ -481,14 +447,10 @@ Other Style Guides ``` - - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. + - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html), [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. - eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html). - - jscs rules: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings). - ```javascript // bad function sayHi(name) { @@ -512,12 +474,10 @@ Other Style Guides ## Functions - - [7.1](#7.1) Use function declarations instead of function expressions. + - [7.1](#7.1) Use function declarations instead of function expressions. [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. - jscs rules: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations). - ```javascript // bad const foo = function () { @@ -528,14 +488,10 @@ Other Style Guides } ``` - - [7.2](#7.2) Immediately invoked function expressions: + - [7.2](#7.2) Immediately invoked function expressions: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html), [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) > Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE. - eslint rules: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html). - - jscs rules: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE). - ```javascript // immediately-invoked function expression (IIFE) (function () { @@ -543,9 +499,7 @@ Other Style Guides }()); ``` - - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. - - eslint rules: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html). + - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html) - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). @@ -682,12 +636,10 @@ Other Style Guides const y = function a() {}; ``` - - [7.12](#7.12) Never mutate parameters. + - [7.12](#7.12) Never mutate parameters. [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller. - eslint rules: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html). - ```javascript // bad function f1(obj) { @@ -700,12 +652,10 @@ Other Style Guides }; ``` - - [7.13](#7.13) Never reassign parameters. + - [7.13](#7.13) Never reassign parameters. [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8. - eslint rules: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html). - ```javascript // bad function f1(a) { @@ -729,15 +679,11 @@ Other Style Guides ## Arrow Functions - - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation. + - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation. [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html), [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) > Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax. - > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration. - - eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html). - - jscs rules: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions). + > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.. ```javascript // bad @@ -753,16 +699,12 @@ Other Style Guides }); ``` - - [8.2](#8.2) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. + - [8.2](#8.2) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html), [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions) > Why? Syntactic sugar. It reads well when multiple functions are chained together. > Why not? If you plan on returning an object. - eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html). - - jscs rules: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions). - ```javascript // good [1, 2, 3].map(number => `A string containing the ${number}.`); @@ -799,14 +741,10 @@ Other Style Guides ``` - - [8.4](#8.4) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. + - [8.4](#8.4) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) > Why? Less visual clutter. - eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html). - - jscs rules: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam). - ```js // bad [1, 2, 3].map((x) => x * x); @@ -999,12 +937,10 @@ Other Style Guides ## Iterators and Generators - - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. + - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects. - eslint rules: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html). - ```javascript const numbers = [1, 2, 3, 4, 5]; @@ -1035,11 +971,7 @@ Other Style Guides ## Properties - - [12.1](#12.1) Use dot notation when accessing properties. - - eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html). - - jscs rules: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation). + - [12.1](#12.1) Use dot notation when accessing properties. [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html), [`requireDotNotation`](http://jscs.info/rule/requireDotNotation) ```javascript const luke = { @@ -1084,14 +1016,10 @@ Other Style Guides const superPower = new SuperPower(); ``` - - [13.2](#13.2) Use one `const` declaration per variable. + - [13.2](#13.2) Use one `const` declaration per variable. [`one-var`](http://eslint.org/docs/rules/one-var.html), [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. - eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html). - - jscs rules: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl). - ```javascript // bad const items = getItems(), @@ -1274,12 +1202,10 @@ Other Style Guides ## Comparison Operators & Equality - - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. + - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html) - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: - eslint rules: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html). - + **Objects** evaluate to **true** + **Undefined** evaluates to **false** + **Null** evaluates to **false** @@ -1350,11 +1276,7 @@ Other Style Guides ``` - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your - `if` block's closing brace. - - eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html). - - jscs rules: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements). + `if` block's closing brace. [`brace-style`](http://eslint.org/docs/rules/brace-style.html), [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements) ```javascript // bad @@ -1484,11 +1406,7 @@ Other Style Guides ## Whitespace - - [18.1](#18.1) Use soft tabs set to 2 spaces. - - eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html). - - jscs rules: [`validateIndentation`](http://jscs.info/rule/validateIndentation). + - [18.1](#18.1) Use soft tabs set to 2 spaces. [`indent`](http://eslint.org/docs/rules/indent.html), [`validateIndentation`](http://jscs.info/rule/validateIndentation) ```javascript // bad @@ -1507,11 +1425,7 @@ Other Style Guides } ``` - - [18.2](#18.2) Place 1 space before the leading brace. - - eslint rules: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html). - - jscs rules: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements). + - [18.2](#18.2) Place 1 space before the leading brace. [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html), [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements). ```javascript // bad @@ -1537,11 +1451,7 @@ Other Style Guides }); ``` - - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. - - eslint rules: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html). - - jscs rules: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords). + - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html), [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) ```javascript // bad @@ -1565,11 +1475,7 @@ Other Style Guides } ``` - - [18.4](#18.4) Set off operators with spaces. - - eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html). - - jscs rules: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators). + - [18.4](#18.4) Set off operators with spaces. [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html), [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) ```javascript // bad @@ -1643,9 +1549,7 @@ Other Style Guides .call(tron.led); ``` - - [18.7](#18.7) Leave a blank line after blocks and before the next statement. - - jscs rules: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks). + - [18.7](#18.7) Leave a blank line after blocks and before the next statement. [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) ```javascript // bad @@ -1702,11 +1606,7 @@ Other Style Guides return arr; ``` - - [18.8](#18.8) Do not pad your blocks with blank lines. - - eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html). - - jscs rules: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks). + - [18.8](#18.8) Do not pad your blocks with blank lines. [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html), [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) ```javascript // bad @@ -1738,11 +1638,7 @@ Other Style Guides } ``` - - [18.9](#18.9) Do not add spaces inside parentheses. - - eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html). - - jscs rules: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses). + - [18.9](#18.9) Do not add spaces inside parentheses. [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html), [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) ```javascript // bad @@ -1766,11 +1662,7 @@ Other Style Guides } ``` - - [18.10](#18.10) Do not add spaces inside brackets. - - eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html). - - jscs rules: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets). + - [18.10](#18.10) Do not add spaces inside brackets. [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html), [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets). ```javascript // bad @@ -1782,11 +1674,7 @@ Other Style Guides console.log(foo[0]); ``` - - [18.11](#18.11) Add spaces inside curly braces. - - eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html). - - jscs rules: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets). + - [18.11](#18.11) Add spaces inside curly braces. [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html), [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets) ```javascript // bad @@ -1796,14 +1684,10 @@ Other Style Guides const foo = { clark: 'kent' }; ``` - - [18.12](#18.12) Avoid having lines of code that are longer than 100 characters (including whitespace). + - [18.12](#18.12) Avoid having lines of code that are longer than 100 characters (including whitespace). [`max-len`](http://eslint.org/docs/rules/max-len.html), [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) > Why? This ensures readability and maintainability. - eslint rules: [`max-len`](http://eslint.org/docs/rules/max-len.html). - - jscs rules: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength). - ```javascript // bad const foo = 'Whatever national crop flips the window. The cartoon reverts within the screw. Whatever wizard constrains a helpful ally. The counterpart ascends!'; @@ -1829,11 +1713,7 @@ Other Style Guides ## Commas - - [19.1](#19.1) Leading commas: **Nope.** - - eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html). - - jscs rules: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak). + - [19.1](#19.1) Leading commas: **Nope.** [`comma-style`](http://eslint.org/docs/rules/comma-style.html), [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) ```javascript // bad @@ -1867,11 +1747,7 @@ Other Style Guides }; ``` - - [19.2](#19.2) Additional trailing comma: **Yup.** - - eslint rules: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html). - - jscs rules: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma). + - [19.2](#19.2) Additional trailing comma: **Yup.** [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html), [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. @@ -1919,11 +1795,7 @@ Other Style Guides ## Semicolons - - [20.1](#20.1) **Yup.** - - eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html). - - jscs rules: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons). + - [20.1](#20.1) **Yup.** [`semi`](http://eslint.org/docs/rules/semi.html), [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) ```javascript // bad @@ -1965,9 +1837,7 @@ Other Style Guides const totalScore = String(this.reviewScore); ``` - - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. - - eslint rules: [`radix`](http://eslint.org/docs/rules/radix). + - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. [`radix`](http://eslint.org/docs/rules/radix) ```javascript const inputValue = '4'; @@ -2045,11 +1915,7 @@ Other Style Guides } ``` - - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. - - eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html). - - jscs rules: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers). + - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. [`camelcase`](http://eslint.org/docs/rules/camelcase.html), `requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) ```javascript // bad @@ -2062,11 +1928,7 @@ Other Style Guides function thisIsMyFunction() {} ``` - - [22.3](#22.3) Use PascalCase when naming constructors or classes. - - eslint rules: [`new-cap`](http://eslint.org/docs/rules/new-cap.html). - - jscs rules: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors). + - [22.3](#22.3) Use PascalCase when naming constructors or classes. [`new-cap`](http://eslint.org/docs/rules/new-cap.html), [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) ```javascript // bad @@ -2090,11 +1952,7 @@ Other Style Guides }); ``` - - [22.4](#22.4) Use a leading underscore `_` when naming private properties. - - eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html). - - jscs rules: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores). + - [22.4](#22.4) Use a leading underscore `_` when naming private properties. [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html), [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) ```javascript // bad @@ -2105,9 +1963,7 @@ Other Style Guides this._firstName = 'Panda'; ``` - - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. - - jscs rules: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes). + - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) ```javascript // bad @@ -2266,9 +2122,7 @@ Other Style Guides ## jQuery - - [25.1](#25.1) Prefix jQuery object variables with a `$`. - - jscs rules: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment). + - [25.1](#25.1) Prefix jQuery object variables with a `$`. [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) ```javascript // bad From d852f5190eaf9e5a06e5463723249816583511d8 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Mon, 25 Jan 2016 22:19:01 -0800 Subject: [PATCH 0028/1167] [react][rule links] condense lines --- react/README.md | 50 ++++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/react/README.md b/react/README.md index e551172952..8da5cdc7ce 100644 --- a/react/README.md +++ b/react/README.md @@ -27,9 +27,7 @@ ## Class vs `React.createClass` vs stateless - - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. - - eslint rules: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md). + - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) ```javascript // bad @@ -48,9 +46,9 @@ } } ``` - + And if you don't have state or refs, prefer functions over classes: - + ```javascript // bad @@ -59,7 +57,7 @@ return
{this.props.hello}
; } } - + // good function Listing({ hello }) { return
{hello}
; @@ -70,9 +68,7 @@ - **Extensions**: Use `.jsx` extension for React components. - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`. - - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. - - eslint rules: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md). + - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) ```javascript // bad @@ -119,9 +115,7 @@ ## Alignment - - Follow these alignment styles for JSX syntax - - eslint rules: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md). + - Follow these alignment styles for JSX syntax. [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) ```javascript // bad @@ -148,13 +142,11 @@ ## Quotes - - Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. + - Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes) > Why? JSX attributes [can't contain escaped quotes](http://eslint.org/docs/rules/jsx-quotes), so double quotes make conjunctions like `"don't"` easier to type. > Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention. - eslint rules: [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes). - ```javascript // bad @@ -206,9 +198,7 @@ /> ``` - - Omit the value of the prop when it is explicitly `true`. - - eslint rules: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md). + - Omit the value of the prop when it is explicitly `true`. [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md) ```javascript // bad @@ -224,9 +214,7 @@ ## Parentheses - - Wrap JSX tags in parentheses when they span more than one line. - - eslint rules: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md). + - Wrap JSX tags in parentheses when they span more than one line. [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) ```javascript // bad @@ -254,9 +242,7 @@ ## Tags - - Always self-close tags that have no children. - - eslint rules: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md). + - Always self-close tags that have no children. [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md) ```javascript // bad @@ -266,9 +252,7 @@ ``` - - If your component has multi-line properties, close its tag on a new line. - - eslint rules: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md). + - If your component has multi-line properties, close its tag on a new line. [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) ```javascript // bad @@ -285,12 +269,10 @@ ## Methods - - Bind event handlers for the render method in the constructor. + - Bind event handlers for the render method in the constructor. [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md) > Why? A bind call in the render path creates a brand new function on every single render. - eslint rules: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md). - ```javascript // bad class extends React.Component { @@ -393,7 +375,7 @@ export default Link; ``` - - Ordering for `React.createClass`: + - Ordering for `React.createClass`: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md) 1. `displayName` 1. `propTypes` @@ -417,16 +399,12 @@ 1. *Optional render methods* like `renderNavigation()` or `renderProfilePicture()` 1. `render` - eslint rules: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md). - ## `isMounted` - - Do not use `isMounted`. + - Do not use `isMounted`. [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md) > Why? [`isMounted` is an anti-pattern][anti-pattern], is not available when using ES6 classes, and is on its way to being officially deprecated. [anti-pattern]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html - eslint rules: [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md). - **[⬆ back to top](#table-of-contents)** From 992a9cea58ddde54354d6e53800de97b93bfe9f4 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Mon, 25 Jan 2016 22:23:16 -0800 Subject: [PATCH 0029/1167] [react][rule links] add eslint labels back --- react/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/react/README.md b/react/README.md index 8da5cdc7ce..96edd521e3 100644 --- a/react/README.md +++ b/react/README.md @@ -21,13 +21,13 @@ ## Basic Rules - Only include one React component per file. - - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file. eslint rule: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless). + - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file. eslint: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless). - Always use JSX syntax. - Do not use `React.createElement` unless you're initializing the app from a file that is not JSX. ## Class vs `React.createClass` vs stateless - - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) + - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) ```javascript // bad @@ -68,7 +68,7 @@ - **Extensions**: Use `.jsx` extension for React components. - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`. - - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) + - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) ```javascript // bad @@ -115,7 +115,7 @@ ## Alignment - - Follow these alignment styles for JSX syntax. [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) + - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) ```javascript // bad @@ -142,7 +142,7 @@ ## Quotes - - Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes) + - Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. eslint: [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes) > Why? JSX attributes [can't contain escaped quotes](http://eslint.org/docs/rules/jsx-quotes), so double quotes make conjunctions like `"don't"` easier to type. > Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention. @@ -198,7 +198,7 @@ /> ``` - - Omit the value of the prop when it is explicitly `true`. [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md) + - Omit the value of the prop when it is explicitly `true`. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md) ```javascript // bad @@ -214,7 +214,7 @@ ## Parentheses - - Wrap JSX tags in parentheses when they span more than one line. [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) + - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) ```javascript // bad @@ -242,7 +242,7 @@ ## Tags - - Always self-close tags that have no children. [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md) + - Always self-close tags that have no children. eslint: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md) ```javascript // bad @@ -252,7 +252,7 @@ ``` - - If your component has multi-line properties, close its tag on a new line. [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) + - If your component has multi-line properties, close its tag on a new line. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) ```javascript // bad @@ -269,7 +269,7 @@ ## Methods - - Bind event handlers for the render method in the constructor. [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md) + - Bind event handlers for the render method in the constructor. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md) > Why? A bind call in the render path creates a brand new function on every single render. @@ -375,7 +375,7 @@ export default Link; ``` - - Ordering for `React.createClass`: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md) + - Ordering for `React.createClass`: eslint: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md) 1. `displayName` 1. `propTypes` @@ -401,7 +401,7 @@ ## `isMounted` - - Do not use `isMounted`. [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md) + - Do not use `isMounted`. eslint: [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md) > Why? [`isMounted` is an anti-pattern][anti-pattern], is not available when using ES6 classes, and is on its way to being officially deprecated. From 7293a0f02dd0d9b35e9fb1e927be568157bbf7af Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Mon, 25 Jan 2016 22:34:39 -0800 Subject: [PATCH 0030/1167] [rule links] add labels back --- README.md | 90 +++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index bb371499ad..3abec0b1e9 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Other Style Guides ## References - - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html) + - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. eslint: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html) > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. @@ -101,7 +101,7 @@ Other Style Guides const b = 2; ``` - - [2.2](#2.2) If you must reassign references, use `let` instead of `var`. [`no-var`](http://eslint.org/docs/rules/no-var.html), [`disallowVar`](http://jscs.info/rule/disallowVar) + - [2.2](#2.2) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](http://eslint.org/docs/rules/no-var.html) jscs: [`disallowVar`](http://jscs.info/rule/disallowVar) > Why? `let` is block-scoped rather than function-scoped like `var`. @@ -135,7 +135,7 @@ Other Style Guides ## Objects - - [3.1](#3.1) Use the literal syntax for object creation. [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html) + - [3.1](#3.1) Use the literal syntax for object creation. eslint: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html) ```javascript // bad @@ -145,7 +145,7 @@ Other Style Guides const item = {}; ``` - - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) + - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -161,7 +161,7 @@ Other Style Guides }; ``` - - [3.3](#3.3) Use readable synonyms in place of reserved words. [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) + - [3.3](#3.3) Use readable synonyms in place of reserved words. jscs: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -207,7 +207,7 @@ Other Style Guides ``` - - [3.5](#3.5) Use object method shorthand. [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html), [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + - [3.5](#3.5) Use object method shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) ```javascript // bad @@ -230,7 +230,7 @@ Other Style Guides ``` - - [3.6](#3.6) Use property value shorthand. [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html), [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + - [3.6](#3.6) Use property value shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) > Why? It is shorter to write and descriptive. @@ -277,7 +277,7 @@ Other Style Guides }; ``` - - [3.8](#3.8) Only quote properties that are invalid identifiers. [`quote-props`](http://eslint.org/docs/rules/quote-props.html), [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) + - [3.8](#3.8) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. @@ -301,7 +301,7 @@ Other Style Guides ## Arrays - - [4.1](#4.1) Use the literal syntax for array creation. [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html) + - [4.1](#4.1) Use the literal syntax for array creation. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html) ```javascript // bad @@ -350,7 +350,7 @@ Other Style Guides ## Destructuring - - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) + - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) > Why? Destructuring saves you from creating temporary references for those properties. @@ -375,7 +375,7 @@ Other Style Guides } ``` - - [5.2](#5.2) Use array destructuring. [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) + - [5.2](#5.2) Use array destructuring. jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) ```javascript const arr = [1, 2, 3, 4]; @@ -417,7 +417,7 @@ Other Style Guides ## Strings - - [6.1](#6.1) Use single quotes `''` for strings. [`quotes`](http://eslint.org/docs/rules/quotes.html), [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) + - [6.1](#6.1) Use single quotes `''` for strings. eslint: [`quotes`](http://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) ```javascript // bad @@ -447,7 +447,7 @@ Other Style Guides ``` - - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html), [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) + - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. @@ -474,7 +474,7 @@ Other Style Guides ## Functions - - [7.1](#7.1) Use function declarations instead of function expressions. [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) + - [7.1](#7.1) Use function declarations instead of function expressions. jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. @@ -488,7 +488,7 @@ Other Style Guides } ``` - - [7.2](#7.2) Immediately invoked function expressions: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html), [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) + - [7.2](#7.2) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) > 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. @@ -499,7 +499,7 @@ Other Style Guides }()); ``` - - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html) + - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html) - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). @@ -636,7 +636,7 @@ Other Style Guides const y = function a() {}; ``` - - [7.12](#7.12) Never mutate parameters. [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) + - [7.12](#7.12) Never mutate parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller. @@ -652,7 +652,7 @@ Other Style Guides }; ``` - - [7.13](#7.13) Never reassign parameters. [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) + - [7.13](#7.13) Never reassign parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8. @@ -679,7 +679,7 @@ Other Style Guides ## Arrow Functions - - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation. [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html), [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) + - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation. eslint: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) > 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. @@ -699,7 +699,7 @@ Other Style Guides }); ``` - - [8.2](#8.2) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html), [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions) + - [8.2](#8.2) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions) > Why? Syntactic sugar. It reads well when multiple functions are chained together. @@ -741,7 +741,7 @@ Other Style Guides ``` - - [8.4](#8.4) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) + - [8.4](#8.4) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) > Why? Less visual clutter. @@ -937,7 +937,7 @@ Other Style Guides ## Iterators and Generators - - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) + - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects. @@ -971,7 +971,7 @@ Other Style Guides ## Properties - - [12.1](#12.1) Use dot notation when accessing properties. [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html), [`requireDotNotation`](http://jscs.info/rule/requireDotNotation) + - [12.1](#12.1) Use dot notation when accessing properties. eslint: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html) jscs: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation) ```javascript const luke = { @@ -1016,7 +1016,7 @@ Other Style Guides const superPower = new SuperPower(); ``` - - [13.2](#13.2) Use one `const` declaration per variable. [`one-var`](http://eslint.org/docs/rules/one-var.html), [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) + - [13.2](#13.2) Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. @@ -1202,7 +1202,7 @@ Other Style Guides ## Comparison Operators & Equality - - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html) + - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. eslint: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html) - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: @@ -1276,7 +1276,7 @@ Other Style Guides ``` - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your - `if` block's closing brace. [`brace-style`](http://eslint.org/docs/rules/brace-style.html), [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements) + `if` block's closing brace. eslint: [`brace-style`](http://eslint.org/docs/rules/brace-style.html) jscs: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements) ```javascript // bad @@ -1406,7 +1406,7 @@ Other Style Guides ## Whitespace - - [18.1](#18.1) Use soft tabs set to 2 spaces. [`indent`](http://eslint.org/docs/rules/indent.html), [`validateIndentation`](http://jscs.info/rule/validateIndentation) + - [18.1](#18.1) Use soft tabs set to 2 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) ```javascript // bad @@ -1425,7 +1425,7 @@ Other Style Guides } ``` - - [18.2](#18.2) Place 1 space before the leading brace. [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html), [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements). + - [18.2](#18.2) Place 1 space before the leading brace. eslint: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html) jscs: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements) ```javascript // bad @@ -1451,7 +1451,7 @@ Other Style Guides }); ``` - - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html), [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) + - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) ```javascript // bad @@ -1475,7 +1475,7 @@ Other Style Guides } ``` - - [18.4](#18.4) Set off operators with spaces. [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html), [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) + - [18.4](#18.4) Set off operators with spaces. eslint: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html) jscs: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) ```javascript // bad @@ -1549,7 +1549,7 @@ Other Style Guides .call(tron.led); ``` - - [18.7](#18.7) Leave a blank line after blocks and before the next statement. [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) + - [18.7](#18.7) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) ```javascript // bad @@ -1606,7 +1606,7 @@ Other Style Guides return arr; ``` - - [18.8](#18.8) Do not pad your blocks with blank lines. [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html), [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) + - [18.8](#18.8) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html) jscs: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) ```javascript // bad @@ -1638,7 +1638,7 @@ Other Style Guides } ``` - - [18.9](#18.9) Do not add spaces inside parentheses. [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html), [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) + - [18.9](#18.9) Do not add spaces inside parentheses. eslint: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html) jscs: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) ```javascript // bad @@ -1662,7 +1662,7 @@ Other Style Guides } ``` - - [18.10](#18.10) Do not add spaces inside brackets. [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html), [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets). + - [18.10](#18.10) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html) jscs: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets) ```javascript // bad @@ -1674,7 +1674,7 @@ Other Style Guides console.log(foo[0]); ``` - - [18.11](#18.11) Add spaces inside curly braces. [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html), [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets) + - [18.11](#18.11) Add spaces inside curly braces. eslint: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets) ```javascript // bad @@ -1684,7 +1684,7 @@ Other Style Guides const foo = { clark: 'kent' }; ``` - - [18.12](#18.12) Avoid having lines of code that are longer than 100 characters (including whitespace). [`max-len`](http://eslint.org/docs/rules/max-len.html), [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) + - [18.12](#18.12) Avoid having lines of code that are longer than 100 characters (including whitespace). eslint: [`max-len`](http://eslint.org/docs/rules/max-len.html) jscs: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) > Why? This ensures readability and maintainability. @@ -1713,7 +1713,7 @@ Other Style Guides ## Commas - - [19.1](#19.1) Leading commas: **Nope.** [`comma-style`](http://eslint.org/docs/rules/comma-style.html), [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) + - [19.1](#19.1) Leading commas: **Nope.** eslint: [`comma-style`](http://eslint.org/docs/rules/comma-style.html) jscs: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) ```javascript // bad @@ -1747,7 +1747,7 @@ Other Style Guides }; ``` - - [19.2](#19.2) Additional trailing comma: **Yup.** [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html), [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) + - [19.2](#19.2) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. @@ -1795,7 +1795,7 @@ Other Style Guides ## Semicolons - - [20.1](#20.1) **Yup.** [`semi`](http://eslint.org/docs/rules/semi.html), [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) + - [20.1](#20.1) **Yup.** eslint: [`semi`](http://eslint.org/docs/rules/semi.html) jscs: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) ```javascript // bad @@ -1837,7 +1837,7 @@ Other Style Guides const totalScore = String(this.reviewScore); ``` - - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. [`radix`](http://eslint.org/docs/rules/radix) + - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](http://eslint.org/docs/rules/radix) ```javascript const inputValue = '4'; @@ -1915,7 +1915,7 @@ Other Style Guides } ``` - - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. [`camelcase`](http://eslint.org/docs/rules/camelcase.html), `requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) + - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](http://eslint.org/docs/rules/camelcase.html) jscs: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) ```javascript // bad @@ -1928,7 +1928,7 @@ Other Style Guides function thisIsMyFunction() {} ``` - - [22.3](#22.3) Use PascalCase when naming constructors or classes. [`new-cap`](http://eslint.org/docs/rules/new-cap.html), [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) + - [22.3](#22.3) Use PascalCase when naming constructors or classes. eslint: [`new-cap`](http://eslint.org/docs/rules/new-cap.html) jscs: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) ```javascript // bad @@ -1952,7 +1952,7 @@ Other Style Guides }); ``` - - [22.4](#22.4) Use a leading underscore `_` when naming private properties. [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html), [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) + - [22.4](#22.4) Use a leading underscore `_` when naming private properties. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) ```javascript // bad @@ -1963,7 +1963,7 @@ Other Style Guides this._firstName = 'Panda'; ``` - - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) + - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) ```javascript // bad @@ -2122,7 +2122,7 @@ Other Style Guides ## jQuery - - [25.1](#25.1) Prefix jQuery object variables with a `$`. [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) + - [25.1](#25.1) Prefix jQuery object variables with a `$`. jscs: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) ```javascript // bad From 94776c35ebdddae3fba49d1ddd56f109a70dd2c3 Mon Sep 17 00:00:00 2001 From: Matt Brennan Date: Tue, 26 Jan 2016 14:20:55 +0000 Subject: [PATCH 0031/1167] Remove language interpretable as an ableist slur --- react/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index 96edd521e3..ee9e32ca58 100644 --- a/react/README.md +++ b/react/README.md @@ -136,7 +136,7 @@ superLongParam="bar" anotherSuperLongParam="baz" > - + ``` From da1d031ff8479e57da013a03e482d429e68519b3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 26 Jan 2016 15:03:13 -0800 Subject: [PATCH 0032/1167] [guide] [react] add a note preferring normal functions for functional stateless components. --- react/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index ee9e32ca58..5ea9b5248c 100644 --- a/react/README.md +++ b/react/README.md @@ -47,7 +47,7 @@ } ``` - And if you don't have state or refs, prefer functions over classes: + And if you don't have state or refs, prefer normal functions (not arrow functions) over classes: ```javascript @@ -58,6 +58,11 @@ } } + // bad (since arrow functions do not have a "name" property) + const Listing = ({ hello }) => ( +
{hello}
+ ); + // good function Listing({ hello }) { return
{hello}
; From 760e50704cebff4fa07e237d50a10d4fd8b0234a Mon Sep 17 00:00:00 2001 From: Ethan Rubio Date: Tue, 26 Jan 2016 15:09:05 -0800 Subject: [PATCH 0033/1167] Fixed capitalization Fixed capitalization of ES6 to match the rest of the README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3abec0b1e9..0211792ca3 100644 --- a/README.md +++ b/README.md @@ -2193,7 +2193,7 @@ Other Style Guides ## ECMAScript 6 Styles - - [27.1](#27.1) This is a collection of links to the various es6 features. + - [27.1](#27.1) This is a collection of links to the various ES6 features. 1. [Arrow Functions](#arrow-functions) 1. [Classes](#constructors) From 79a6bfa101848a6d8e7af45abf2063982c838ee0 Mon Sep 17 00:00:00 2001 From: LarryBattle Date: Tue, 26 Jan 2016 23:53:51 -0600 Subject: [PATCH 0034/1167] Added names to invalid function declarations --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0211792ca3..b324226fa9 100644 --- a/README.md +++ b/README.md @@ -1267,10 +1267,10 @@ Other Style Guides } // bad - function () { return false; } + function foo() { return false; } // good - function () { + function bar() { return false; } ``` @@ -1410,17 +1410,17 @@ Other Style Guides ```javascript // bad - function () { + function foo() { ∙∙∙∙const name; } // bad - function () { + function bar() { ∙const name; } // good - function () { + function baz() { ∙∙const name; } ``` @@ -2216,7 +2216,7 @@ Other Style Guides - [28.1](#28.1) **Yup.** ```javascript - function () { + function foo() { return true; } ``` From 784d029980003d1ff90b472abcd0974496d6d765 Mon Sep 17 00:00:00 2001 From: Fredrik Olovsson Date: Wed, 27 Jan 2016 11:53:57 +0100 Subject: [PATCH 0035/1167] Edit sample code in 24.1 to follow rule 8.1 Replaced function expression with arrow function notation. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b324226fa9..e8edf1497e 100644 --- a/README.md +++ b/README.md @@ -2099,7 +2099,7 @@ Other Style Guides ... - $(this).on('listingUpdated', function (e, listingId) { + $(this).on('listingUpdated', (e, listingId) => { // do something with listingId }); ``` @@ -2112,7 +2112,7 @@ Other Style Guides ... - $(this).on('listingUpdated', function (e, data) { + $(this).on('listingUpdated', (e, data) => { // do something with data.listingId }); ``` From 51510a43c83811406d2098f19e7af90a30918f64 Mon Sep 17 00:00:00 2001 From: Mark Sanghoon Kim Date: Wed, 27 Jan 2016 23:14:53 -0800 Subject: [PATCH 0036/1167] Fixed capitalization and comment spacing Fixed line 1219 to have a lowercase 'a' to be consistent with the style guide. Fixed line 1831 to only have one space between the // and the => --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e8edf1497e..70eae71971 100644 --- a/README.md +++ b/README.md @@ -1216,7 +1216,7 @@ Other Style Guides ```javascript if ([0] && []) { // true - // An array (even an empty one) is an object, objects will evaluate to true + // an array (even an empty one) is an object, objects will evaluate to true } ``` @@ -1828,7 +1828,7 @@ Other Style Guides - [21.2](#21.2) Strings: ```javascript - // => this.reviewScore = 9; + // => this.reviewScore = 9; // bad const totalScore = this.reviewScore + ''; From 7eb7b785134aeae27c37c557a2342e8ee48242ad Mon Sep 17 00:00:00 2001 From: Prayag Verma Date: Sat, 30 Jan 2016 10:42:33 +0530 Subject: [PATCH 0037/1167] Minor typo Remove extra dot --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70eae71971..a0f492a93a 100644 --- a/README.md +++ b/README.md @@ -683,7 +683,7 @@ Other Style Guides > 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. - > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.. + > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration. ```javascript // bad From d293e748725ee16fb1a96afd80b005c60e2781a0 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Mon, 11 Jan 2016 17:54:35 -0500 Subject: [PATCH 0038/1167] add section 15.5 - Ternaries add link to the relevant eslint rule --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index a0f492a93a..da96b7979b 100644 --- a/README.md +++ b/README.md @@ -1246,6 +1246,29 @@ Other Style Guides - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. + - [15.5](#15.5) Ternaries should not be nested and generally be single line expressions. + + eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html). + + ```javascript + //bad + const foo = maybe1 > maybe2 + ? "bar" + : value1 > value2 ? "baz" : null; + + //better + const maybeNull = value1 > value2 ? 'baz' : null; + + const foo = maybe1 > maybe2 + ? 'bar' + : maybeNull; + + //best + const maybeNull = value1 > value2 ? 'baz' : null; + + const foo = maybe1 > maybe2 ? 'bar' : maybeNull; + ``` + **[⬆ back to top](#table-of-contents)** From 206e13b1855647c7c66e0a3809f5a8a0b93e54f1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 2 Feb 2016 10:33:18 -0800 Subject: [PATCH 0039/1167] [guide] remove trailing whitespace --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index da96b7979b..b758421de8 100644 --- a/README.md +++ b/README.md @@ -1247,28 +1247,28 @@ Other Style Guides - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. - [15.5](#15.5) Ternaries should not be nested and generally be single line expressions. - + eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html). - + ```javascript //bad const foo = maybe1 > maybe2 ? "bar" : value1 > value2 ? "baz" : null; - + //better const maybeNull = value1 > value2 ? 'baz' : null; - + const foo = maybe1 > maybe2 ? 'bar' : maybeNull; - + //best const maybeNull = value1 > value2 ? 'baz' : null; - + const foo = maybe1 > maybe2 ? 'bar' : maybeNull; ``` - + **[⬆ back to top](#table-of-contents)** From 38d9b34b2720a2f26e9fa33365836e26d9a7a44e Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 2 Feb 2016 15:30:57 -0800 Subject: [PATCH 0040/1167] Avoid lexical declarations in case/default clauses This commit adds guidance warning people to avoid lexical declarations in case/default clauses and enables the corresponding ESLint rule. http://eslint.org/docs/rules/no-case-declarations.html We didn't have a section on switch statements yet, so I thought about starting one. It seemed like it would best fit between section 15 (Comparison Operators & Equality) and section 16 (Blocks), but I didn't want to mess up all of the following numberings, since people probably have references to them. I considered adding this near the end to minimize this effect, but it really seemed to belong near these other things. I landed on appending it to Section 15 (Comparison Operators & Equality) and I think it sorta fits there since switch statements are a related concept. --- README.md | 41 +++++++++++++++++++ .../rules/best-practices.js | 2 + 2 files changed, 43 insertions(+) diff --git a/README.md b/README.md index b758421de8..381d5c6b94 100644 --- a/README.md +++ b/README.md @@ -1245,6 +1245,47 @@ Other Style Guides ``` - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. + - [15.5](#15.5) Use braces to create blocks in `case` and `default` clauses that contain lexical declarations (e.g. `let`, `const`, `function`, and `class`). + + > Why? Lexical declarations are visible in the entire `switch` block but only get initialized when assigned, which only happens when its `case` is reached. This causes problems when multiple `case` clauses attempt to define the same thing. + + eslint rules: [`no-case-declarations`](http://eslint.org/docs/rules/no-case-declarations.html). + + ```javascript + // bad + switch (foo) { + case 1: + let x = 1; + break; + case 2: + const y = 2; + break; + case 3: + function f() {} + break; + default: + class C {} + } + + // good + switch (foo) { + case 1: { + let x = 1; + break; + } + case 2: { + const y = 2; + break; + } + case 3: { + function f() {} + break; + } + default: { + class C {} + } + } + ``` - [15.5](#15.5) Ternaries should not be nested and generally be single line expressions. diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index c2af1b7875..d8b94e9bf0 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -24,6 +24,8 @@ module.exports = { 'no-alert': 1, // disallow use of arguments.caller or arguments.callee 'no-caller': 2, + // disallow lexical declarations in case/default clauses + 'no-case-declaration': 2, // disallow division operators explicitly at beginning of regular expression 'no-div-regex': 0, // disallow else after a return in an if From 4d74fe1f5ab7e2f67e4ad837387debbf276e3929 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 3 Feb 2016 12:23:51 -0800 Subject: [PATCH 0041/1167] Add example of a case clause that does not need a block As @kesne and @ljharb pointed out, this section was unclear about whether or not you should always include blocks for all case clauses. To make things clearer, I am adding a case clause that does not need a block to the good example. We decided that we should only require blocks for case clauses that actually need them because it matches the as-needed spirit of section 3.8 ("Only quote properties that are invalid identifiers"). Perhaps if there was an as-needed but consistent setting for the ESLint rule, we would consider revising this a little, but this seems good enough for now. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 381d5c6b94..9920eba790 100644 --- a/README.md +++ b/README.md @@ -1281,6 +1281,9 @@ Other Style Guides function f() {} break; } + case 4: + bar(); + break; default: { class C {} } From 7e15ccf4cb39d370e085c860901cce5d9d01d810 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 13 Jan 2016 16:27:12 -0800 Subject: [PATCH 0042/1167] [eslint config] [breaking] disallow unneeded ternary expressions. --- README.md | 22 +++++++++++++++++--- packages/eslint-config-airbnb/rules/style.js | 4 +++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9920eba790..67e9589b06 100644 --- a/README.md +++ b/README.md @@ -1295,24 +1295,40 @@ Other Style Guides eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html). ```javascript - //bad + // bad const foo = maybe1 > maybe2 ? "bar" : value1 > value2 ? "baz" : null; - //better + // better const maybeNull = value1 > value2 ? 'baz' : null; const foo = maybe1 > maybe2 ? 'bar' : maybeNull; - //best + // best const maybeNull = value1 > value2 ? 'baz' : null; const foo = maybe1 > maybe2 ? 'bar' : maybeNull; ``` + - [15.6](#15.6) Avoid unneeded ternary statements. + + eslint rules: [`no-unneeded-ternary`](http://eslint.org/docs/rules/no-unneeded-ternary.html). + + ```javascript + // bad + const foo = a ? a : b; + const bar = c ? true : false; + const baz = c ? false : true; + + // good + const foo = a || b; + const bar = !!c; + const baz = !c; + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 2e3e3cae1b..e1dce37dc7 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -74,7 +74,9 @@ module.exports = { // disallow dangling underscores in identifiers 'no-underscore-dangle': 0, // disallow the use of Boolean literals in conditional expressions - 'no-unneeded-ternary': 0, + // also, prefer `a || b` over `a ? a : b` + // http://eslint.org/docs/rules/no-unneeded-ternary + 'no-unneeded-ternary': [2, { "defaultAssignment": false }], // require padding inside curly braces 'object-curly-spacing': [2, 'always'], // allow just one var statement per function From b6920af58119409c7983f0fa4ea566ee58349a61 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 3 Feb 2016 17:26:33 -0800 Subject: [PATCH 0043/1167] [eslint config] [dev deps] update `eslint-plugin-react`, `react`, `tape` --- 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 63439f6b62..24c7a14e55 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -40,9 +40,9 @@ "devDependencies": { "babel-tape-runner": "1.2.0", "eslint": "^1.10.3", - "eslint-plugin-react": "^3.12.0", - "react": "^0.13.3", - "tape": "^4.2.2", + "eslint-plugin-react": "^3.16.1", + "react": "^0.14.7", + "tape": "^4.4.0", "parallelshell": "^2.0.0" }, "peerDependencies": { From 6f1d92851c56752cf5c8bcad134cccea8fbd6ce0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 3 Feb 2016 18:27:59 -0800 Subject: [PATCH 0044/1167] [eslint config] [fix] `s/no-case-declaration/no-case-declarations/g` (from #712) --- packages/eslint-config-airbnb/rules/best-practices.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index d8b94e9bf0..a221d4d999 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -25,7 +25,8 @@ module.exports = { // disallow use of arguments.caller or arguments.callee 'no-caller': 2, // disallow lexical declarations in case/default clauses - 'no-case-declaration': 2, + // http://eslint.org/docs/rules/no-case-declarations.html + 'no-case-declarations': 2, // disallow division operators explicitly at beginning of regular expression 'no-div-regex': 0, // disallow else after a return in an if From a8461e045328daf2ae8b007301d9cbb6607383bc Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 3 Feb 2016 18:28:07 -0800 Subject: [PATCH 0045/1167] [eslint config] [fix] fix `npm run lint` --- packages/eslint-config-airbnb/rules/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index e1dce37dc7..25c5326857 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -76,7 +76,7 @@ module.exports = { // disallow the use of Boolean literals in conditional expressions // also, prefer `a || b` over `a ? a : b` // http://eslint.org/docs/rules/no-unneeded-ternary - 'no-unneeded-ternary': [2, { "defaultAssignment": false }], + 'no-unneeded-ternary': [2, { 'defaultAssignment': false }], // require padding inside curly braces 'object-curly-spacing': [2, 'always'], // allow just one var statement per function From 06fab80dfabdf2695ec29a035d85dfccd31d9222 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 3 Feb 2016 17:27:52 -0800 Subject: [PATCH 0046/1167] v5.0.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 6 ++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index e9d0220666..75febddbd9 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,9 @@ +5.0.0 / 2016-02-03 +================== + - [breaking] disallow unneeded ternary expressions + - [breaking] Avoid lexical declarations in case/default clauses + - [dev deps] update `babel-tape-runner`, `eslint-plugin-react`, `react`, `tape` + 4.0.0 / 2016-01-22 ================== - [breaking] require outer IIFE wrapping; flesh out guide section diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 24c7a14e55..437f1d1db0 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "4.0.0", + "version": "5.0.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 24e7fd0c147eeb9a2082301af09d44a56b181cf0 Mon Sep 17 00:00:00 2001 From: Ray Sinlao Date: Thu, 4 Feb 2016 00:00:58 -0800 Subject: [PATCH 0047/1167] Added parenthesis to 'good' example in 8.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67e9589b06..32c966ce98 100644 --- a/README.md +++ b/README.md @@ -716,7 +716,7 @@ Other Style Guides }); // good - [1, 2, 3].map(number => { + [1, 2, 3].map((number) => { const nextNumber = number + 1; return `A string containing the ${nextNumber}.`; }); From e007ec5be9f54c2a0fdfcfc6e8f193f0ceb11692 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Thu, 4 Feb 2016 11:01:17 -0800 Subject: [PATCH 0048/1167] Sort static methods above constructor for React I think it makes more sense to put static methods above the constructor in classes. I would like to update the ESLint configuration to match this, but it looks like the react/sort-comp rule does not support it quite yet. https://github.com/yannickcr/eslint-plugin-react/issues/128 --- react/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index 5ea9b5248c..e0351f42a7 100644 --- a/react/README.md +++ b/react/README.md @@ -334,8 +334,8 @@ - Ordering for `class extends React.Component`: - 1. `constructor` 1. optional `static` methods + 1. `constructor` 1. `getChildContext` 1. `componentWillMount` 1. `componentDidMount` From 1bb72ab9e27e5437373b15e643a4602d009bf7ed Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:09:39 -0800 Subject: [PATCH 0049/1167] [Deps] update `eslint` to v2, `eslint-plugin-react` to v4 --- packages/eslint-config-airbnb/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 6b5cad58b5..dd54ae754e 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,14 +43,14 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "1.2.0", - "eslint": "^1.10.3", - "eslint-plugin-react": "^3.16.1", + "eslint": "^2.2.0", + "eslint-plugin-react": "^4.0.0", "react": "^0.14.7", "tape": "^4.4.0", "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": "^1.0.0", - "eslint-plugin-react": "^3.16.1" + "eslint": "^2.2.0", + "eslint-plugin-react": "^4.0.0" } } From d49a1ed670bc1d26a78edc99b9a3b553db9bc13e Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:10:30 -0800 Subject: [PATCH 0050/1167] [eslint-v2] no-empty-label => no-labels --- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index a221d4d999..1359e58ba6 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -32,7 +32,7 @@ module.exports = { // disallow else after a return in an if 'no-else-return': 2, // disallow use of labels for anything other then loops and switches - 'no-empty-label': 2, + "no-labels": [2, {"allowLoop": false, "allowSwitch": false}], // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() From 1efb11ca93e6fd3d22c3a09825fcd4c7c3c896e8 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:11:22 -0800 Subject: [PATCH 0051/1167] [eslint-v2] space-after/before/return/throw/case => keyword-spacing --- packages/eslint-config-airbnb/rules/style.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 25c5326857..e97e0d25f8 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -100,10 +100,12 @@ module.exports = { 'semi': [2, 'always'], // sort variables within the same declaration block 'sort-vars': 0, - // require a space before certain keywords - 'space-before-keywords': [2, 'always'], - // require a space after certain keywords - 'space-after-keywords': [2, 'always'], + // require a space before & after certain keywords + "keyword-spacing": [2, {"before": true, "after": true, "overrides": { + 'return': {'after': true}, + 'throw': {'after': true}, + 'case': {'after': true} + }}], // require or disallow space before blocks 'space-before-blocks': 2, // require or disallow space before function opening parenthesis @@ -113,8 +115,6 @@ module.exports = { 'space-in-parens': [2, 'never'], // require spaces around operators 'space-infix-ops': 2, - // require a space after return, throw, and case - 'space-return-throw-case': 2, // Require or disallow spaces before/after unary operators 'space-unary-ops': 0, // require or disallow a space immediately following the // or /* in a comment From da4213c6dd6b842f72171fc669007185e03902d8 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:29:20 -0800 Subject: [PATCH 0052/1167] [eslint-v2] fix no-labels rule --- packages/eslint-config-airbnb/rules/best-practices.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 1359e58ba6..d87d70d82c 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -32,7 +32,7 @@ module.exports = { // disallow else after a return in an if 'no-else-return': 2, // disallow use of labels for anything other then loops and switches - "no-labels": [2, {"allowLoop": false, "allowSwitch": false}], + 'no-labels': [2, { 'allowLoop': true, 'allowSwitch': true }], // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() @@ -53,8 +53,6 @@ module.exports = { 'no-invalid-this': 0, // disallow usage of __iterator__ property 'no-iterator': 2, - // disallow use of labeled statements - 'no-labels': 2, // disallow unnecessary nested blocks 'no-lone-blocks': 2, // disallow creation of functions within loops From dff50992380894e9056fe03b5300f83c47b4c761 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:30:11 -0800 Subject: [PATCH 0053/1167] [eslint-v2] set es6 env to true --- packages/eslint-config-airbnb/rules/es6.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index f28a436ba3..508257a5bf 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -1,6 +1,6 @@ module.exports = { 'env': { - 'es6': false + 'es6': true }, 'ecmaFeatures': { 'arrowFunctions': true, From 4f32315b24e9545a4e5f8c226a989dbafc1c2099 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:36:08 -0800 Subject: [PATCH 0054/1167] [eslint-v2] ecmaFeatures => parserOptions --- packages/eslint-config-airbnb/rules/es6.js | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 508257a5bf..508885708b 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -2,24 +2,12 @@ module.exports = { 'env': { 'es6': true }, - 'ecmaFeatures': { - 'arrowFunctions': true, - 'blockBindings': true, - 'classes': true, - 'defaultParams': true, - 'destructuring': true, - 'forOf': true, - 'generators': false, - 'modules': true, - 'objectLiteralComputedProperties': true, - 'objectLiteralDuplicateProperties': false, - 'objectLiteralShorthandMethods': true, - 'objectLiteralShorthandProperties': true, - 'restParams': true, - 'spread': true, - 'superInFunctions': true, - 'templateStrings': true, - 'jsx': true + 'parserOptions': { + 'ecmaVersion': 6, + 'sourceType': 'module', + 'ecmaFeatures': { + 'jsx': true + } }, 'rules': { // enforces no braces where they can be omitted From 3aa8c584871474a5bacbc32158e8e76d1ccf94df Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:36:26 -0800 Subject: [PATCH 0055/1167] [eslint-v2] fix keyword-spacing style and sorting --- packages/eslint-config-airbnb/rules/style.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index e97e0d25f8..0e8036ec51 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -31,6 +31,16 @@ module.exports = { 'jsx-quotes': [2, 'prefer-double'], // enforces spacing between keys and values in object literal properties 'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }], + // require a space before & after certain keywords + 'keyword-spacing': [2, { + 'before': true, + 'after': true, + 'overrides': { + 'return': { 'after': true }, + 'throw': { 'after': true }, + 'case': { 'after': true } + } + }], // enforces empty lines around comments 'lines-around-comment': 0, // disallow mixed 'LF' and 'CRLF' as linebreaks @@ -100,12 +110,6 @@ module.exports = { 'semi': [2, 'always'], // sort variables within the same declaration block 'sort-vars': 0, - // require a space before & after certain keywords - "keyword-spacing": [2, {"before": true, "after": true, "overrides": { - 'return': {'after': true}, - 'throw': {'after': true}, - 'case': {'after': true} - }}], // require or disallow space before blocks 'space-before-blocks': 2, // require or disallow space before function opening parenthesis From d952efed242e9f4e25f3a4b45b7f62075a1a26e2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 13 Feb 2016 11:10:48 -0800 Subject: [PATCH 0056/1167] [Fix] `eslint` peerDep should not include breaking changes. --- packages/eslint-config-airbnb/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 437f1d1db0..467b916eec 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -46,6 +46,7 @@ "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": ">=1.0.0" + "eslint": "^1.0.0", + "eslint-plugin-react": "^3.16.1" } } From 8b58d8770cc1dcb3a2e4a7b7be94ea84d4dc3c4c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 13 Feb 2016 11:11:39 -0800 Subject: [PATCH 0057/1167] v5.0.1 --- packages/eslint-config-airbnb/CHANGELOG.md | 4 ++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 75febddbd9..7c47c680f5 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,7 @@ +5.0.1 / 2016-02-13 +================== + - [fix] `eslint` peerDep should not include breaking changes + 5.0.0 / 2016-02-03 ================== - [breaking] disallow unneeded ternary expressions diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 467b916eec..c8263acf29 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "5.0.0", + "version": "5.0.1", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From aa9add108e71dc69c9baa984894ce5914c973251 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:37:39 -0800 Subject: [PATCH 0058/1167] [pkg] add harry to contributors --- packages/eslint-config-airbnb/package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index c8263acf29..6b5cad58b5 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -30,6 +30,10 @@ "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" + }, + { + "name": "Harrison Shoff", + "url": "https://twitter.com/hshoff" } ], "license": "MIT", From 75807b9d5ead326be45f4719d81bda52d2bbb32a Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 12 Feb 2016 11:42:15 -0800 Subject: [PATCH 0059/1167] [eslint-v2] no gens, no dup props in obj literal --- packages/eslint-config-airbnb/rules/es6.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 508885708b..08b5889172 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -6,7 +6,9 @@ module.exports = { 'ecmaVersion': 6, 'sourceType': 'module', 'ecmaFeatures': { - 'jsx': true + 'jsx': true, + 'generators': false, + 'objectLiteralDuplicateProperties': false } }, 'rules': { From 5109c849268020266b300229d7efd2de50f94c21 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 13 Feb 2016 13:41:52 -0800 Subject: [PATCH 0060/1167] [eslint-v2] fix no-labels rule --- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index d87d70d82c..00f7d2d988 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -32,7 +32,7 @@ module.exports = { // disallow else after a return in an if 'no-else-return': 2, // disallow use of labels for anything other then loops and switches - 'no-labels': [2, { 'allowLoop': true, 'allowSwitch': true }], + 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() From 1cbc628c49fe8e9540028f8a560b43ebdd08c82b Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 13 Feb 2016 13:57:38 -0800 Subject: [PATCH 0061/1167] [eslint-v2][constructors] disallow unnecessary constructors --- README.md | 24 ++++++++++++++++++++++ packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 32c966ce98..952b135a24 100644 --- a/README.md +++ b/README.md @@ -883,6 +883,30 @@ Other Style Guides } ``` + - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. + + ```javascript + // bad + class Jedi { + constructor() {} + + getName() { + return this.name; + } + } + + // good + class Rey extends Jedi { + constructor(...args) { + super(...args); + } + + getName() { + return this.name; + } + } + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 08b5889172..f55d6b9bac 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -34,6 +34,9 @@ module.exports = { 'no-this-before-super': 0, // require let or const instead of var 'no-var': 2, + // disallow unnecessary constructor + // http://eslint.org/docs/rules/no-useless-constructor + 'no-useless-constructor': 2, // require method and property shorthand syntax for object literals // https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md 'object-shorthand': [2, 'always'], From 91b83650b006764d1b235b79c265151c8b00ba19 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 02:34:47 -0800 Subject: [PATCH 0062/1167] [eslint-v2][constructors] fix bad + good examples --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 952b135a24..46e783580b 100644 --- a/README.md +++ b/README.md @@ -895,14 +895,17 @@ Other Style Guides } } - // good class Rey extends Jedi { constructor(...args) { super(...args); } + } - getName() { - return this.name; + // good + class Rey extends Jedi { + constructor(...args) { + super(...args); + this.name = 'Rey'; } } ``` From c05b2da9db51dc160b45c72faf317cb2f5604660 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 02:50:51 -0800 Subject: [PATCH 0063/1167] [eslint-v2] add new rules, disabled: - `id-blacklist` - `no-extra-label` - `no-implicit-globals` - `no-restricted-imports` - `no-unmodified-loop-condition` - `no-unused-labels` - `sort-imports` - `yield-star-spacing` --- .../eslint-config-airbnb/rules/best-practices.js | 16 ++++++++++++++-- packages/eslint-config-airbnb/rules/es6.js | 11 ++++++++++- packages/eslint-config-airbnb/rules/variables.js | 3 +++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 00f7d2d988..845904206e 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -20,6 +20,9 @@ module.exports = { 'eqeqeq': 2, // make sure for-in loops have an if statement 'guard-for-in': 2, + // Blacklist certain identifiers to prevent them being used + // http://eslint.org/docs/rules/id-blacklist + 'id-blacklist': 0, // disallow the use of alert, confirm, and prompt 'no-alert': 1, // disallow use of arguments.caller or arguments.callee @@ -31,8 +34,9 @@ module.exports = { 'no-div-regex': 0, // disallow else after a return in an if 'no-else-return': 2, - // disallow use of labels for anything other then loops and switches - 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], + // disallow Unnecessary Labels + // http://eslint.org/docs/rules/no-extra-label + 'no-extra-label': 0, // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() @@ -53,6 +57,8 @@ module.exports = { 'no-invalid-this': 0, // disallow usage of __iterator__ property 'no-iterator': 2, + // disallow use of labels for anything other then loops and switches + 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], // disallow unnecessary nested blocks 'no-lone-blocks': 2, // disallow creation of functions within loops @@ -94,8 +100,14 @@ module.exports = { 'no-sequences': 2, // restrict what can be thrown as an exception 'no-throw-literal': 2, + // disallow unmodified conditions of loops + // http://eslint.org/docs/rules/no-unmodified-loop-condition + 'no-unmodified-loop-condition': 0, // disallow usage of expressions in statement position 'no-unused-expressions': 2, + // disallow unused labels + // http://eslint.org/docs/rules/no-unused-labels + 'no-unused-labels': 0, // disallow unnecessary .call() and .apply() 'no-useless-call': 0, // disallow use of void operator diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index f55d6b9bac..11e212b5eb 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,6 +30,9 @@ module.exports = { 'no-class-assign': 0, // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow specific imports + // http://eslint.org/docs/rules/no-restricted-imports + 'no-restricted-imports': 0, // disallow to use this/super before super() calling in constructors. 'no-this-before-super': 0, // require let or const instead of var @@ -52,6 +55,12 @@ module.exports = { // http://eslint.org/docs/rules/prefer-template 'prefer-template': 2, // disallow generator functions that do not have yield - 'require-yield': 0 + 'require-yield': 0, + // import sorting + // http://eslint.org/docs/rules/sort-imports + 'sort-imports': 0, + // enforce spacing around the * in yield* expressions + // http://eslint.org/docs/rules/yield-star-spacing + 'yield-star-spacing': 0 } }; diff --git a/packages/eslint-config-airbnb/rules/variables.js b/packages/eslint-config-airbnb/rules/variables.js index 59914313f9..b9073f72c5 100644 --- a/packages/eslint-config-airbnb/rules/variables.js +++ b/packages/eslint-config-airbnb/rules/variables.js @@ -6,6 +6,9 @@ module.exports = { 'no-catch-shadow': 0, // disallow deletion of variables 'no-delete-var': 2, + // disallow var and named functions in global scope + // http://eslint.org/docs/rules/no-implicit-globals + 'no-implicit-globals': 0, // disallow labels that share a name with a variable 'no-label-var': 0, // disallow shadowing of names such as arguments From a126d0b85c8b2afcdd309c39f45c14815bb1ab23 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 12:56:03 -0800 Subject: [PATCH 0064/1167] [eslint-v2] enforce yield-start-spacing, no-unused-labels, no-extra-label --- packages/eslint-config-airbnb/rules/best-practices.js | 4 ++-- packages/eslint-config-airbnb/rules/es6.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 845904206e..5a50af000a 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -36,7 +36,7 @@ module.exports = { 'no-else-return': 2, // disallow Unnecessary Labels // http://eslint.org/docs/rules/no-extra-label - 'no-extra-label': 0, + 'no-extra-label': 2, // disallow comparisons to null without a type-checking operator 'no-eq-null': 0, // disallow use of eval() @@ -107,7 +107,7 @@ module.exports = { 'no-unused-expressions': 2, // disallow unused labels // http://eslint.org/docs/rules/no-unused-labels - 'no-unused-labels': 0, + 'no-unused-labels': 2, // disallow unnecessary .call() and .apply() 'no-useless-call': 0, // disallow use of void operator diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 11e212b5eb..8ba6e5e3c9 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -61,6 +61,6 @@ module.exports = { 'sort-imports': 0, // enforce spacing around the * in yield* expressions // http://eslint.org/docs/rules/yield-star-spacing - 'yield-star-spacing': 0 + 'yield-star-spacing': [2, 'after'] } }; From fbd9c35dd37c2466b809a89c79703583de77d275 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 11:14:38 -0800 Subject: [PATCH 0065/1167] [eslint-v2][arrays] add array-callback-return rule --- README.md | 45 +++++++++++++++++++ .../rules/best-practices.js | 3 ++ 2 files changed, 48 insertions(+) diff --git a/README.md b/README.md index 46e783580b..b52dbdcc23 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,51 @@ Other Style Guides const nodes = Array.from(foo); ``` + - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [array-callback-return](http://eslint.org/docs/rules/array-callback-return) + + ```javascript + // good + [1, 2, 3].map((x) => { + const y = x + 1; + return x * y; + }); + + // good + [1, 2, 3].map(x => x + 1); + + // bad + const flat = {}; + [[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => { + const flatten = memo.concat(item); + flat[index] = memo.concat(item); + }); + + // good + const flat = {}; + [[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => { + const flatten = memo.concat(item); + flat[index] = flatten; + return flatten; + }); + + // bad + [1, 2, 3].filter((x) => { + if (x > 2) { + return true; + } else { + return false; + } + }); + + // good + [1, 2, 3].filter((x) => { + if (x > 2) { + return true; + } + return false; + }); + ``` + **[⬆ back to top](#table-of-contents)** ## Destructuring diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 5a50af000a..6f66792478 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -2,6 +2,9 @@ module.exports = { 'rules': { // enforces getter/setter pairs in objects 'accessor-pairs': 0, + // enforces return statements in callbacks of array's methods + // http://eslint.org/docs/rules/array-callback-return + 'array-callback-return': 2, // treat var statements as if they were block scoped 'block-scoped-var': 2, // specify the maximum cyclomatic complexity allowed in a program From 172dffbb52ae6b61fe41c9a4c14d4be68070111f Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 11:48:04 -0800 Subject: [PATCH 0066/1167] [eslint-v2][whitespace] add newline-per-chained-call rule --- README.md | 8 ++++++-- packages/eslint-config-airbnb/rules/style.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b52dbdcc23..7290e0aca3 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,7 @@ Other Style Guides if (x > 2) { return true; } + return false; }); ``` @@ -1664,8 +1665,8 @@ Other Style Guides })(this);↵ ``` - - [18.6](#18.6) Use indentation when making long method chains. Use a leading dot, which - emphasizes that the line is a method call, not a new statement. + - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which + emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) ```javascript // bad @@ -1702,6 +1703,9 @@ Other Style Guides .append('svg:g') .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')') .call(tron.led); + + // good + const leds = stage.selectAll('.led').data(data); ``` - [18.7](#18.7) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 0e8036ec51..4e8710c347 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -59,6 +59,9 @@ module.exports = { 'new-parens': 0, // allow/disallow an empty newline after var statement 'newline-after-var': 0, + // enforces new line after each method call in the chain to make it more readable and easy to maintain + // http://eslint.org/docs/rules/newline-per-chained-call + 'newline-per-chained-call': [2, { "ignoreChainWithDepth": 3 }], // disallow use of the Array constructor 'no-array-constructor': 0, // disallow use of the continue statement From 6a03a32915533eb09151c754333ccf0f724d05ad Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 14:47:23 -0800 Subject: [PATCH 0067/1167] [eslint-v2][arrow functions] add no-confusing-arrow rule --- README.md | 13 +++++++++++++ packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 7290e0aca3..e5ed8a3754 100644 --- a/README.md +++ b/README.md @@ -817,6 +817,19 @@ Other Style Guides }); ``` + - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [no-confusing-arrow](http://eslint.org/docs/rules/no-confusing-arrow) + + ```js + // bad + const isActive = item => item.height > 256 ? true : false; + + // bad + const isActive = (item) => item.height > 256 ? true : false; + + // good + const isActive = item => { return item.height > 256 ? true : false; } + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 8ba6e5e3c9..88fbf2eb89 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -28,6 +28,9 @@ module.exports = { 'generator-star-spacing': 0, // disallow modifying variables of class declarations 'no-class-assign': 0, + // disallow arrow functions where they could be confused with comparisons + // http://eslint.org/docs/rules/no-confusing-arrow + 'no-confusing-arrow': 2, // disallow modifying variables that are declared using const 'no-const-assign': 2, // disallow specific imports From ba10353e9b34f44afbd8b4a2ecdff923356a2ae7 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 14:50:49 -0800 Subject: [PATCH 0068/1167] [eslint-v2][arrow functions] improve examples --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e5ed8a3754..e2b48378ae 100644 --- a/README.md +++ b/README.md @@ -821,13 +821,13 @@ Other Style Guides ```js // bad - const isActive = item => item.height > 256 ? true : false; + const itemHeight = item => item.height > 256 ? item.largeSize : item.smallSize; // bad - const isActive = (item) => item.height > 256 ? true : false; + const itemHeight = (item) => item.height > 256 ? item.largeSize : item.smallSize; // good - const isActive = item => { return item.height > 256 ? true : false; } + const itemHeight = item => { return item.height > 256 ? item.largeSize : item.smallSize; } ``` **[⬆ back to top](#table-of-contents)** From 3762c9add826e47587242460db331d8203cea069 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 14:58:28 -0800 Subject: [PATCH 0069/1167] [eslint-v2] add no-new-symbol rule --- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 88fbf2eb89..be2ebe5c7c 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -33,6 +33,9 @@ module.exports = { 'no-confusing-arrow': 2, // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow symbol constructor + // http://eslint.org/docs/rules/no-new-symbol + 'no-new-symbol': 2, // disallow specific imports // http://eslint.org/docs/rules/no-restricted-imports 'no-restricted-imports': 0, From 92df6357b3ed3326eaca33454b112d06dbd76f0e Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:30:28 -0800 Subject: [PATCH 0070/1167] [eslint-v2][variables] add no-self-assign --- packages/eslint-config-airbnb/rules/variables.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/variables.js b/packages/eslint-config-airbnb/rules/variables.js index b9073f72c5..3bfcc83fde 100644 --- a/packages/eslint-config-airbnb/rules/variables.js +++ b/packages/eslint-config-airbnb/rules/variables.js @@ -11,6 +11,9 @@ module.exports = { 'no-implicit-globals': 0, // disallow labels that share a name with a variable 'no-label-var': 0, + // disallow self assignment + // http://eslint.org/docs/rules/no-self-assign + 'no-self-assign': 2, // disallow shadowing of names such as arguments 'no-shadow-restricted-names': 2, // disallow declaration of variables already declared in the outer scope From e6cbcf4cc56b04edbb22eef2856fce78bf4625b1 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:35:23 -0800 Subject: [PATCH 0071/1167] [eslint-v2][whitespace] add no-whitespace-before-property rule --- README.md | 2 +- packages/eslint-config-airbnb/rules/style.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2b48378ae..99f9b3dff7 100644 --- a/README.md +++ b/README.md @@ -1679,7 +1679,7 @@ Other Style Guides ``` - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which - emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) + emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) [no-whitespace-before-property](http://eslint.org/docs/rules/no-whitespace-before-property) ```javascript // bad diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 4e8710c347..85c1fd706d 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -90,6 +90,9 @@ module.exports = { // also, prefer `a || b` over `a ? a : b` // http://eslint.org/docs/rules/no-unneeded-ternary 'no-unneeded-ternary': [2, { 'defaultAssignment': false }], + // disallow whitespace before properties + // http://eslint.org/docs/rules/no-whitespace-before-property + 'no-whitespace-before-property': 2, // require padding inside curly braces 'object-curly-spacing': [2, 'always'], // allow just one var statement per function From c5b4f05879be4cd48c1737ad9bfdb00ed8a87ee0 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:39:32 -0800 Subject: [PATCH 0072/1167] [eslint-v2] add one-var-declaration-per-line --- packages/eslint-config-airbnb/rules/style.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 85c1fd706d..a5d9e094de 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -97,6 +97,9 @@ module.exports = { 'object-curly-spacing': [2, 'always'], // allow just one var statement per function 'one-var': [2, 'never'], + // require a newline around variable declaration + // http://eslint.org/docs/rules/one-var-declaration-per-line + 'one-var-declaration-per-line': [2, 'always'], // require assignment operator shorthand where possible or prohibit it entirely 'operator-assignment': 0, // enforce operators to be placed before or after line breaks From e1a087fbb1eeb861acce7bab67476ccd4dd080e0 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:45:44 -0800 Subject: [PATCH 0073/1167] [eslint-v2] add prefer-rest-params --- README.md | 2 +- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99f9b3dff7..795608e126 100644 --- a/README.md +++ b/README.md @@ -581,7 +581,7 @@ Other Style Guides ``` - - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. + - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [prefer-rest-params](http://eslint.org/docs/rules/prefer-rest-params) > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`. diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index be2ebe5c7c..ae835a6ab9 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -57,6 +57,9 @@ module.exports = { 'prefer-spread': 0, // suggest using Reflect methods where applicable 'prefer-reflect': 0, + // use rest parameters instead of arguments + // http://eslint.org/docs/rules/prefer-rest-params + 'prefer-rest-params': 2, // suggest using template literals instead of string concatenation // http://eslint.org/docs/rules/prefer-template 'prefer-template': 2, From 1f12a12be474bc9f61b2b1556549e865f3be114c Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:48:31 -0800 Subject: [PATCH 0074/1167] [eslint-v2] fix empty constructor example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 795608e126..909954c934 100644 --- a/README.md +++ b/README.md @@ -956,14 +956,14 @@ Other Style Guides class Rey extends Jedi { constructor(...args) { - super(...args); + super(args); } } // good class Rey extends Jedi { constructor(...args) { - super(...args); + super(args); this.name = 'Rey'; } } From 65609373bfe33e5d86b2ac04ff2fd7f0aaa6a8a2 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 18:56:49 -0800 Subject: [PATCH 0075/1167] [eslint-v2][template strings] add template-curly-spacing rule, fix #716 --- README.md | 7 ++++++- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 909954c934..d9bab06129 100644 --- a/README.md +++ b/README.md @@ -493,7 +493,7 @@ Other Style Guides ``` - - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) + - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. @@ -508,6 +508,11 @@ Other Style Guides return ['How are you, ', name, '?'].join(); } + // bad + function sayHi(name) { + return `How are you, ${ name }?`; + } + // good function sayHi(name) { return `How are you, ${name}?`; diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index ae835a6ab9..e88b2d5059 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -68,6 +68,9 @@ module.exports = { // import sorting // http://eslint.org/docs/rules/sort-imports 'sort-imports': 0, + // enforce usage of spacing in template strings + // http://eslint.org/docs/rules/template-curly-spacing + 'template-curly-spacing': 2, // enforce spacing around the * in yield* expressions // http://eslint.org/docs/rules/yield-star-spacing 'yield-star-spacing': [2, 'after'] From e0959d0f1d35105a9db8d972e0f844daf0dfa072 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 19:04:12 -0800 Subject: [PATCH 0076/1167] [eslint-v2] fix rule links in readme --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d9bab06129..e423c59499 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ Other Style Guides const nodes = Array.from(foo); ``` - - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [array-callback-return](http://eslint.org/docs/rules/array-callback-return) + - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return) ```javascript // good @@ -586,7 +586,7 @@ Other Style Guides ``` - - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [prefer-rest-params](http://eslint.org/docs/rules/prefer-rest-params) + - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`. @@ -822,7 +822,7 @@ Other Style Guides }); ``` - - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [no-confusing-arrow](http://eslint.org/docs/rules/no-confusing-arrow) + - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](http://eslint.org/docs/rules/no-confusing-arrow) ```js // bad @@ -947,7 +947,7 @@ Other Style Guides } ``` - - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. + - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) ```javascript // bad @@ -959,6 +959,7 @@ Other Style Guides } } + // bad class Rey extends Jedi { constructor(...args) { super(args); @@ -1684,7 +1685,7 @@ Other Style Guides ``` - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which - emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) [no-whitespace-before-property](http://eslint.org/docs/rules/no-whitespace-before-property) + emphasizes that the line is a method call, not a new statement. eslint: [`newline-per-chained-call`](http://eslint.org/docs/rules/newline-per-chained-call) [`no-whitespace-before-property`](http://eslint.org/docs/rules/no-whitespace-before-property) ```javascript // bad From ff0adbe2918dbc5b26814f61853227318d787965 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 12:59:00 -0800 Subject: [PATCH 0077/1167] [eslint-v2][react] acceptTranspilerName => ignoreTranspilerName --- packages/eslint-config-airbnb/rules/react.js | 5 ++++- packages/eslint-config-airbnb/rules/style.js | 5 +++-- packages/eslint-config-airbnb/test/test-react-order.js | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index e1e1c25993..2b59ca200e 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -10,7 +10,7 @@ module.exports = { 'rules': { // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - 'react/display-name': [0, { 'acceptTranspilerName': false }], + 'react/display-name': [0, { 'ignoreTranspilerName': true }], // Forbid certain propTypes (any, array, object) // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md 'react/forbid-prop-types': [0, { 'forbid': ['any', 'array', 'object'] }], @@ -116,6 +116,9 @@ module.exports = { // Prevent extra closing tags for components without children // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md 'react/self-closing-comp': 2, + // Enforce spaces before the closing bracket of self-closing JSX elements + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md + 'react/jsx-space-before-closing': [2, 'always'], // Enforce component methods order // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md 'react/sort-comp': [2, { diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index a5d9e094de..c147aae8b7 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -59,9 +59,10 @@ module.exports = { 'new-parens': 0, // allow/disallow an empty newline after var statement 'newline-after-var': 0, - // enforces new line after each method call in the chain to make it more readable and easy to maintain + // enforces new line after each method call in the chain to make it + // more readable and easy to maintain // http://eslint.org/docs/rules/newline-per-chained-call - 'newline-per-chained-call': [2, { "ignoreChainWithDepth": 3 }], + 'newline-per-chained-call': [2, { 'ignoreChainWithDepth': 3 }], // disallow use of the Array constructor 'no-array-constructor': 0, // disallow use of the continue statement diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index 77448cf86a..f5b2d452fe 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -14,7 +14,8 @@ const cli = new CLIEngine({ function lint(text) { // @see http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles // @see http://eslint.org/docs/developer-guide/nodejs-api.html#executeontext - return cli.executeOnText(text).results[0]; + const linter = cli.executeOnText(text); + return linter.results[0]; } function wrapComponent(body) { From 133fc51e21321c3eba0cda5f6fa008ff55940d8c Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:02:15 -0800 Subject: [PATCH 0078/1167] [eslint-v2][react] add static-methods to top of sort-comp order --- packages/eslint-config-airbnb/rules/react.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 2b59ca200e..a9facdd732 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -123,6 +123,7 @@ module.exports = { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md 'react/sort-comp': [2, { 'order': [ + 'static-methods', 'lifecycle', '/^on.+$/', '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', From 07948531dccc62d21f190ed4a2edc035642da01a Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:05:49 -0800 Subject: [PATCH 0079/1167] [eslint-v2][react] set ignoreTranspilerName to false --- packages/eslint-config-airbnb/rules/react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index a9facdd732..99e4c02010 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -10,7 +10,7 @@ module.exports = { 'rules': { // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - 'react/display-name': [0, { 'ignoreTranspilerName': true }], + 'react/display-name': [0, { 'ignoreTranspilerName': false }], // Forbid certain propTypes (any, array, object) // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md 'react/forbid-prop-types': [0, { 'forbid': ['any', 'array', 'object'] }], From 822c0dfdfe16ead8d4e3da8c35c007901e94f4eb Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:10:42 -0800 Subject: [PATCH 0080/1167] [eslint-v2][react] jsx-sort-prop-types => sort-prop-types --- packages/eslint-config-airbnb/rules/react.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 99e4c02010..b7a9889e69 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -54,8 +54,8 @@ module.exports = { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md 'react/jsx-pascal-case': 0, // Enforce propTypes declarations alphabetical sorting - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md - 'react/jsx-sort-prop-types': [0, { + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md + 'react/sort-prop-types': [0, { 'ignoreCase': false, 'callbacksLast': false, }], From b79e9512801f798698f15baaaec92c328c0af6c0 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 23:33:39 -0800 Subject: [PATCH 0081/1167] [eslint-v2][arrays] update array-callback-return good/bad ex --- README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e423c59499..e89fc1cd6a 100644 --- a/README.md +++ b/README.md @@ -374,9 +374,10 @@ Other Style Guides }); // bad - [1, 2, 3].filter((x) => { - if (x > 2) { - return true; + inbox].filter((msg) => { + const { subject, author } = msg; + if (subject === 'Mockingbird') { + return author === 'Harper Lee'; } else { return false; } @@ -384,12 +385,14 @@ Other Style Guides // good [1, 2, 3].filter((x) => { - if (x > 2) { - return true; - } + inbox].filter((msg) => { + const { subject, author } = msg; + if (subject === 'Mockingbird') { + return author === 'Harper Lee'; + } - return false; - }); + return false; + }); ``` **[⬆ back to top](#table-of-contents)** From 3983d380edd22fe7546f9fef2d04fc69a5db04f7 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 23:39:29 -0800 Subject: [PATCH 0082/1167] [eslint-v2][arrays] fix example --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e89fc1cd6a..e10cca35ea 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ Other Style Guides }); // bad - inbox].filter((msg) => { + inbox.filter((msg) => { const { subject, author } = msg; if (subject === 'Mockingbird') { return author === 'Harper Lee'; @@ -384,15 +384,14 @@ Other Style Guides }); // good - [1, 2, 3].filter((x) => { - inbox].filter((msg) => { - const { subject, author } = msg; - if (subject === 'Mockingbird') { - return author === 'Harper Lee'; - } + inbox.filter((msg) => { + const { subject, author } = msg; + if (subject === 'Mockingbird') { + return author === 'Harper Lee'; + } - return false; - }); + return false; + }); ``` **[⬆ back to top](#table-of-contents)** From 0f32b96c125784e0db507682d3fb2fe05098e903 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sat, 20 Feb 2016 13:24:55 -0800 Subject: [PATCH 0083/1167] [changelog] update changelog for 6.0.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 7c47c680f5..fcb16ec26c 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,21 @@ +6.0.0 / 2016-02-21 +================== +- [breaking] enable `array-callback-return` +- [breaking] enable `no-confusing-arrow` +- [breaking] enable `no-new-symbol` +- [breaking] enable `no-restricted-imports` +- [breaking] enable `no-useless-constructor` +- [breaking] enable `prefer-rest-params` +- [breaking] enable `template-curly-spaces` +- [breaking] enable `newline-per-chained-call` +- [breaking] enable `one-var-declaration-per-line` +- [breaking] enable `no-self-assign` +- [breaking] enable `no-whitespace-before-property` +- [breaking] [react] enable `react/jsx-space-before-closing` +- [breaking] [react] enable `static-methods` at top of `react/sort-comp` +- [breaking] [react] don't `ignoreTranspilerName` for `react/display-name` +- [peer+dev deps] update `eslint`, `eslint-plugin-react` + 5.0.1 / 2016-02-13 ================== - [fix] `eslint` peerDep should not include breaking changes From 4574659833a8d1c6c45833bb06743ababa6929e8 Mon Sep 17 00:00:00 2001 From: Sergey Fursov Date: Sun, 21 Feb 2016 01:31:20 +0300 Subject: [PATCH 0084/1167] rearrange comma-dangle rule to match es5/es6 codestyles, fixes #741 --- packages/eslint-config-airbnb/rules/errors.js | 2 -- packages/eslint-config-airbnb/rules/es6.js | 2 ++ packages/eslint-config-airbnb/rules/legacy.js | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/errors.js b/packages/eslint-config-airbnb/rules/errors.js index ec1b1aab0e..1c1addf5fa 100644 --- a/packages/eslint-config-airbnb/rules/errors.js +++ b/packages/eslint-config-airbnb/rules/errors.js @@ -1,7 +1,5 @@ module.exports = { 'rules': { - // disallow trailing commas in object literals - 'comma-dangle': [2, 'always-multiline'], // disallow assignment in conditional expressions 'no-cond-assign': [2, 'always'], // disallow use of console diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index e34684346d..f28a436ba3 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,6 +30,8 @@ module.exports = { // require space before/after arrow function's arrow // https://github.com/eslint/eslint/blob/master/docs/rules/arrow-spacing.md 'arrow-spacing': [2, { 'before': true, 'after': true }], + // require trailing commas in multiline object literals + 'comma-dangle': [2, 'always-multiline'], // verify super() callings in constructors 'constructor-super': 0, // enforce the spacing around the * in generator functions diff --git a/packages/eslint-config-airbnb/rules/legacy.js b/packages/eslint-config-airbnb/rules/legacy.js index e94c774f26..dc34856f5e 100644 --- a/packages/eslint-config-airbnb/rules/legacy.js +++ b/packages/eslint-config-airbnb/rules/legacy.js @@ -1,5 +1,7 @@ module.exports = { 'rules': { + // disallow trailing commas in object literals + 'comma-dangle': [2, 'never'], // specify the maximum depth that blocks can be nested 'max-depth': [0, 4], // limits the number of parameters that can be used in the function declaration. From b648de3233c157c81b9d6301d061e16136ca1d29 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 00:51:00 -0800 Subject: [PATCH 0085/1167] [eslint config] v6.0.0 --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index dd54ae754e..d014d2c079 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "5.0.1", + "version": "6.0.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 8a6f00968db332594d1181ffa05894c2fb3fc906 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 10:28:54 -0800 Subject: [PATCH 0086/1167] Fix no-useless-constructor example. Per https://github.com/airbnb/javascript/pull/730#discussion_r53565774 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e10cca35ea..37bb6433a0 100644 --- a/README.md +++ b/README.md @@ -964,14 +964,14 @@ Other Style Guides // bad class Rey extends Jedi { constructor(...args) { - super(args); + super(...args); } } // good class Rey extends Jedi { constructor(...args) { - super(args); + super(...args); this.name = 'Rey'; } } From 12fb48611ad2c035ba0aa30ccb5a708263867261 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 10:57:42 -0800 Subject: [PATCH 0087/1167] =?UTF-8?q?Disable=20`newline-per-chained-call`?= =?UTF-8?q?=20until=20`eslint`=E2=80=99s=20bug=20is=20resolved.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug: https://github.com/eslint/eslint/issues/5289 Closes #748. --- packages/eslint-config-airbnb/rules/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index c147aae8b7..b9b0e23f5c 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -62,7 +62,7 @@ module.exports = { // enforces new line after each method call in the chain to make it // more readable and easy to maintain // http://eslint.org/docs/rules/newline-per-chained-call - 'newline-per-chained-call': [2, { 'ignoreChainWithDepth': 3 }], + 'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 3 }], // disallow use of the Array constructor 'no-array-constructor': 0, // disallow use of the continue statement From f4e94ade2ba9f42edea07977f4b0bfcb90c448d5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 21 Feb 2016 10:59:44 -0800 Subject: [PATCH 0088/1167] v6.0.1 --- packages/eslint-config-airbnb/CHANGELOG.md | 6 +++++- packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index fcb16ec26c..7c29ba922e 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,7 @@ +6.0.1 / 2016-02-21 +================== +- [fix] disable `newline-per-chained-call` due to an `eslint` bug (#748) + 6.0.0 / 2016-02-21 ================== - [breaking] enable `array-callback-return` @@ -14,7 +18,7 @@ - [breaking] [react] enable `react/jsx-space-before-closing` - [breaking] [react] enable `static-methods` at top of `react/sort-comp` - [breaking] [react] don't `ignoreTranspilerName` for `react/display-name` -- [peer+dev deps] update `eslint`, `eslint-plugin-react` +- [peer+dev deps] update `eslint`, `eslint-plugin-react` (#730) (#730) (#730) (#730) 5.0.1 / 2016-02-13 ================== diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index d014d2c079..618d928332 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.0.0", + "version": "6.0.1", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 50ff33de88f6f1363a27e61d59f2c950cf0bd9f8 Mon Sep 17 00:00:00 2001 From: Cihan Bebek Date: Sun, 21 Feb 2016 21:38:33 +0200 Subject: [PATCH 0089/1167] Small typo fix in 18.6 'bad'-example. Function call 'class()' to 'classed()'. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37bb6433a0..2bdac55fab 100644 --- a/README.md +++ b/README.md @@ -1710,7 +1710,7 @@ Other Style Guides .updateCount(); // bad - const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true) + const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').classed('led', true) .attr('width', (radius + margin) * 2).append('svg:g') .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')') .call(tron.led); From f12b2a195aa53447cc2d902628af7e76d35ec447 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Feb 2016 10:46:03 -0800 Subject: [PATCH 0090/1167] [Dev Deps] update `babel-tape-runner`. Closes https://github.com/wavded/babel-tape-runner/issues/11 --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 618d928332..bfd7d24f76 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -42,7 +42,7 @@ }, "homepage": "https://github.com/airbnb/javascript", "devDependencies": { - "babel-tape-runner": "1.2.0", + "babel-tape-runner": "^1.3.1", "eslint": "^2.2.0", "eslint-plugin-react": "^4.0.0", "react": "^0.14.7", From 33f1ddb4c534e0db605cca3d4060113b32c248ce Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Feb 2016 14:30:23 -0800 Subject: [PATCH 0091/1167] =?UTF-8?q?Disable=20`no-confusing-arrow`=20unti?= =?UTF-8?q?l=20eslint=E2=80=99s=20bug=20is=20resolved.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug: https://github.com/eslint/eslint/issues/5332 Closes #752. --- packages/eslint-config-airbnb/rules/es6.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index e88b2d5059..ef50e0a7f5 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,7 +30,7 @@ module.exports = { 'no-class-assign': 0, // disallow arrow functions where they could be confused with comparisons // http://eslint.org/docs/rules/no-confusing-arrow - 'no-confusing-arrow': 2, + 'no-confusing-arrow': 0, // disallow modifying variables that are declared using const 'no-const-assign': 2, // disallow symbol constructor From 6c637b97d919f9434ea00fedaa367794e0cad49e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Feb 2016 14:49:34 -0800 Subject: [PATCH 0092/1167] [eslint config] v6.0.2 --- packages/eslint-config-airbnb/CHANGELOG.md | 4 ++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 7c29ba922e..c7cd9c97a9 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,7 @@ +6.0.2 / 2016-02-22 +================== +- [fix] disable `no-confusing-arrow` due to an `eslint` bug (#752) + 6.0.1 / 2016-02-21 ================== - [fix] disable `newline-per-chained-call` due to an `eslint` bug (#748) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index bfd7d24f76..9478f804fd 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.0.1", + "version": "6.0.2", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From db8b07f51ad54682bd0225a42d9d5325044ab8f2 Mon Sep 17 00:00:00 2001 From: NakShi Date: Mon, 22 Feb 2016 15:39:53 -0800 Subject: [PATCH 0093/1167] Fixed README typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2bdac55fab..f1dadba1dc 100644 --- a/README.md +++ b/README.md @@ -1384,7 +1384,7 @@ Other Style Guides } ``` - - [15.5](#15.5) Ternaries should not be nested and generally be single line expressions. + - [15.6](#15.6) Ternaries should not be nested and generally be single line expressions. eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html). @@ -1407,7 +1407,7 @@ Other Style Guides const foo = maybe1 > maybe2 ? 'bar' : maybeNull; ``` - - [15.6](#15.6) Avoid unneeded ternary statements. + - [15.7](#15.7) Avoid unneeded ternary statements. eslint rules: [`no-unneeded-ternary`](http://eslint.org/docs/rules/no-unneeded-ternary.html). From 714f71d1d2f9788742e0949dabb0cee4677e8929 Mon Sep 17 00:00:00 2001 From: Felix Sanz Date: Tue, 23 Feb 2016 01:25:02 +0100 Subject: [PATCH 0094/1167] Added getter/setter info I tried to search for getter/setter in the readme but nothing was found. Added some info to make a clear statement about them --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1dadba1dc..06a4eb6b43 100644 --- a/README.md +++ b/README.md @@ -1033,7 +1033,7 @@ Other Style Guides - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) - > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects. + > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. ```javascript const numbers = [1, 2, 3, 4, 5]; @@ -2217,7 +2217,7 @@ Other Style Guides ## Accessors - [23.1](#23.1) Accessor functions for properties are not required. - - [23.2](#23.2) If you do make accessor functions use getVal() and setVal('hello'). + - [23.2](#23.2) Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello'). ```javascript // bad From cba519a4424286bc3a2a9374b64d35e706be5632 Mon Sep 17 00:00:00 2001 From: Max Beier Date: Tue, 23 Feb 2016 15:07:17 +0100 Subject: [PATCH 0095/1167] Updated CHANGELOG.md --- packages/eslint-config-airbnb/CHANGELOG.md | 170 +++++++++++++-------- 1 file changed, 105 insertions(+), 65 deletions(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index c7cd9c97a9..109d7becd2 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,132 +1,172 @@ 6.0.2 / 2016-02-22 ================== -- [fix] disable `no-confusing-arrow` due to an `eslint` bug (#752) +- [fix] disable [`no-confusing-arrow`][no-confusing-arrow] due to an `eslint` bug ([#752](https://github.com/airbnb/javascript/issues/752)) 6.0.1 / 2016-02-21 ================== -- [fix] disable `newline-per-chained-call` due to an `eslint` bug (#748) +- [fix] disable [`newline-per-chained-call`][newline-per-chained-call] due to an `eslint` bug ([#748](https://github.com/airbnb/javascript/issues/748)) 6.0.0 / 2016-02-21 ================== -- [breaking] enable `array-callback-return` -- [breaking] enable `no-confusing-arrow` -- [breaking] enable `no-new-symbol` -- [breaking] enable `no-restricted-imports` -- [breaking] enable `no-useless-constructor` -- [breaking] enable `prefer-rest-params` -- [breaking] enable `template-curly-spaces` -- [breaking] enable `newline-per-chained-call` -- [breaking] enable `one-var-declaration-per-line` -- [breaking] enable `no-self-assign` -- [breaking] enable `no-whitespace-before-property` -- [breaking] [react] enable `react/jsx-space-before-closing` -- [breaking] [react] enable `static-methods` at top of `react/sort-comp` -- [breaking] [react] don't `ignoreTranspilerName` for `react/display-name` -- [peer+dev deps] update `eslint`, `eslint-plugin-react` (#730) (#730) (#730) (#730) +- [breaking] enable [`array-callback-return`][array-callback-return] +- [breaking] enable [`no-confusing-arrow`][no-confusing-arrow] +- [breaking] enable [`no-new-symbol`][no-new-symbol] +- [breaking] enable [`no-restricted-imports`][no-restricted-imports] +- [breaking] enable [`no-useless-constructor`][no-useless-constructor] +- [breaking] enable [`prefer-rest-params`][prefer-rest-params] +- [breaking] enable [`template-curly-spacing`][template-curly-spacing] +- [breaking] enable [`newline-per-chained-call`][newline-per-chained-call] +- [breaking] enable [`one-var-declaration-per-line`][one-var-declaration-per-line] +- [breaking] enable [`no-self-assign`][no-self-assign] +- [breaking] enable [`no-whitespace-before-property`][no-whitespace-before-property] +- [breaking] [react] enable [`react/jsx-space-before-closing`][react/jsx-space-before-closing] +- [breaking] [react] enable `static-methods` at top of [`react/sort-comp`][react/sort-comp] +- [breaking] [react] don't `ignoreTranspilerName` for [`react/display-name`][react/display-name] +- [peer+dev deps] update `eslint`, `eslint-plugin-react` ([#730](https://github.com/airbnb/javascript/issues/730)) 5.0.1 / 2016-02-13 ================== - - [fix] `eslint` peerDep should not include breaking changes +- [fix] `eslint` peerDep should not include breaking changes 5.0.0 / 2016-02-03 ================== - - [breaking] disallow unneeded ternary expressions - - [breaking] Avoid lexical declarations in case/default clauses - - [dev deps] update `babel-tape-runner`, `eslint-plugin-react`, `react`, `tape` +- [breaking] disallow unneeded ternary expressions +- [breaking] Avoid lexical declarations in case/default clauses +- [dev deps] update `babel-tape-runner`, `eslint-plugin-react`, `react`, `tape` 4.0.0 / 2016-01-22 ================== - - [breaking] require outer IIFE wrapping; flesh out guide section - - [minor] Add missing `arrow-body-style`, `prefer-template` rules (#678) - - [minor] Add `prefer-arrow-callback` to ES6 rules (to match the guide) (#677) - - [Tests] run `npm run lint` as part of tests; fix errors - - [Tests] use `parallelshell` to parallelize npm run-scripts +- [breaking] require outer IIFE wrapping; flesh out guide section +- [minor] Add missing [`arrow-body-style`][arrow-body-style], [`prefer-template`][prefer-template] rules ([#678](https://github.com/airbnb/javascript/issues/678)) +- [minor] Add [`prefer-arrow-callback`][prefer-arrow-callback] to ES6 rules (to match the guide) ([#677](https://github.com/airbnb/javascript/issues/677)) +- [Tests] run `npm run lint` as part of tests; fix errors +- [Tests] use `parallelshell` to parallelize npm run-scripts 3.1.0 / 2016-01-07 ================== - - [minor] Allow multiple stateless components in a single file +- [minor] Allow multiple stateless components in a single file 3.0.2 / 2016-01-06 ================== - - [fix] Ignore URLs in `max-len` (#664) +- [fix] Ignore URLs in [`max-len`][max-len] ([#664](https://github.com/airbnb/javascript/issues/664)) 3.0.1 / 2016-01-06 ================== - - [fix] because we use babel, keywords should not be quoted +- [fix] because we use babel, keywords should not be quoted 3.0.0 / 2016-01-04 ================== - - [breaking] enable `quote-props` rule (#632) - - [breaking] Define a max line length of 100 characters (#639) - - [breaking] [react] Minor cleanup for the React styleguide, add `react/jsx-no-bind` (#619) - - [breaking] update best-practices config to prevent parameter object manipulation (#627) - - [minor] Enable react/no-is-mounted rule (#635, #633) - - [minor] Sort react/prefer-es6-class alphabetically (#634) - - [minor] enable react/prefer-es6-class rule - - Permit strict mode in "legacy" config - - [react] add missing rules from eslint-plugin-react (enforcing where necessary) (#581) - - [dev deps] update `eslint-plugin-react` +- [breaking] enable [`quote-props`][quote-props] rule ([#632](https://github.com/airbnb/javascript/issues/632)) +- [breaking] Define a max line length of 100 characters ([#639](https://github.com/airbnb/javascript/issues/639)) +- [breaking] [react] Minor cleanup for the React styleguide, add [`react/jsx-no-bind`][react/jsx-no-bind] ([#619](https://github.com/airbnb/javascript/issues/619)) +- [breaking] update best-practices config to prevent parameter object manipulation ([#627](https://github.com/airbnb/javascript/issues/627)) +- [minor] Enable [`react/no-is-mounted`][react/no-is-mounted] rule (#635, #633) +- [minor] Sort [`react/prefer-es6-class`][react/prefer-es6-class] alphabetically ([#634](https://github.com/airbnb/javascript/issues/634)) +- [minor] enable [`react/prefer-es6-class`][react/prefer-es6-class] rule +- Permit strict mode in "legacy" config +- [react] add missing rules from `eslint-plugin-react` (enforcing where necessary) ([#581](https://github.com/airbnb/javascript/issues/581)) +- [dev deps] update `eslint-plugin-react` 2.1.1 / 2015-12-15 ================== - - [fix] Remove deprecated react/jsx-quotes (#622) +- [fix] Remove deprecated [`react/jsx-quotes`][react/jsx-quotes] ([#622](https://github.com/airbnb/javascript/issues/622)) 2.1.0 / 2015-12-15 ================== - - [fix] use `require.resolve` to allow nested `extend`s (#582) - - [new] enable `object-shorthand` rule (#621) - - [new] enable `arrow-spacing` rule (#517) - - [docs] flesh out react rule defaults (#618) +- [fix] use `require.resolve` to allow nested `extend`s ([#582](https://github.com/airbnb/javascript/issues/582)) +- [new] enable [`object-shorthand`][object-shorthand] rule ([#621](https://github.com/airbnb/javascript/issues/621)) +- [new] enable [`arrow-spacing`][arrow-spacing] rule ([#517](https://github.com/airbnb/javascript/issues/517)) +- [docs] flesh out react rule defaults ([#618](https://github.com/airbnb/javascript/issues/618)) 2.0.0 / 2015-12-03 ================== - - [breaking] `space-before-function-paren`: require function spacing: `function (` (#605) - - [breaking] `indent`: Fix switch statement indentation rule (#606) - - [breaking] `array-bracket-spacing`, `computed-property-spacing`: disallow spacing inside brackets (#594) - - [breaking] `object-curly-spacing`: require padding inside curly braces (#594) - - [breaking] `space-in-parens`: disallow spaces in parens (#594) +- [breaking] [`space-before-function-paren`][space-before-function-paren]: require function spacing: `function (` ([#605](https://github.com/airbnb/javascript/issues/605)) +- [breaking] [`indent`][indent]: Fix switch statement indentation rule ([#606](https://github.com/airbnb/javascript/issues/606)) +- [breaking] [`array-bracket-spacing`][array-bracket-spacing], [`computed-property-spacing`][computed-property-spacing]: disallow spacing inside brackets ([#594](https://github.com/airbnb/javascript/issues/594)) +- [breaking] [`object-curly-spacing`][object-curly-spacing]: require padding inside curly braces ([#594](https://github.com/airbnb/javascript/issues/594)) +- [breaking] [`space-in-parens`][space-in-parens]: disallow spaces in parens ([#594](https://github.com/airbnb/javascript/issues/594)) 1.0.2 / 2015-11-25 ================== - - [breaking] `no-multiple-empty-lines`: only allow 1 blank line at EOF (#578) - - [new] `restParams`: enable rest params (#592) +- [breaking] [`no-multiple-empty-lines`][no-multiple-empty-lines]: only allow 1 blank line at EOF ([#578](https://github.com/airbnb/javascript/issues/578)) +- [new] `restParams`: enable rest params ([#592](https://github.com/airbnb/javascript/issues/592)) 1.0.1 / 2015-11-25 ================== - - *erroneous publish* +- *erroneous publish* 1.0.0 / 2015-11-08 ================== - - require `eslint` `v1.0.0` or higher - - remove `babel-eslint` dependency +- require `eslint` `v1.0.0` or higher +- remove `babel-eslint` dependency 0.1.1 / 2015-11-05 ================== - - remove id-length rule (#569) - - enable `no-mixed-spaces-and-tabs` (#539) - - enable `no-const-assign` (#560) - - enable `space-before-keywords` (#554) +- remove [`id-length`][id-length] rule ([#569](https://github.com/airbnb/javascript/issues/569)) +- enable [`no-mixed-spaces-and-tabs`][no-mixed-spaces-and-tabs] ([#539](https://github.com/airbnb/javascript/issues/539)) +- enable [`no-const-assign`][no-const-assign] ([#560](https://github.com/airbnb/javascript/issues/560)) +- enable [`space-before-keywords`][space-before-keywords] ([#554](https://github.com/airbnb/javascript/issues/554)) 0.1.0 / 2015-11-05 ================== - - switch to modular rules files courtesy the [eslint-config-default][ecd] project and [@taion][taion]. [PR][pr-modular] - - export `eslint-config-airbnb/legacy` for ES5-only users. `eslint-config-airbnb/legacy` does not require the `babel-eslint` parser. [PR][pr-legacy] +- switch to modular rules files courtesy the [eslint-config-default][ecd] project and [@taion][taion]. [PR][pr-modular] +- export `eslint-config-airbnb/legacy` for ES5-only users. `eslint-config-airbnb/legacy` does not require the `babel-eslint` parser. [PR][pr-legacy] 0.0.9 / 2015-09-24 ================== -- add rule `no-undef` -- add rule `id-length` +- add rule [`no-undef`][no-undef] +- add rule [`id-length`][id-length] 0.0.8 / 2015-08-21 ================== - - now has a changelog - - now is modular (see instructions above for with react and without react versions) +- now has a changelog +- now is modular (see instructions above for with react and without react versions) 0.0.7 / 2015-07-30 ================== - - TODO: fill in +- TODO: fill in + [ecd]: https://github.com/walmartlabs/eslint-config-defaults [taion]: https://github.com/taion [pr-modular]: https://github.com/airbnb/javascript/pull/526 [pr-legacy]: https://github.com/airbnb/javascript/pull/527 + +[array-bracket-spacing]: http://eslint.org/docs/rules/array-bracket-spacing +[array-callback-return]: http://eslint.org/docs/rules/array-callback-return +[arrow-body-style]: http://eslint.org/docs/rules/arrow-body-style +[arrow-spacing]: http://eslint.org/docs/rules/arrow-spacing +[computed-property-spacing]: http://eslint.org/docs/rules/computed-property-spacing +[id-length]: http://eslint.org/docs/rules/id-length +[indent]: http://eslint.org/docs/rules/indent +[max-len]: http://eslint.org/docs/rules/max-len +[newline-per-chained-call]: http://eslint.org/docs/rules/newline-per-chained-call +[no-confusing-arrow]: http://eslint.org/docs/rules/no-confusing-arrow +[no-const-assign]: http://eslint.org/docs/rules/no-const-assign +[no-mixed-spaces-and-tabs]: http://eslint.org/docs/rules/no-mixed-spaces-and-tabs +[no-multiple-empty-lines]: http://eslint.org/docs/rules/no-multiple-empty-lines +[no-new-symbol]: http://eslint.org/docs/rules/no-new-symbol +[no-restricted-imports]: http://eslint.org/docs/rules/no-restricted-imports +[no-self-assign]: http://eslint.org/docs/rules/no-self-assign +[no-undef]: http://eslint.org/docs/rules/no-undef +[no-useless-constructor]: http://eslint.org/docs/rules/no-useless-constructor +[no-whitespace-before-property]: http://eslint.org/docs/rules/no-whitespace-before-property +[object-curly-spacing]: http://eslint.org/docs/rules/object-curly-spacing +[object-shorthand]: http://eslint.org/docs/rules/object-shorthand +[one-var-declaration-per-line]: http://eslint.org/docs/rules/one-var-declaration-per-line +[prefer-arrow-callback]: http://eslint.org/docs/rules/prefer-arrow-callback +[prefer-rest-params]: http://eslint.org/docs/rules/prefer-rest-params +[prefer-template]: http://eslint.org/docs/rules/prefer-template +[quote-props]: http://eslint.org/docs/rules/quote-props +[space-before-function-paren]: http://eslint.org/docs/rules/space-before-function-paren +[space-before-keywords]: http://eslint.org/docs/rules/space-before-keywords +[space-in-parens]: http://eslint.org/docs/rules/space-in-parens +[template-curly-spacing]: http://eslint.org/docs/rules/template-curly-spacing + +[react/jsx-space-before-closing]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md +[react/sort-comp]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md +[react/display-name]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md +[react/jsx-no-bind]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md +[react/no-is-mounted]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md +[react/prefer-es6-class]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md +[react/jsx-quotes]: https://github.com/yannickcr/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md \ No newline at end of file From 30c448d1df2c5a16bee4dd618ebdcf908b7475a3 Mon Sep 17 00:00:00 2001 From: David Bows Date: Tue, 23 Feb 2016 07:18:10 -0500 Subject: [PATCH 0096/1167] Updated "In The Wild" to include Brainshark. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 06a4eb6b43..e4ced5f970 100644 --- a/README.md +++ b/README.md @@ -2520,6 +2520,7 @@ Other Style Guides - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/) - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript) + - **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript) - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide) - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) From 2d8409c3e549f082f30c37d62d64304289380f52 Mon Sep 17 00:00:00 2001 From: Javier Villanueva Date: Wed, 24 Feb 2016 11:03:46 +0000 Subject: [PATCH 0097/1167] Enforce literal syntax for array creation --- packages/eslint-config-airbnb/rules/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index b9b0e23f5c..6e1278161a 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -64,7 +64,7 @@ module.exports = { // http://eslint.org/docs/rules/newline-per-chained-call 'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 3 }], // disallow use of the Array constructor - 'no-array-constructor': 0, + 'no-array-constructor': 2, // disallow use of the continue statement 'no-continue': 0, // disallow comments inline after code From d321f68c462acbec50d9cf6a977f1a4a50e8924e Mon Sep 17 00:00:00 2001 From: Nick Hwang Date: Wed, 24 Feb 2016 13:53:14 -0500 Subject: [PATCH 0098/1167] Fix word spacing and preserve consistent quotes --- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- packages/eslint-config-airbnb/rules/react.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 6f66792478..ff782a5b7a 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -76,7 +76,7 @@ module.exports = { 'no-new': 2, // disallow use of new operator for Function object 'no-new-func': 2, - // disallows creating new instances of String,Number, and Boolean + // disallows creating new instances of String, Number, and Boolean 'no-new-wrappers': 2, // disallow use of (old style) octal literals 'no-octal': 2, diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index b7a9889e69..6071cd3004 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -106,7 +106,7 @@ module.exports = { 'react/prefer-es6-class': [2, 'always'], // Prevent missing props validation in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md - 'react/prop-types': [2, { 'ignore': [], customValidators: [] }], + 'react/prop-types': [2, { 'ignore': [], 'customValidators': [] }], // Prevent missing React when using JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md 'react/react-in-jsx-scope': 2, From 7684892951ef663e1c4e62ad57d662e9b2748b9e Mon Sep 17 00:00:00 2001 From: Boris Besemer Date: Thu, 25 Feb 2016 09:12:52 +0100 Subject: [PATCH 0099/1167] fixes tiny typo's on JSCS rules --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4ced5f970..44a317e0bd 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ Other Style Guides const item = {}; ``` - - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) + - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -161,7 +161,7 @@ Other Style Guides }; ``` - - [3.3](#3.3) Use readable synonyms in place of reserved words. jscs: [`disallowIdentiferNames`](http://jscs.info/rule/disallowIdentifierNames) + - [3.3](#3.3) Use readable synonyms in place of reserved words. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad From 607ad012eeaa4e72601b381d49ddb905dee2f138 Mon Sep 17 00:00:00 2001 From: chief10 Date: Tue, 1 Mar 2016 15:28:10 -0600 Subject: [PATCH 0100/1167] change wording for 8.2 for consistency --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 44a317e0bd..32068abd57 100644 --- a/README.md +++ b/README.md @@ -759,15 +759,15 @@ Other Style Guides > Why not? If you plan on returning an object. ```javascript - // good - [1, 2, 3].map(number => `A string containing the ${number}.`); - // bad [1, 2, 3].map(number => { const nextNumber = number + 1; `A string containing the ${nextNumber}.`; }); + // good + [1, 2, 3].map(number => `A string containing the ${number}.`); + // good [1, 2, 3].map((number) => { const nextNumber = number + 1; From 246cde0de837218c16595246f81c900320c57c0b Mon Sep 17 00:00:00 2001 From: Hyeonsu Lee Date: Wed, 2 Mar 2016 10:25:02 +0900 Subject: [PATCH 0101/1167] Fix the typo error in JSHint link --- es5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es5/README.md b/es5/README.md index 2d24f1a4a2..caaa17b503 100644 --- a/es5/README.md +++ b/es5/README.md @@ -1562,7 +1562,7 @@ **Tools** - Code Style Linters - + [JSHint](http://www.jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc) + + [JSHint](http://www.jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/.jshintrc) + [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json) **Other Style Guides** From 32e3e0f45a60aeed038619116548de6ff8197c16 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Duhaime Date: Wed, 2 Mar 2016 09:42:02 -0500 Subject: [PATCH 0102/1167] Update README.md Add colon to TODO and FIXME. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32068abd57..875c1a724d 100644 --- a/README.md +++ b/README.md @@ -1550,7 +1550,7 @@ Other Style Guides } ``` - - [17.3](#17.3) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`. + - [17.3](#17.3) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME: -- need to figure this out` or `TODO: -- need to implement`. - [17.4](#17.4) Use `// FIXME:` to annotate problems. From 03d0054a46dff8b8fc337a39b84acf69e420e678 Mon Sep 17 00:00:00 2001 From: David Petersen Date: Wed, 2 Mar 2016 09:11:46 -0600 Subject: [PATCH 0103/1167] Enable react/prefer-stateless-function rule --- packages/eslint-config-airbnb/rules/react.js | 3 +++ react/README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 6071cd3004..835fb43125 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -104,6 +104,9 @@ module.exports = { // Require ES6 class declarations over React.createClass // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md 'react/prefer-es6-class': [2, 'always'], + // Require stateless functions when not using lifecycle methods, setState or ref + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md + 'react/prefer-stateless-function': 2, // Prevent missing props validation in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md 'react/prop-types': [2, { 'ignore': [], 'customValidators': [] }], diff --git a/react/README.md b/react/README.md index e0351f42a7..8bab601e12 100644 --- a/react/README.md +++ b/react/README.md @@ -27,7 +27,7 @@ ## Class vs `React.createClass` vs stateless - - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) + - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) ```javascript // bad From 762b7510ab8ff0e3f282c9ae6cc985f8262038a8 Mon Sep 17 00:00:00 2001 From: Jon Tejada Date: Thu, 3 Mar 2016 15:21:53 -0800 Subject: [PATCH 0104/1167] fixed a broken link to REI's JS style guide --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 875c1a724d..d7b56aae9a 100644 --- a/README.md +++ b/README.md @@ -2560,7 +2560,7 @@ Other Style Guides - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide) - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript) - **React**: [/facebook/react/blob/master/CONTRIBUTING.md#style-guide](https://github.com/facebook/react/blob/master/CONTRIBUTING.md#style-guide) - - **REI**: [reidev/js-style-guide](https://github.com/reidev/js-style-guide) + - **REI**: [reidev/js-style-guide](https://github.com/rei/code-style-guides/blob/master/docs/javascript.md) - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide) - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide) - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) From 87616367cbf0a298a6e5f3a85cdd4f1ba317ea57 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 4 Mar 2016 20:05:42 -0800 Subject: [PATCH 0105/1167] [Dev Deps] update `eslint`, `tape`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 6 +++--- packages/eslint-config-airbnb/rules/es6.js | 2 ++ packages/eslint-config-airbnb/rules/style.js | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 9478f804fd..dd86cda2d0 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,10 +43,10 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.2.0", - "eslint-plugin-react": "^4.0.0", + "eslint": "^2.3.0", + "eslint-plugin-react": "^4.1.0", "react": "^0.14.7", - "tape": "^4.4.0", + "tape": "^4.5.0", "parallelshell": "^2.0.0" }, "peerDependencies": { diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index ef50e0a7f5..d0b7bbde9f 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -36,6 +36,8 @@ module.exports = { // disallow symbol constructor // http://eslint.org/docs/rules/no-new-symbol 'no-new-symbol': 2, + // disallow specific globals + 'no-restricted-globals': 0, // disallow specific imports // http://eslint.org/docs/rules/no-restricted-imports 'no-restricted-imports': 0, diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 6e1278161a..d811f8851f 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -59,6 +59,8 @@ module.exports = { 'new-parens': 0, // allow/disallow an empty newline after var statement 'newline-after-var': 0, + // http://eslint.org/docs/rules/newline-before-return + 'newline-before-return': 0, // enforces new line after each method call in the chain to make it // more readable and easy to maintain // http://eslint.org/docs/rules/newline-per-chained-call From 7b8a0ca85d11d01dabfd51bdd0125c3624a1a0e3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Mar 2016 14:19:34 -0800 Subject: [PATCH 0106/1167] [Dev Deps] update `eslint-plugin-react` (new rule is in #772) --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index dd86cda2d0..068cbab823 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -44,7 +44,7 @@ "devDependencies": { "babel-tape-runner": "^1.3.1", "eslint": "^2.3.0", - "eslint-plugin-react": "^4.1.0", + "eslint-plugin-react": "^4.2.0", "react": "^0.14.7", "tape": "^4.5.0", "parallelshell": "^2.0.0" From 0ece94f5bf2575b20ff69d38c6660da52382fb33 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 5 Mar 2016 14:43:58 -0800 Subject: [PATCH 0107/1167] [eslint config] v6.1.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 5 +++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 109d7becd2..bb9374e170 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,8 @@ +6.1.0 / 2016-02-22 +================== +- [new] enable [`react/prefer-stateless-function`][react/prefer-stateless-function] +- [dev deps] update `react-plugin-eslint`, `eslint`, `tape` + 6.0.2 / 2016-02-22 ================== - [fix] disable [`no-confusing-arrow`][no-confusing-arrow] due to an `eslint` bug ([#752](https://github.com/airbnb/javascript/issues/752)) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 068cbab823..9c26a62532 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.0.2", + "version": "6.1.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 8b6abf8cda2be140a15bb08deca2770d419d2882 Mon Sep 17 00:00:00 2001 From: Maks Sadowsky Date: Sun, 6 Mar 2016 11:01:01 +0200 Subject: [PATCH 0108/1167] Update README: Document corresponding jscs rules --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d7b56aae9a..f3e09449f8 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,7 @@ Other Style Guides const [first, second] = arr; ``` - - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring. + - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn) > Why? You can add new properties over time or change the order of things without breaking call sites. From e7f5e0f336501282bfdfc7a58424d140fb543533 Mon Sep 17 00:00:00 2001 From: giang pi Date: Mon, 7 Mar 2016 14:01:57 +0700 Subject: [PATCH 0109/1167] Vietnamese language --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f3e09449f8..b8c355601d 100644 --- a/README.md +++ b/README.md @@ -2595,6 +2595,7 @@ Other Style Guides - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [uprock/javascript](https://github.com/uprock/javascript) - ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide) - ![th](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Thailand.png) **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide) + - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [giangpii/javascript-style-guide](https://github.com/giangpii/javascript-style-guide) ## The JavaScript Style Guide Guide From 34f64c21e56df09e548d04f29e16664b80fc1b93 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 Mar 2016 14:16:06 -0800 Subject: [PATCH 0110/1167] Add defaults for `react/jsx-no-bind` --- packages/eslint-config-airbnb/rules/react.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 835fb43125..a5d0d17de2 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -40,7 +40,11 @@ module.exports = { 'react/jsx-max-props-per-line': [0, { 'maximum': 1 }], // Prevent usage of .bind() and arrow functions in JSX props // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md - 'react/jsx-no-bind': 2, + 'react/jsx-no-bind': [2, { + 'ignoreRefs': false, + 'allowArrowFunctions': false, + 'allowBind': false, + }], // Prevent duplicate props in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md 'react/jsx-no-duplicate-props': [0, { 'ignoreCase': false }], From 01fc30b65b64ad9485dfccd8f64257e77475dd83 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 Mar 2016 14:48:32 -0800 Subject: [PATCH 0111/1167] [Dev Deps] update `tape` --- packages/eslint-config-airbnb/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 9c26a62532..0721839841 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -46,7 +46,7 @@ "eslint": "^2.3.0", "eslint-plugin-react": "^4.2.0", "react": "^0.14.7", - "tape": "^4.5.0", + "tape": "^4.5.1", "parallelshell": "^2.0.0" }, "peerDependencies": { From 9e87e1d13bb8258adcdc7b05c7bece52adc1abbb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 8 Mar 2016 10:07:30 -0800 Subject: [PATCH 0112/1167] [guide] add some more justification for one-var and `String()` type coercions --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b8c355601d..97530e537a 100644 --- a/README.md +++ b/README.md @@ -590,7 +590,7 @@ Other Style Guides - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) - > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`. + > Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`. ```javascript // bad @@ -1112,7 +1112,7 @@ Other Style Guides - [13.2](#13.2) Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) - > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. + > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once. ```javascript // bad @@ -1339,6 +1339,7 @@ Other Style Guides ``` - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. + - [15.5](#15.5) Use braces to create blocks in `case` and `default` clauses that contain lexical declarations (e.g. `let`, `const`, `function`, and `class`). > Why? Lexical declarations are visible in the entire `switch` block but only get initialized when assigned, which only happens when its `case` is reached. This causes problems when multiple `case` clauses attempt to define the same thing. @@ -2011,7 +2012,10 @@ Other Style Guides // => this.reviewScore = 9; // bad - const totalScore = this.reviewScore + ''; + const totalScore = this.reviewScore + ''; // invokes this.reviewScore.valueOf() + + // bad + const totalScore = this.reviewScore.toString(); // isn't guaranteed to return a string // good const totalScore = String(this.reviewScore); From 4709e644c0a622e020c3d5446a4cb1f22e910b10 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 Mar 2016 22:50:40 -0800 Subject: [PATCH 0113/1167] [guide] Permanent links. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Preserve the original links, because cool URLs don’t change. --- README.md | 376 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 247 insertions(+), 129 deletions(-) diff --git a/README.md b/README.md index 97530e537a..5368efacf7 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ Other Style Guides ## Types - - [1.1](#1.1) **Primitives**: When you access a primitive type you work directly on its value. + + - [1.1](#types--primitives) **Primitives**: When you access a primitive type you work directly on its value. + `string` + `number` @@ -68,7 +69,9 @@ Other Style Guides console.log(foo, bar); // => 1, 9 ``` - - [1.2](#1.2) **Complex**: When you access a complex type you work on a reference to its value. + + + - [1.2](#types--complex) **Complex**: When you access a complex type you work on a reference to its value. + `object` + `array` @@ -87,7 +90,8 @@ Other Style Guides ## References - - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. eslint: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html) + + - [2.1](#references--prefer-const) Use `const` for all of your references; avoid using `var`. eslint: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html) > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. @@ -101,7 +105,8 @@ Other Style Guides const b = 2; ``` - - [2.2](#2.2) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](http://eslint.org/docs/rules/no-var.html) jscs: [`disallowVar`](http://jscs.info/rule/disallowVar) + + - [2.2](#references--disallow-var) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](http://eslint.org/docs/rules/no-var.html) jscs: [`disallowVar`](http://jscs.info/rule/disallowVar) > Why? `let` is block-scoped rather than function-scoped like `var`. @@ -119,7 +124,8 @@ Other Style Guides } ``` - - [2.3](#2.3) Note that both `let` and `const` are block-scoped. + + - [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped. ```javascript // const and let only exist in the blocks they are defined in. @@ -135,7 +141,8 @@ Other Style Guides ## Objects - - [3.1](#3.1) Use the literal syntax for object creation. eslint: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html) + + - [3.1](#objects--no-new) Use the literal syntax for object creation. eslint: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html) ```javascript // bad @@ -145,7 +152,8 @@ Other Style Guides const item = {}; ``` - - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) + + - [3.2](#objects--reserved-words) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -161,7 +169,8 @@ Other Style Guides }; ``` - - [3.3](#3.3) Use readable synonyms in place of reserved words. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) + + - [3.3](#objects--reserved-words-2) Use readable synonyms in place of reserved words. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames) ```javascript // bad @@ -180,8 +189,8 @@ Other Style Guides }; ``` - - - [3.4](#3.4) Use computed property names when creating objects with dynamic property names. + + - [3.4](#es6-computed-properties) Use computed property names when creating objects with dynamic property names. > Why? They allow you to define all the properties of an object in one place. @@ -206,8 +215,8 @@ Other Style Guides }; ``` - - - [3.5](#3.5) Use object method shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + + - [3.5](#es6-object-shorthand) Use object method shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) ```javascript // bad @@ -229,8 +238,8 @@ Other Style Guides }; ``` - - - [3.6](#3.6) Use property value shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) + + - [3.6](#es6-object-concise) Use property value shorthand. eslint: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html) jscs: [`requireEnhancedObjectLiterals`](http://jscs.info/rule/requireEnhancedObjectLiterals) > Why? It is shorter to write and descriptive. @@ -248,7 +257,8 @@ Other Style Guides }; ``` - - [3.7](#3.7) Group your shorthand properties at the beginning of your object declaration. + + - [3.7](#objects--grouped-shorthand) Group your shorthand properties at the beginning of your object declaration. > Why? It's easier to tell which properties are using the shorthand. @@ -277,7 +287,8 @@ Other Style Guides }; ``` - - [3.8](#3.8) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) + + - [3.8](#objects-quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects) > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. @@ -301,7 +312,8 @@ Other Style Guides ## Arrays - - [4.1](#4.1) Use the literal syntax for array creation. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html) + + - [4.1](#arrays--literals) Use the literal syntax for array creation. eslint: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html) ```javascript // bad @@ -311,7 +323,8 @@ Other Style Guides const items = []; ``` - - [4.2](#4.2) Use Array#push instead of direct assignment to add items to an array. + + - [4.2](#arrays--push) Use Array#push instead of direct assignment to add items to an array. ```javascript const someStack = []; @@ -323,8 +336,8 @@ Other Style Guides someStack.push('abracadabra'); ``` - - - [4.3](#4.3) Use array spreads `...` to copy arrays. + + - [4.3](#es6-array-spreads) Use array spreads `...` to copy arrays. ```javascript // bad @@ -339,14 +352,17 @@ Other Style Guides // good const itemsCopy = [...items]; ``` - - [4.4](#4.4) To convert an array-like object to an array, use Array#from. + + + - [4.4](#arrays--from) To convert an array-like object to an array, use Array#from. ```javascript const foo = document.querySelectorAll('.foo'); const nodes = Array.from(foo); ``` - - [4.5](#4.5) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return) + + - [4.5](#arrays--callback-return) Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return) ```javascript // good @@ -398,7 +414,8 @@ Other Style Guides ## Destructuring - - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) + + - [5.1](#destructuring--object) Use object destructuring when accessing and using multiple properties of an object. jscs: [`requireObjectDestructuring`](http://jscs.info/rule/requireObjectDestructuring) > Why? Destructuring saves you from creating temporary references for those properties. @@ -423,7 +440,8 @@ Other Style Guides } ``` - - [5.2](#5.2) Use array destructuring. jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) + + - [5.2](#destructuring--array) Use array destructuring. jscs: [`requireArrayDestructuring`](http://jscs.info/rule/requireArrayDestructuring) ```javascript const arr = [1, 2, 3, 4]; @@ -436,7 +454,8 @@ Other Style Guides const [first, second] = arr; ``` - - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn) + + - [5.3](#destructuring--object-over-array) Use object destructuring for multiple return values, not array destructuring. jscs: [`disallowArrayDestructuringReturn`](http://jscs.info/rule/disallowArrayDestructuringReturn) > Why? You can add new properties over time or change the order of things without breaking call sites. @@ -465,7 +484,8 @@ Other Style Guides ## Strings - - [6.1](#6.1) Use single quotes `''` for strings. eslint: [`quotes`](http://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) + + - [6.1](#strings--quotes) Use single quotes `''` for strings. eslint: [`quotes`](http://eslint.org/docs/rules/quotes.html) jscs: [`validateQuoteMarks`](http://jscs.info/rule/validateQuoteMarks) ```javascript // bad @@ -475,8 +495,11 @@ Other Style Guides const name = 'Capt. Janeway'; ``` - - [6.2](#6.2) Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation. - - [6.3](#6.3) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). + + - [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation. + + + - [6.3](#strings--concat-perf) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). ```javascript // bad @@ -494,8 +517,8 @@ Other Style Guides 'with this, you would get nowhere fast.'; ``` - - - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) + + - [6.4](#es6-template-literals) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings) > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. @@ -520,14 +543,17 @@ Other Style Guides return `How are you, ${name}?`; } ``` - - [6.5](#6.5) Never use `eval()` on a string, it opens too many vulnerabilities. + + + - [6.5](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities. **[⬆ back to top](#table-of-contents)** ## Functions - - [7.1](#7.1) Use function declarations instead of function expressions. jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) + + - [7.1](#functions--declarations) Use function declarations instead of function expressions. jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. @@ -541,7 +567,8 @@ Other Style Guides } ``` - - [7.2](#7.2) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) + + - [7.2](#functions--iife) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) > Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE. @@ -552,9 +579,11 @@ Other Style Guides }()); ``` - - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html) + + - [7.3](#functions--in-blocks) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [`no-loop-func`](http://eslint.org/docs/rules/no-loop-func.html) - - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). + + - [7.4](#functions--note-on-blocks) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). ```javascript // bad @@ -573,7 +602,8 @@ Other Style Guides } ``` - - [7.5](#7.5) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope. + + - [7.5](#functions--arguments-shadow) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope. ```javascript // bad @@ -587,8 +617,8 @@ Other Style Guides } ``` - - - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) + + - [7.6](#es6-rest) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params) > Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`. @@ -605,8 +635,8 @@ Other Style Guides } ``` - - - [7.7](#7.7) Use default parameter syntax rather than mutating function arguments. + + - [7.7](#es6-default-parameters) Use default parameter syntax rather than mutating function arguments. ```javascript // really bad @@ -632,7 +662,8 @@ Other Style Guides } ``` - - [7.8](#7.8) Avoid side effects with default parameters. + + - [7.8](#functions--default-side-effects) Avoid side effects with default parameters. > Why? They are confusing to reason about. @@ -648,7 +679,8 @@ Other Style Guides count(); // 3 ``` - - [7.9](#7.9) Always put default parameters last. + + - [7.9](#functions--defaults-last) Always put default parameters last. ```javascript // bad @@ -662,7 +694,8 @@ Other Style Guides } ``` - - [7.10](#7.10) Never use the Function constructor to create a new function. + + - [7.10](#functions--constructor) Never use the Function constructor to create a new function. > Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities. @@ -674,7 +707,8 @@ Other Style Guides var subtract = Function('a', 'b', 'return a - b'); ``` - - [7.11](#7.11) Spacing in a function signature. + + - [7.11](#functions--signature-spacing) Spacing in a function signature. > Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name. @@ -689,7 +723,8 @@ Other Style Guides const y = function a() {}; ``` - - [7.12](#7.12) Never mutate parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) + + - [7.12](#functions--mutate-params) Never mutate parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller. @@ -705,7 +740,8 @@ Other Style Guides }; ``` - - [7.13](#7.13) Never reassign parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) + + - [7.13](#functions--reassign-params) Never reassign parameters. eslint: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html) > Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8. @@ -732,7 +768,8 @@ Other Style Guides ## Arrow Functions - - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation. eslint: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) + + - [8.1](#arrows--use-them) When you must use function expressions (as when passing an anonymous function), use arrow function notation. eslint: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html) jscs: [`requireArrowFunctions`](http://jscs.info/rule/requireArrowFunctions) > Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax. @@ -752,7 +789,8 @@ Other Style Guides }); ``` - - [8.2](#8.2) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions) + + - [8.2](#arrows--implicit-return) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam), [`requireShorthandArrowFunctions`](http://jscs.info/rule/requireShorthandArrowFunctions) > Why? Syntactic sugar. It reads well when multiple functions are chained together. @@ -775,7 +813,8 @@ Other Style Guides }); ``` - - [8.3](#8.3) In case the expression spans over multiple lines, wrap it in parentheses for better readability. + + - [8.3](#arrows--paren-wrap) In case the expression spans over multiple lines, wrap it in parentheses for better readability. > Why? It shows clearly where the function starts and ends. @@ -793,8 +832,8 @@ Other Style Guides )); ``` - - - [8.4](#8.4) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) + + - [8.4](#arrows--one-arg-parens) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. eslint: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html) jscs: [`disallowParenthesesAroundArrowParam`](http://jscs.info/rule/disallowParenthesesAroundArrowParam) > Why? Less visual clutter. @@ -824,7 +863,8 @@ Other Style Guides }); ``` - - [8.5](#8.5) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](http://eslint.org/docs/rules/no-confusing-arrow) + + - [8.5](#arrows--confusing) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](http://eslint.org/docs/rules/no-confusing-arrow) ```js // bad @@ -842,7 +882,8 @@ Other Style Guides ## Constructors - - [9.1](#9.1) Always use `class`. Avoid manipulating `prototype` directly. + + - [9.1](#constructors--use-class) Always use `class`. Avoid manipulating `prototype` directly. > Why? `class` syntax is more concise and easier to reason about. @@ -871,7 +912,8 @@ Other Style Guides } ``` - - [9.2](#9.2) Use `extends` for inheritance. + + - [9.2](#constructors--extends) Use `extends` for inheritance. > Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`. @@ -894,7 +936,8 @@ Other Style Guides } ``` - - [9.3](#9.3) Methods can return `this` to help with method chaining. + + - [9.3](#constructors--chaining) Methods can return `this` to help with method chaining. ```javascript // bad @@ -931,7 +974,8 @@ Other Style Guides ``` - - [9.4](#9.4) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects. + + - [9.4](#constructors--tostring) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects. ```javascript class Jedi { @@ -949,7 +993,8 @@ Other Style Guides } ``` - - [9.5](#9.5) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) + + - [9.5](#constructors--no-useless) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) ```javascript // bad @@ -982,7 +1027,8 @@ Other Style Guides ## Modules - - [10.1](#10.1) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system. + + - [10.1](#modules--use-them) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system. > Why? Modules are the future, let's start using the future now. @@ -1000,7 +1046,8 @@ Other Style Guides export default es6; ``` - - [10.2](#10.2) Do not use wildcard imports. + + - [10.2](#modules--no-wildcard) Do not use wildcard imports. > Why? This makes sure you have a single default export. @@ -1012,7 +1059,8 @@ Other Style Guides import AirbnbStyleGuide from './AirbnbStyleGuide'; ``` - - [10.3](#10.3) And do not export directly from an import. + + - [10.3](#modules--no-export-from-import) And do not export directly from an import. > Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent. @@ -1031,7 +1079,8 @@ Other Style Guides ## Iterators and Generators - - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) + + - [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. @@ -1056,7 +1105,8 @@ Other Style Guides sum === 15; ``` - - [11.2](#11.2) Don't use generators for now. + + - [11.2](#generators--nope) Don't use generators for now. > Why? They don't transpile well to ES5. @@ -1065,7 +1115,8 @@ Other Style Guides ## Properties - - [12.1](#12.1) Use dot notation when accessing properties. eslint: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html) jscs: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation) + + - [12.1](#properties--dot) Use dot notation when accessing properties. eslint: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html) jscs: [`requireDotNotation`](http://jscs.info/rule/requireDotNotation) ```javascript const luke = { @@ -1080,7 +1131,8 @@ Other Style Guides const isJedi = luke.jedi; ``` - - [12.2](#12.2) Use subscript notation `[]` when accessing properties with a variable. + + - [12.2](#properties--bracket) Use bracket notation `[]` when accessing properties with a variable. ```javascript const luke = { @@ -1100,7 +1152,8 @@ Other Style Guides ## Variables - - [13.1](#13.1) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. + + - [13.1](#variables--const) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. ```javascript // bad @@ -1110,7 +1163,8 @@ Other Style Guides const superPower = new SuperPower(); ``` - - [13.2](#13.2) Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) + + - [13.2](#variables--one-const) Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl) > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once. @@ -1132,7 +1186,8 @@ Other Style Guides const dragonball = 'z'; ``` - - [13.3](#13.3) Group all your `const`s and then group all your `let`s. + + - [13.3](#variables--const-let-group) Group all your `const`s and then group all your `let`s. > Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables. @@ -1157,7 +1212,8 @@ Other Style Guides let length; ``` - - [13.4](#13.4) Assign variables where you need them, but place them in a reasonable place. + + - [13.4](#variables--define-where-used) Assign variables where you need them, but place them in a reasonable place. > Why? `let` and `const` are block scoped and not function scoped. @@ -1200,7 +1256,8 @@ Other Style Guides ## Hoisting - - [14.1](#14.1) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15). + + - [14.1](#hoisting--about) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15). ```javascript // we know this wouldn't work (assuming there @@ -1235,7 +1292,8 @@ Other Style Guides } ``` - - [14.2](#14.2) Anonymous function expressions hoist their variable name, but not the function assignment. + + - [14.2](#hoisting--anon-expressions) Anonymous function expressions hoist their variable name, but not the function assignment. ```javascript function example() { @@ -1249,7 +1307,8 @@ Other Style Guides } ``` - - [14.3](#14.3) Named function expressions hoist the variable name, not the function name or the function body. + + - [14.3](#hoisting--named-expresions) Named function expressions hoist the variable name, not the function name or the function body. ```javascript function example() { @@ -1277,7 +1336,8 @@ Other Style Guides } ``` - - [14.4](#14.4) Function declarations hoist their name and the function body. + + - [14.4](#hoisting--declarations) Function declarations hoist their name and the function body. ```javascript function example() { @@ -1296,9 +1356,11 @@ Other Style Guides ## Comparison Operators & Equality - - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. eslint: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html) + + - [15.1](#comparison--eqeqeq) Use `===` and `!==` over `==` and `!=`. eslint: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html) - - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: + + - [15.2](#comparison--if) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: + **Objects** evaluate to **true** + **Undefined** evaluates to **false** @@ -1314,7 +1376,8 @@ Other Style Guides } ``` - - [15.3](#15.3) Use shortcuts. + + - [15.3](#comparison--shortcuts) Use shortcuts. ```javascript // bad @@ -1338,9 +1401,11 @@ Other Style Guides } ``` - - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. + + - [15.4](#comparison--moreinfo) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. - - [15.5](#15.5) Use braces to create blocks in `case` and `default` clauses that contain lexical declarations (e.g. `let`, `const`, `function`, and `class`). + + - [15.5](#comparison--switch-blocks) Use braces to create blocks in `case` and `default` clauses that contain lexical declarations (e.g. `let`, `const`, `function`, and `class`). > Why? Lexical declarations are visible in the entire `switch` block but only get initialized when assigned, which only happens when its `case` is reached. This causes problems when multiple `case` clauses attempt to define the same thing. @@ -1385,7 +1450,8 @@ Other Style Guides } ``` - - [15.6](#15.6) Ternaries should not be nested and generally be single line expressions. + + - [15.6](#comparison--nested-ternaries) Ternaries should not be nested and generally be single line expressions. eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html). @@ -1408,7 +1474,8 @@ Other Style Guides const foo = maybe1 > maybe2 ? 'bar' : maybeNull; ``` - - [15.7](#15.7) Avoid unneeded ternary statements. + + - [15.7](#comparison--unneeded-ternary) Avoid unneeded ternary statements. eslint rules: [`no-unneeded-ternary`](http://eslint.org/docs/rules/no-unneeded-ternary.html). @@ -1429,7 +1496,8 @@ Other Style Guides ## Blocks - - [16.1](#16.1) Use braces with all multi-line blocks. + + - [16.1](#blocks--braces) Use braces with all multi-line blocks. ```javascript // bad @@ -1453,8 +1521,8 @@ Other Style Guides } ``` - - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your - `if` block's closing brace. eslint: [`brace-style`](http://eslint.org/docs/rules/brace-style.html) jscs: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements) + + - [16.2](#blocks--cuddled-elses) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your `if` block's closing brace. eslint: [`brace-style`](http://eslint.org/docs/rules/brace-style.html) jscs: [`disallowNewlineBeforeBlockStatements`](http://jscs.info/rule/disallowNewlineBeforeBlockStatements) ```javascript // bad @@ -1481,7 +1549,8 @@ Other Style Guides ## Comments - - [17.1](#17.1) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values. + + - [17.1](#comments--multiline) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values. ```javascript // bad @@ -1513,7 +1582,8 @@ Other Style Guides } ``` - - [17.2](#17.2) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block. + + - [17.2](#comments--singleline) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block. ```javascript // bad @@ -1551,9 +1621,11 @@ Other Style Guides } ``` - - [17.3](#17.3) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME: -- need to figure this out` or `TODO: -- need to implement`. + + - [17.3](#comments--actionitems) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME: -- need to figure this out` or `TODO: -- need to implement`. - - [17.4](#17.4) Use `// FIXME:` to annotate problems. + + - [17.4](#comments--fixme) Use `// FIXME:` to annotate problems. ```javascript class Calculator extends Abacus { @@ -1566,7 +1638,8 @@ Other Style Guides } ``` - - [17.5](#17.5) Use `// TODO:` to annotate solutions to problems. + + - [17.5](#comments--todo) Use `// TODO:` to annotate solutions to problems. ```javascript class Calculator extends Abacus { @@ -1584,7 +1657,8 @@ Other Style Guides ## Whitespace - - [18.1](#18.1) Use soft tabs set to 2 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) + + - [18.1](#whitespace--spaces) Use soft tabs set to 2 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) ```javascript // bad @@ -1603,7 +1677,8 @@ Other Style Guides } ``` - - [18.2](#18.2) Place 1 space before the leading brace. eslint: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html) jscs: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements) + + - [18.2](#whitespace--before-blocks) Place 1 space before the leading brace. eslint: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html) jscs: [`requireSpaceBeforeBlockStatements`](http://jscs.info/rule/requireSpaceBeforeBlockStatements) ```javascript // bad @@ -1629,7 +1704,8 @@ Other Style Guides }); ``` - - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) + + - [18.3](#whitespace--around-keywords) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords) ```javascript // bad @@ -1653,7 +1729,8 @@ Other Style Guides } ``` - - [18.4](#18.4) Set off operators with spaces. eslint: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html) jscs: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) + + - [18.4](#whitespace--infix-ops) Set off operators with spaces. eslint: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html) jscs: [`requireSpaceBeforeBinaryOperators`](http://jscs.info/rule/requireSpaceBeforeBinaryOperators), [`requireSpaceAfterBinaryOperators`](http://jscs.info/rule/requireSpaceAfterBinaryOperators) ```javascript // bad @@ -1663,7 +1740,8 @@ Other Style Guides const x = y + 5; ``` - - [18.5](#18.5) End files with a single newline character. + + - [18.5](#whitespace--newline-at-end) End files with a single newline character. ```javascript // bad @@ -1687,7 +1765,8 @@ Other Style Guides })(this);↵ ``` - - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which + + - [18.6](#whitespace--chains) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which emphasizes that the line is a method call, not a new statement. eslint: [`newline-per-chained-call`](http://eslint.org/docs/rules/newline-per-chained-call) [`no-whitespace-before-property`](http://eslint.org/docs/rules/no-whitespace-before-property) ```javascript @@ -1730,7 +1809,8 @@ Other Style Guides const leds = stage.selectAll('.led').data(data); ``` - - [18.7](#18.7) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) + + - [18.7](#whitespace--after-blocks) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) ```javascript // bad @@ -1787,7 +1867,8 @@ Other Style Guides return arr; ``` - - [18.8](#18.8) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html) jscs: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) + + - [18.8](#whitespace--padded-blocks) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html) jscs: [`disallowPaddingNewlinesInBlocks`](http://jscs.info/rule/disallowPaddingNewlinesInBlocks) ```javascript // bad @@ -1819,7 +1900,8 @@ Other Style Guides } ``` - - [18.9](#18.9) Do not add spaces inside parentheses. eslint: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html) jscs: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) + + - [18.9](#whitespace--in-parens) Do not add spaces inside parentheses. eslint: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html) jscs: [`disallowSpacesInsideParentheses`](http://jscs.info/rule/disallowSpacesInsideParentheses) ```javascript // bad @@ -1843,7 +1925,8 @@ Other Style Guides } ``` - - [18.10](#18.10) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html) jscs: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets) + + - [18.10](#whitespace--in-brackets) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html) jscs: [`disallowSpacesInsideArrayBrackets`](http://jscs.info/rule/disallowSpacesInsideArrayBrackets) ```javascript // bad @@ -1855,7 +1938,8 @@ Other Style Guides console.log(foo[0]); ``` - - [18.11](#18.11) Add spaces inside curly braces. eslint: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets) + + - [18.11](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets) ```javascript // bad @@ -1865,7 +1949,8 @@ Other Style Guides const foo = { clark: 'kent' }; ``` - - [18.12](#18.12) Avoid having lines of code that are longer than 100 characters (including whitespace). eslint: [`max-len`](http://eslint.org/docs/rules/max-len.html) jscs: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) + + - [18.12](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). eslint: [`max-len`](http://eslint.org/docs/rules/max-len.html) jscs: [`maximumLineLength`](http://jscs.info/rule/maximumLineLength) > Why? This ensures readability and maintainability. @@ -1894,7 +1979,8 @@ Other Style Guides ## Commas - - [19.1](#19.1) Leading commas: **Nope.** eslint: [`comma-style`](http://eslint.org/docs/rules/comma-style.html) jscs: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) + + - [19.1](#commas--leading-trailing) Leading commas: **Nope.** eslint: [`comma-style`](http://eslint.org/docs/rules/comma-style.html) jscs: [`requireCommaBeforeLineBreak`](http://jscs.info/rule/requireCommaBeforeLineBreak) ```javascript // bad @@ -1928,7 +2014,8 @@ Other Style Guides }; ``` - - [19.2](#19.2) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) + + - [19.2](#commas--dangling) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma) > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. @@ -1976,7 +2063,8 @@ Other Style Guides ## Semicolons - - [20.1](#20.1) **Yup.** eslint: [`semi`](http://eslint.org/docs/rules/semi.html) jscs: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) + + - [20.1](#20.1) **Yup.** eslint: [`semi`](http://eslint.org/docs/rules/semi.html) jscs: [`requireSemicolons`](http://jscs.info/rule/requireSemicolons) ```javascript // bad @@ -2005,8 +2093,11 @@ Other Style Guides ## Type Casting & Coercion - - [21.1](#21.1) Perform type coercion at the beginning of the statement. - - [21.2](#21.2) Strings: + + - [21.1](#coercion--explicit) Perform type coercion at the beginning of the statement. + + + - [21.2](#coercion--strings) Strings: ```javascript // => this.reviewScore = 9; @@ -2021,7 +2112,8 @@ Other Style Guides const totalScore = String(this.reviewScore); ``` - - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](http://eslint.org/docs/rules/radix) + + - [21.3](#coercion--numbers) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](http://eslint.org/docs/rules/radix) ```javascript const inputValue = '4'; @@ -2045,7 +2137,8 @@ Other Style Guides const val = parseInt(inputValue, 10); ``` - - [21.4](#21.4) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing. + + - [21.4](#coercion--comment-deviations) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing. ```javascript // good @@ -2057,7 +2150,8 @@ Other Style Guides const val = inputValue >> 0; ``` - - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: + + - [21.5](#coercion--bitwise) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: ```javascript 2147483647 >> 0 //=> 2147483647 @@ -2065,7 +2159,8 @@ Other Style Guides 2147483649 >> 0 //=> -2147483647 ``` - - [21.6](#21.6) Booleans: + + - [21.6](#coercion--booleans) Booleans: ```javascript const age = 0; @@ -2085,7 +2180,8 @@ Other Style Guides ## Naming Conventions - - [22.1](#22.1) Avoid single letter names. Be descriptive with your naming. + + - [22.1](#naming--descriptive) Avoid single letter names. Be descriptive with your naming. ```javascript // bad @@ -2099,7 +2195,8 @@ Other Style Guides } ``` - - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](http://eslint.org/docs/rules/camelcase.html) jscs: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) + + - [22.2](#naming--camelCase) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](http://eslint.org/docs/rules/camelcase.html) jscs: [`requireCamelCaseOrUpperCaseIdentifiers`](http://jscs.info/rule/requireCamelCaseOrUpperCaseIdentifiers) ```javascript // bad @@ -2112,7 +2209,8 @@ Other Style Guides function thisIsMyFunction() {} ``` - - [22.3](#22.3) Use PascalCase when naming constructors or classes. eslint: [`new-cap`](http://eslint.org/docs/rules/new-cap.html) jscs: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) + + - [22.3](#naming--PascalCase) Use PascalCase only when naming constructors or classes. eslint: [`new-cap`](http://eslint.org/docs/rules/new-cap.html) jscs: [`requireCapitalizedConstructors`](http://jscs.info/rule/requireCapitalizedConstructors) ```javascript // bad @@ -2136,7 +2234,8 @@ Other Style Guides }); ``` - - [22.4](#22.4) Use a leading underscore `_` when naming private properties. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) + + - [22.4](#naming--leading-underscore) Use a leading underscore `_` when naming private properties. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores) ```javascript // bad @@ -2147,7 +2246,8 @@ Other Style Guides this._firstName = 'Panda'; ``` - - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) + + - [22.5](#naming--self-this) Don't save references to `this`. Use arrow functions or Function#bind. jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes) ```javascript // bad @@ -2174,7 +2274,8 @@ Other Style Guides } ``` - - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class. + + - [22.6](#naming--filename-matches-export) If your file exports a single class, your filename should be exactly the name of the class. ```javascript // file contents @@ -2194,7 +2295,8 @@ Other Style Guides import CheckBox from './CheckBox'; ``` - - [22.7](#22.7) Use camelCase when you export-default a function. Your filename should be identical to your function's name. + + - [22.7](#naming--camelCase-default-export) Use camelCase when you export-default a function. Your filename should be identical to your function's name. ```javascript function makeStyleGuide() { @@ -2203,7 +2305,8 @@ Other Style Guides export default makeStyleGuide; ``` - - [22.8](#22.8) Use PascalCase when you export a singleton / function library / bare object. + + - [22.8](#naming--PascalCase-singleton) Use PascalCase when you export a singleton / function library / bare object. ```javascript const AirbnbStyleGuide = { @@ -2220,8 +2323,11 @@ Other Style Guides ## Accessors - - [23.1](#23.1) Accessor functions for properties are not required. - - [23.2](#23.2) Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello'). + + - [23.1](#accessors--not-required) Accessor functions for properties are not required. + + + - [23.2](#accessors--no-getters-setters) Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use getVal() and setVal('hello'). ```javascript // bad @@ -2237,7 +2343,8 @@ Other Style Guides dragon.setAge(25); ``` - - [23.3](#23.3) If the property is a `boolean`, use `isVal()` or `hasVal()`. + + - [23.3](#accessors--boolean-prefix) If the property/method is a `boolean`, use `isVal()` or `hasVal()`. ```javascript // bad @@ -2251,7 +2358,8 @@ Other Style Guides } ``` - - [23.4](#23.4) It's okay to create get() and set() functions, but be consistent. + + - [23.4](#accessors--consistent) It's okay to create get() and set() functions, but be consistent. ```javascript class Jedi { @@ -2275,7 +2383,8 @@ Other Style Guides ## Events - - [24.1](#24.1) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of: + + - [24.1](#events--hash) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of: ```javascript // bad @@ -2306,7 +2415,8 @@ Other Style Guides ## jQuery - - [25.1](#25.1) Prefix jQuery object variables with a `$`. jscs: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) + + - [25.1](#jquery--dollar-prefix) Prefix jQuery object variables with a `$`. jscs: [`requireDollarBeforejQueryAssignment`](http://jscs.info/rule/requireDollarBeforejQueryAssignment) ```javascript // bad @@ -2319,7 +2429,8 @@ Other Style Guides const $sidebarBtn = $('.sidebar-btn'); ``` - - [25.2](#25.2) Cache jQuery lookups. + + - [25.2](#jquery--cache) Cache jQuery lookups. ```javascript // bad @@ -2346,8 +2457,11 @@ Other Style Guides } ``` - - [25.3](#25.3) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16) - - [25.4](#25.4) Use `find` with scoped jQuery object queries. + + - [25.3](#jquery--queries) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16) + + + - [25.4](#jquery--find) Use `find` with scoped jQuery object queries. ```javascript // bad @@ -2371,13 +2485,15 @@ Other Style Guides ## ECMAScript 5 Compatibility - - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/). + + - [26.1](#es5-compat--kangax) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/). **[⬆ back to top](#table-of-contents)** ## ECMAScript 6 Styles - - [27.1](#27.1) This is a collection of links to the various ES6 features. + + - [27.1](#es6-styles) This is a collection of links to the various ES6 features. 1. [Arrow Functions](#arrow-functions) 1. [Classes](#constructors) @@ -2397,7 +2513,8 @@ Other Style Guides ## Testing - - [28.1](#28.1) **Yup.** + + - [28.1](#esting--yup) **Yup.** ```javascript function foo() { @@ -2405,7 +2522,8 @@ Other Style Guides } ``` - - [28.2](#28.2) **No, but seriously**: + + - [28.2](#testing--for-real) **No, but seriously**: - Whichever testing framework you use, you should be writing tests! - Strive to write many small pure functions, and minimize where mutations occur. - Be cautious about stubs and mocks - they can make your tests more brittle. From 2ff6c427b0e1bc8f60581be3481699628fdd8a0b Mon Sep 17 00:00:00 2001 From: Jason Bacchetta Date: Wed, 9 Mar 2016 19:14:00 -0600 Subject: [PATCH 0114/1167] Update README.md Add parentheses around argument, to be consistent with section 8.4 (include parentheses when using braces). --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5368efacf7..603f4f82e3 100644 --- a/README.md +++ b/README.md @@ -874,7 +874,7 @@ Other Style Guides const itemHeight = (item) => item.height > 256 ? item.largeSize : item.smallSize; // good - const itemHeight = item => { return item.height > 256 ? item.largeSize : item.smallSize; } + const itemHeight = (item) => { return item.height > 256 ? item.largeSize : item.smallSize; } ``` **[⬆ back to top](#table-of-contents)** From c38cdd20158ad76030d8a596b67bbc32d7b5494f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 11 Mar 2016 09:29:44 +0100 Subject: [PATCH 0115/1167] Add ascribe's styleguide to the list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 603f4f82e3..d4ed168963 100644 --- a/README.md +++ b/README.md @@ -2637,6 +2637,7 @@ Other Style Guides - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript) - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript) - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript) + - **Ascribe**: [ascribe/javascript](https://github.com/ascribe/javascript) - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript) - **Avant**: [avantcredit/javascript](https://github.com/avantcredit/javascript) - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) From 8fe2f9ed522107e5f22794402342006fa2139aff Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 11 Mar 2016 16:33:31 -0800 Subject: [PATCH 0116/1167] [eslint config] [dev deps] update `eslint`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 0721839841..c4ecc16d43 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,8 +43,8 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.3.0", - "eslint-plugin-react": "^4.2.0", + "eslint": "^2.4.0", + "eslint-plugin-react": "^4.2.1", "react": "^0.14.7", "tape": "^4.5.1", "parallelshell": "^2.0.0" From 6f125a5e85840c08594bfc2a3d1c181282634fc9 Mon Sep 17 00:00:00 2001 From: Tim Cheung Date: Tue, 15 Mar 2016 15:11:28 +0100 Subject: [PATCH 0117/1167] fix react/prefer-stateless-function link --- packages/eslint-config-airbnb/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index bb9374e170..774fad0795 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -174,4 +174,5 @@ [react/jsx-no-bind]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md [react/no-is-mounted]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md [react/prefer-es6-class]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md -[react/jsx-quotes]: https://github.com/yannickcr/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md \ No newline at end of file +[react/jsx-quotes]: https://github.com/yannickcr/eslint-plugin-react/blob/f817e37beddddc84b4788969f07c524fa7f0823b/docs/rules/jsx-quotes.md +[react/prefer-stateless-function]: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md From 9eb24d6b61515747f5a67f179ddb3d73ad385121 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 16 Mar 2016 14:47:35 -0700 Subject: [PATCH 0118/1167] [editorial] clean up some constructor examples Fixes #792 --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d4ed168963..09f6f28627 100644 --- a/README.md +++ b/README.md @@ -890,23 +890,23 @@ Other Style Guides ```javascript // bad function Queue(contents = []) { - this._queue = [...contents]; + this.queue = [...contents]; } Queue.prototype.pop = function () { - const value = this._queue[0]; - this._queue.splice(0, 1); + const value = this.queue[0]; + this.queue.splice(0, 1); return value; - } + }; // good class Queue { constructor(contents = []) { - this._queue = [...contents]; + this.queue = [...contents]; } pop() { - const value = this._queue[0]; - this._queue.splice(0, 1); + const value = this.queue[0]; + this.queue.splice(0, 1); return value; } } From 5ded256d3fab29b7b3fa42238093b9af632fb32b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 20 Mar 2016 17:23:49 -0700 Subject: [PATCH 0119/1167] [Fix] re-enable `no-confusing-arrow` rule, with `allowParens` option enabled. Per #752, fixes #791. --- packages/eslint-config-airbnb/rules/es6.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index d0b7bbde9f..a26e49d9df 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -30,7 +30,9 @@ module.exports = { 'no-class-assign': 0, // disallow arrow functions where they could be confused with comparisons // http://eslint.org/docs/rules/no-confusing-arrow - 'no-confusing-arrow': 0, + 'no-confusing-arrow': [2, { + 'allowParens': true, + }], // disallow modifying variables that are declared using const 'no-const-assign': 2, // disallow symbol constructor From f796cfc81f14d80b67f341a436c4c31f3500bcd1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 20 Mar 2016 17:26:15 -0700 Subject: [PATCH 0120/1167] [peer deps] update `eslint`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index c4ecc16d43..ff8adb78c8 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -50,7 +50,7 @@ "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": "^2.2.0", - "eslint-plugin-react": "^4.0.0" + "eslint": "^2.4.0", + "eslint-plugin-react": "^4.2.3" } } From 8db205c4d2309fcf31c2681366bdd35d68c77dff Mon Sep 17 00:00:00 2001 From: Arnav Singh Date: Sun, 20 Mar 2016 22:40:07 -0700 Subject: [PATCH 0121/1167] Fix "object destructuring for multiple return values" example ... to use the same destructured properties in the good and bad code. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09f6f28627..432ef98900 100644 --- a/README.md +++ b/README.md @@ -476,7 +476,7 @@ Other Style Guides } // the caller selects only the data they need - const { left, right } = processInput(input); + const { left, top } = processInput(input); ``` From 94ace27f465bbbdd814bafedbbd3708b8d21b06e Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Wed, 9 Mar 2016 08:59:48 -0800 Subject: [PATCH 0122/1167] Allow arrow functions in JSX props --- packages/eslint-config-airbnb/rules/react.js | 4 ++-- react/README.md | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index a5d0d17de2..470738b769 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -41,8 +41,8 @@ module.exports = { // Prevent usage of .bind() and arrow functions in JSX props // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md 'react/jsx-no-bind': [2, { - 'ignoreRefs': false, - 'allowArrowFunctions': false, + 'ignoreRefs': true, + 'allowArrowFunctions': true, 'allowBind': false, }], // Prevent duplicate props in JSX diff --git a/react/README.md b/react/README.md index 8bab601e12..6eddabcad2 100644 --- a/react/README.md +++ b/react/README.md @@ -274,6 +274,23 @@ ## Methods + - Use arrow functions to close over local variables. + + ```javascript + function ItemList(props) { + return ( +
    + {props.items.map((item, index) => ( + doSomethingWith(item.name, index)} + /> + ))} +
+ ); + } + ``` + - Bind event handlers for the render method in the constructor. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md) > Why? A bind call in the render path creates a brand new function on every single render. From ec898a67e09a5f47b7afdc24dbb5bb3ab0214268 Mon Sep 17 00:00:00 2001 From: Juan Scolari Date: Mon, 21 Mar 2016 20:54:59 -0300 Subject: [PATCH 0123/1167] Add SysGarage to list of organizations --- README.md | 1 + es5/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 432ef98900..6013998b27 100644 --- a/README.md +++ b/README.md @@ -2689,6 +2689,7 @@ Other Style Guides - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - **Springload**: [springload/javascript](https://github.com/springload/javascript) - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript) + - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide) - **Target**: [target/javascript](https://github.com/target/javascript) - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) diff --git a/es5/README.md b/es5/README.md index caaa17b503..b2fa49d9c1 100644 --- a/es5/README.md +++ b/es5/README.md @@ -1672,6 +1672,7 @@ - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/javascript) - **Super**: [SuperJobs/javascript](https://github.com/SuperJobs/javascript) + - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide) - **Target**: [target/javascript](https://github.com/target/javascript) - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) From ff6e1d0d08c129db5876a897ee146ae801178809 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 22 Mar 2016 23:34:59 -0700 Subject: [PATCH 0124/1167] [eslint config] v6.2.0 --- packages/eslint-config-airbnb/CHANGELOG.md | 7 +++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md index 774fad0795..3968eea84b 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,10 @@ +6.2.0 / 2016-03-22 +================== +- [new] Allow arrow functions in JSX props +- [fix] re-enable `no-confusing-arrow` rule, with `allowParens` option enabled ([#752](https://github.com/airbnb/javascript/issues/752), [#791](https://github.com/airbnb/javascript/issues/791)) +- [dev deps] update `tape`, `eslint`, `eslint-plugin-react` +- [peer deps] update `eslint`, `eslint-plugin-react` + 6.1.0 / 2016-02-22 ================== - [new] enable [`react/prefer-stateless-function`][react/prefer-stateless-function] diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index ff8adb78c8..da5bf3f2fc 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "6.1.0", + "version": "6.2.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 5ce6fb1eae2b0a948e526d127654b044f34d3b1b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 26 Mar 2016 22:39:17 -0700 Subject: [PATCH 0125/1167] [eslint config] [dev deps] update `eslint`, `eslint-plugin-react` --- packages/eslint-config-airbnb/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index da5bf3f2fc..0d059f0c8d 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,8 +43,8 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.4.0", - "eslint-plugin-react": "^4.2.1", + "eslint": "^2.5.3", + "eslint-plugin-react": "^4.2.3", "react": "^0.14.7", "tape": "^4.5.1", "parallelshell": "^2.0.0" From 24565121c1847fbf27d0854a1d2fc9accbbef4df Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 26 Mar 2016 22:42:29 -0700 Subject: [PATCH 0126/1167] [eslint config] [breaking] add `no-duplicate-imports` rule. --- README.md | 21 +++++++++++++++++++++ packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 6013998b27..8233e4916e 100644 --- a/README.md +++ b/README.md @@ -1075,6 +1075,27 @@ Other Style Guides export default es6; ``` + + - [10.4](#modules--no-duplicate-imports) Only import from a path in one place. + eslint: [`no-duplicate-imports`](http://eslint.org/docs/rules/no-duplicate-imports) + > Why? Having multiple lines that import from the same path can make code harder to maintain. + + ```javascript + // bad + import foo from 'foo'; + // … some other imports … // + import { named1, named2 } from 'foo'; + + // good + import foo, { named1, named2 } from 'foo'; + + // good + import foo, { + named1, + named2, + } from 'foo'; + ``` + **[⬆ back to top](#table-of-contents)** ## Iterators and Generators diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index a26e49d9df..78a43b94cd 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -35,6 +35,9 @@ module.exports = { }], // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow importing from the same path more than once + // http://eslint.org/docs/rules/no-duplicate-imports + 'no-duplicate-imports': 2, // disallow symbol constructor // http://eslint.org/docs/rules/no-new-symbol 'no-new-symbol': 2, From 81241b83cf3a95c1560d4080c39bf8b57381656f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 26 Mar 2016 23:11:23 -0700 Subject: [PATCH 0127/1167] [eslint config] [breaking] add `no-useless-escape` rule. --- README.md | 14 ++++++++++++++ .../eslint-config-airbnb/rules/best-practices.js | 3 +++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 8233e4916e..664b24921a 100644 --- a/README.md +++ b/README.md @@ -547,6 +547,20 @@ Other Style Guides - [6.5](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities. + + - [6.6](#strings--escaping) Do not unnecessarily escape characters in strings. eslint: [`no-useless-escape`](http://eslint.org/docs/rules/no-useless-escape) + + > Why? Backslashes harm readability, thus they should only be present when necessary. + + ```javascript + // bad + const foo = '\'this\' \i\s \"quoted\"'; + + // good + const foo = '\'this\' is "quoted"'; + const foo = `'this' is "quoted"`; + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index ff782a5b7a..e9a0026546 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -113,6 +113,9 @@ module.exports = { 'no-unused-labels': 2, // disallow unnecessary .call() and .apply() 'no-useless-call': 0, + // disallow unnecessary string escaping + // http://eslint.org/docs/rules/no-useless-escape + 'no-useless-escape': 2, // disallow use of void operator 'no-void': 0, // disallow usage of configurable warning terms in comments: e.g. todo From 9415b88afd0d21800e6b595828f0526689084f0a Mon Sep 17 00:00:00 2001 From: Saad Quadri Date: Wed, 30 Mar 2016 02:50:21 -0400 Subject: [PATCH 0128/1167] Add missing description for 7.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 664b24921a..064e9f6276 100644 --- a/README.md +++ b/README.md @@ -582,7 +582,7 @@ Other Style Guides ``` - - [7.2](#functions--iife) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) + - [7.2](#functions--iife) Wrap immediately invoked function expressions in parentheses. eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE) > Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE. From 5ec8765a28923671a59465901c03a7f997eb861a Mon Sep 17 00:00:00 2001 From: Yarun Luon Date: Thu, 31 Mar 2016 18:17:26 -0700 Subject: [PATCH 0129/1167] Add Chartboost to 'In the Wild' --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 064e9f6276..ff42af3d2c 100644 --- a/README.md +++ b/README.md @@ -2679,6 +2679,7 @@ Other Style Guides - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/) - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript) - **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript) + - **Chartboost**: [ChartBoost/javascript-style-guide](https://github.com/ChartBoost/javascript-style-guide) - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide) - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) From 062929ee5f5ca368b2b36390fc36aed34ed96797 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 1 Apr 2016 14:25:31 -0700 Subject: [PATCH 0130/1167] [eslint config] [breaking] error on debugger statements --- packages/eslint-config-airbnb/rules/errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/errors.js b/packages/eslint-config-airbnb/rules/errors.js index 1c1addf5fa..62594e0c3e 100644 --- a/packages/eslint-config-airbnb/rules/errors.js +++ b/packages/eslint-config-airbnb/rules/errors.js @@ -9,7 +9,7 @@ module.exports = { // disallow control characters in regular expressions 'no-control-regex': 2, // disallow use of debugger - 'no-debugger': 1, + 'no-debugger': 2, // disallow duplicate arguments in functions 'no-dupe-args': 2, // disallow duplicate keys when creating object literals From 5b9f081d1dac5240f60313784de316c9a63fde62 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 2 Apr 2016 17:46:24 -0700 Subject: [PATCH 0131/1167] [eslint config] [deps] update `eslint`, `react` --- packages/eslint-config-airbnb/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 0d059f0c8d..aefe9a76a6 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -43,14 +43,14 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "^1.3.1", - "eslint": "^2.5.3", + "eslint": "^2.6.0", "eslint-plugin-react": "^4.2.3", - "react": "^0.14.7", + "react": "^0.14.8", "tape": "^4.5.1", "parallelshell": "^2.0.0" }, "peerDependencies": { - "eslint": "^2.4.0", + "eslint": "^2.6.0", "eslint-plugin-react": "^4.2.3" } } From 76e1e4c1de263948f9c35bf43c4de526b17bebb9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 2 Apr 2016 18:08:27 -0700 Subject: [PATCH 0132/1167] [eslint config] [breaking] Add `no-dupe-class-members` rule + section. Closes #785. --- README.md | 30 +++++++++++++++++++--- packages/eslint-config-airbnb/rules/es6.js | 3 +++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ff42af3d2c..03c422d931 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Other Style Guides 1. [Strings](#strings) 1. [Functions](#functions) 1. [Arrow Functions](#arrow-functions) - 1. [Constructors](#constructors) + 1. [Classes & Constructors](#constructors) 1. [Modules](#modules) 1. [Iterators and Generators](#iterators-and-generators) 1. [Properties](#properties) @@ -894,7 +894,7 @@ Other Style Guides **[⬆ back to top](#table-of-contents)** -## Constructors +## Classes & Constructors - [9.1](#constructors--use-class) Always use `class`. Avoid manipulating `prototype` directly. @@ -1008,7 +1008,7 @@ Other Style Guides ``` - - [9.5](#constructors--no-useless) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) + - [9.5](#constructors--no-useless) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. eslint: [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor) ```javascript // bad @@ -1036,6 +1036,30 @@ Other Style Guides } ``` + + - [9.6](#classes--no-duplicate-members) Avoid duplicate class members. eslint: [`no-dupe-class-members`](http://eslint.org/docs/rules/no-dupe-class-members) + + > Why? Duplicate class member declarations will silently prefer the last one - having duplicates is almost certainly a bug. + + ```javascript + // bad + class Foo { + bar() { return 1; } + bar() { return 2; } + } + + // good + class Foo { + bar() { return 1; } + } + + // good + class Foo { + bar() { return 2; } + } + ``` + + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index 78a43b94cd..a826da8d0e 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -35,6 +35,9 @@ module.exports = { }], // disallow modifying variables that are declared using const 'no-const-assign': 2, + // disallow duplicate class members + // http://eslint.org/docs/rules/no-dupe-class-members + 'no-dupe-class-members': 2, // disallow importing from the same path more than once // http://eslint.org/docs/rules/no-duplicate-imports 'no-duplicate-imports': 2, From 6671a55556e09b9f70924e9fd63e76c9e079fa5e Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 3 Apr 2016 09:59:12 -0400 Subject: [PATCH 0133/1167] CHORE - Remove Trailing Spaces --- linters/SublimeLinter/SublimeLinter.sublime-settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index 12360f3f1c..259dbaff6a 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -63,7 +63,7 @@ // Warn when variables are defined but never used. "unused": true, - + // Enforce line length to 80 characters "maxlen": 80, From f21412cba916e4af18cd1594a6b6d18ef4ebc341 Mon Sep 17 00:00:00 2001 From: Amin Date: Mon, 4 Apr 2016 11:39:47 +0400 Subject: [PATCH 0134/1167] Broken link to Classes and constructors --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03c422d931..3034aa4c24 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Other Style Guides 1. [Strings](#strings) 1. [Functions](#functions) 1. [Arrow Functions](#arrow-functions) - 1. [Classes & Constructors](#constructors) + 1. [Classes & Constructors](#classes--constructors) 1. [Modules](#modules) 1. [Iterators and Generators](#iterators-and-generators) 1. [Properties](#properties) From a2bdbb83d15e8d35fa40a14b888ad1eee029c7df Mon Sep 17 00:00:00 2001 From: Peter Kuiper Date: Mon, 4 Apr 2016 14:20:17 +0200 Subject: [PATCH 0135/1167] Add KickorStick to 'In the Wild' --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3034aa4c24..5384d7dc9f 100644 --- a/README.md +++ b/README.md @@ -2727,6 +2727,7 @@ Other Style Guides - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions) - **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md) - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript) + - **KickorStick**: [kickorstick/javascript](https://github.com/kickorstick/javascript) - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide) - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript) - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript) From 6e770062bb84aa054ff939c1b805cbb12e9195a1 Mon Sep 17 00:00:00 2001 From: Kevin Moot Date: Mon, 4 Apr 2016 19:07:35 -0500 Subject: [PATCH 0136/1167] Adding The Nerdery to the "In the Wild" section --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5384d7dc9f..ec1dca2cc5 100644 --- a/README.md +++ b/README.md @@ -2753,6 +2753,7 @@ Other Style Guides - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide) - **Target**: [target/javascript](https://github.com/target/javascript) - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript) + - **The Nerdery**: [thenerdery/javascript-standards](https://github.com/thenerdery/javascript-standards) - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript) - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide) - **WeBox Studio**: [weboxstudio/javascript](https://github.com/weboxstudio/javascript) From acbddc1083d5ea7608fba212bb6898ca6e224afc Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:14:03 -0700 Subject: [PATCH 0137/1167] Add note and rule about image alt text We want our React apps to be accessible. One thing that developers can do is properly use alt text on images. Thankfully, there is an ESLint rule that will enforce these things for us. --- packages/eslint-config-airbnb/package.json | 2 ++ packages/eslint-config-airbnb/rules/react.js | 5 +++++ .../test/test-react-order.js | 4 ++-- react/README.md | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index aefe9a76a6..769c8950a3 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -44,6 +44,7 @@ "devDependencies": { "babel-tape-runner": "^1.3.1", "eslint": "^2.6.0", + "eslint-plugin-jsx-a11y": "^0.6.0", "eslint-plugin-react": "^4.2.3", "react": "^0.14.8", "tape": "^4.5.1", @@ -51,6 +52,7 @@ }, "peerDependencies": { "eslint": "^2.6.0", + "eslint-plugin-jsx-a11y": "^0.6.0", "eslint-plugin-react": "^4.2.3" } } diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 470738b769..0b128aef63 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -1,5 +1,6 @@ module.exports = { 'plugins': [ + 'jsx-a11y', 'react' ], 'ecmaFeatures': { @@ -8,6 +9,10 @@ module.exports = { // View link below for react rules documentation // https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules 'rules': { + // Require to have a non-empty `alt` prop, or role="presentation" + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md + 'jsx-a11y/img-uses-alt': 2, + // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 'react/display-name': [0, { 'ignoreTranspilerName': false }], diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index f5b2d452fe..81d8235fce 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -28,9 +28,9 @@ ${body} } test('validate react prop order', t => { - t.test('make sure our eslintrc has React linting dependencies', t => { + t.test('make sure our eslintrc has React and JSX linting dependencies', t => { t.plan(1); - t.equal(reactRules.plugins[0], 'react', 'uses eslint-plugin-react'); + t.deepEqual(reactRules.plugins, ['jsx-a11y', 'react']); }); t.test('passes a good component', t => { diff --git a/react/README.md b/react/README.md index 6eddabcad2..29af5cf806 100644 --- a/react/README.md +++ b/react/README.md @@ -217,6 +217,22 @@ /> ``` + - Always include a non-empty `alt` prop on `` tags. If `alt` is an empty string, the `` must have `role="presentation"`. eslint: [`jsx-a11y/img-uses-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md) + + ```javascript + // bad + + + // bad + + + // good + Me waving hello + + // good + + ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From f2aca29ed95dbec65590660e5e0032a00808cf4a Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:21:48 -0700 Subject: [PATCH 0138/1167] Add note and rule about redundant alt text Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text. This will give people using assistive technologies a smoother experience. --- packages/eslint-config-airbnb/rules/react.js | 4 ++++ react/README.md | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 0b128aef63..f505c75ba1 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -13,6 +13,10 @@ module.exports = { // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md 'jsx-a11y/img-uses-alt': 2, + // Prevent img alt text from containing redundant words like "image", "picture", or "photo" + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/redundant-alt.md + 'jsx-a11y/redundant-alt': 2, + // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 'react/display-name': [0, { 'ignoreTranspilerName': false }], diff --git a/react/README.md b/react/README.md index 29af5cf806..bc149b0908 100644 --- a/react/README.md +++ b/react/README.md @@ -233,6 +233,18 @@ ``` + - Do not use words like "image", "photo", or "picture" in `` `alt` props. eslint: [`jsx-a11y/redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md) + + > Why? Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text. + + ```javascript + // bad + Picture of me waving hello + + // good + Me waving hello + ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From 0c3b13fe93e880450305e6c87a1a59f14e042bc5 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:27:21 -0700 Subject: [PATCH 0139/1167] Add note and rule about valid, non-abstract ARIA roles This rule will help people use only valid roles, which might save people from simple, accessibility-busting mistakes. --- packages/eslint-config-airbnb/rules/react.js | 4 ++++ react/README.md | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index f505c75ba1..02794495b1 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -17,6 +17,10 @@ module.exports = { // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/redundant-alt.md 'jsx-a11y/redundant-alt': 2, + // Require ARIA roles to be valid and non-abstract + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/valid-aria-role.md + 'jsx-a11y/valid-aria-role': 2, + // Prevent missing displayName in a React component definition // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md 'react/display-name': [0, { 'ignoreTranspilerName': false }], diff --git a/react/README.md b/react/README.md index bc149b0908..0ac01a5b6f 100644 --- a/react/README.md +++ b/react/README.md @@ -245,6 +245,19 @@ Me waving hello ``` + - Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/roles#role_definitions). eslint: [`jsx-a11y/valid-aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/valid-aria-role.md) + + ```javascript + // bad - not an ARIA role +
+ + // bad - abstract ARIA role +
+ + // good +
+ ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From f697a15e5036932805cb7a5160b6c0ceb2401afe Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:32:55 -0700 Subject: [PATCH 0140/1167] Add note and rule about not using accessKey Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility. --- packages/eslint-config-airbnb/rules/react.js | 4 ++++ react/README.md | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 02794495b1..3c05265b06 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -9,6 +9,10 @@ module.exports = { // View link below for react rules documentation // https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules 'rules': { + // Prevent use of `accessKey` + // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md + 'jsx-a11y/no-access-key': 2, + // Require to have a non-empty `alt` prop, or role="presentation" // https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md 'jsx-a11y/img-uses-alt': 2, diff --git a/react/README.md b/react/README.md index 0ac01a5b6f..4fc7c7c783 100644 --- a/react/README.md +++ b/react/README.md @@ -249,15 +249,27 @@ ```javascript // bad - not an ARIA role -
+
// bad - abstract ARIA role -
+
// good -
+
``` + - Do not use `accessKey` on elements. eslint: [`jsx-a11y/no-access-key`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md) + + > Why? Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility. + + ```javascript + // bad +
+ + // good +
+ ``` + ## Parentheses - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md) From 3f73e35b1874128161a97acbc6a299a801ec077b Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 6 Apr 2016 14:34:21 -0700 Subject: [PATCH 0141/1167] Use jsx fenced codeblocks for JSX code GitHub knows how to do JSX syntax highlighting. Since we are using JSX in this document, I figured we might as well tell GitHub to highlight the syntax as JSX here. This will lead to a better reading experience. --- react/README.md | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/react/README.md b/react/README.md index 4fc7c7c783..6db60dd18a 100644 --- a/react/README.md +++ b/react/README.md @@ -29,7 +29,7 @@ - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) - ```javascript + ```jsx // bad const Listing = React.createClass({ // ... @@ -49,8 +49,7 @@ And if you don't have state or refs, prefer normal functions (not arrow functions) over classes: - ```javascript - + ```jsx // bad class Listing extends React.Component { render() { @@ -75,7 +74,7 @@ - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`. - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) - ```javascript + ```jsx // bad import reservationCard from './ReservationCard'; @@ -91,7 +90,7 @@ - **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name: - ```javascript + ```jsx // bad import Footer from './Footer/Footer'; @@ -106,7 +105,7 @@ - Do not use `displayName` for naming components. Instead, name the component by reference. - ```javascript + ```jsx // bad export default React.createClass({ displayName: 'ReservationCard', @@ -122,7 +121,7 @@ - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) - ```javascript + ```jsx // bad @@ -152,7 +151,7 @@ > Why? JSX attributes [can't contain escaped quotes](http://eslint.org/docs/rules/jsx-quotes), so double quotes make conjunctions like `"don't"` easier to type. > Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention. - ```javascript + ```jsx // bad @@ -170,7 +169,7 @@ - Always include a single space in your self-closing tag. - ```javascript + ```jsx // bad @@ -189,7 +188,7 @@ - Always use camelCase for prop names. - ```javascript + ```jsx // bad