From 5fd7c6f08c0650ed67297fc83c8a0590c9a92cc8 Mon Sep 17 00:00:00 2001 From: Estelle Date: Mon, 23 Mar 2015 18:48:19 -0700 Subject: [PATCH 0001/1318] 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 d2db3b6290da2c3d5f035a7245607c75aa7cc0c2 Mon Sep 17 00:00:00 2001 From: Evan Tschuy Date: Thu, 30 Jul 2015 10:02:18 -0700 Subject: [PATCH 0002/1318] change duplicate 18.5 to 18.6 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab521d38a7..bcec5e6d54 100644 --- a/README.md +++ b/README.md @@ -1355,7 +1355,7 @@ })(this);↵ ``` - - [18.5](#18.5) Use indentation when making long method chains. Use a leading dot, which + - [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. ```javascript @@ -1395,7 +1395,7 @@ .call(tron.led); ``` - - [18.6](#18.6) Leave a blank line after blocks and before the next statement. + - [18.7](#18.7) Leave a blank line after blocks and before the next statement. ```javascript // bad From 20b6913202bdc9e394b6f9a4475dd9a46b1dc704 Mon Sep 17 00:00:00 2001 From: Nikita Gusakov Date: Sat, 8 Aug 2015 17:46:56 +0300 Subject: [PATCH 0003/1318] Simplify ESLint config package. This patch moves `.eslintrc` contents into `index.js` directly. This allows us to drop external dependencies and using javascript comments instead of not valid JSON. --- packages/eslint-config-airbnb/.eslintrc | 220 -------------------- packages/eslint-config-airbnb/index.js | 227 ++++++++++++++++++++- packages/eslint-config-airbnb/package.json | 5 +- 3 files changed, 219 insertions(+), 233 deletions(-) delete mode 100644 packages/eslint-config-airbnb/.eslintrc diff --git a/packages/eslint-config-airbnb/.eslintrc b/packages/eslint-config-airbnb/.eslintrc deleted file mode 100644 index 638bbacf4d..0000000000 --- a/packages/eslint-config-airbnb/.eslintrc +++ /dev/null @@ -1,220 +0,0 @@ -{ - "parser": "babel-eslint", // https://github.com/babel/babel-eslint - "plugins": [ - "react" // https://github.com/yannickcr/eslint-plugin-react - ], - "env": { // http://eslint.org/docs/user-guide/configuring.html#specifying-environments - "browser": true, // browser global variables - "node": true // Node.js global variables and Node.js-specific rules - }, - "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, - "spread": true, - "superInFunctions": true, - "templateStrings": true, - "jsx": true - }, - "rules": { -/** - * Strict mode - */ - // babel inserts "use strict"; for us - "strict": [2, "never"], // http://eslint.org/docs/rules/strict - -/** - * ES6 - */ - "no-var": 2, // http://eslint.org/docs/rules/no-var - "prefer-const": 2, // http://eslint.org/docs/rules/prefer-const - -/** - * Variables - */ - "no-shadow": 2, // http://eslint.org/docs/rules/no-shadow - "no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names - "no-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars - "vars": "local", - "args": "after-used" - }], - "no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define - -/** - * Possible errors - */ - "comma-dangle": [2, "always-multiline"], // http://eslint.org/docs/rules/comma-dangle - "no-cond-assign": [2, "always"], // http://eslint.org/docs/rules/no-cond-assign - "no-console": 1, // http://eslint.org/docs/rules/no-console - "no-debugger": 1, // http://eslint.org/docs/rules/no-debugger - "no-alert": 1, // http://eslint.org/docs/rules/no-alert - "no-constant-condition": 1, // http://eslint.org/docs/rules/no-constant-condition - "no-dupe-keys": 2, // http://eslint.org/docs/rules/no-dupe-keys - "no-duplicate-case": 2, // http://eslint.org/docs/rules/no-duplicate-case - "no-empty": 2, // http://eslint.org/docs/rules/no-empty - "no-ex-assign": 2, // http://eslint.org/docs/rules/no-ex-assign - "no-extra-boolean-cast": 0, // http://eslint.org/docs/rules/no-extra-boolean-cast - "no-extra-semi": 2, // http://eslint.org/docs/rules/no-extra-semi - "no-func-assign": 2, // http://eslint.org/docs/rules/no-func-assign - "no-inner-declarations": 2, // http://eslint.org/docs/rules/no-inner-declarations - "no-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp - "no-irregular-whitespace": 2, // http://eslint.org/docs/rules/no-irregular-whitespace - "no-obj-calls": 2, // http://eslint.org/docs/rules/no-obj-calls - "no-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays - "no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable - "use-isnan": 2, // http://eslint.org/docs/rules/use-isnan - "block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var - -/** - * Best practices - */ - "consistent-return": 2, // http://eslint.org/docs/rules/consistent-return - "curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly - "default-case": 2, // http://eslint.org/docs/rules/default-case - "dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation - "allowKeywords": true - }], - "eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq - "guard-for-in": 2, // http://eslint.org/docs/rules/guard-for-in - "no-caller": 2, // http://eslint.org/docs/rules/no-caller - "no-else-return": 2, // http://eslint.org/docs/rules/no-else-return - "no-eq-null": 2, // http://eslint.org/docs/rules/no-eq-null - "no-eval": 2, // http://eslint.org/docs/rules/no-eval - "no-extend-native": 2, // http://eslint.org/docs/rules/no-extend-native - "no-extra-bind": 2, // http://eslint.org/docs/rules/no-extra-bind - "no-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough - "no-floating-decimal": 2, // http://eslint.org/docs/rules/no-floating-decimal - "no-implied-eval": 2, // http://eslint.org/docs/rules/no-implied-eval - "no-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks - "no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func - "no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str - "no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign - "no-new": 2, // http://eslint.org/docs/rules/no-new - "no-new-func": 2, // http://eslint.org/docs/rules/no-new-func - "no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers - "no-octal": 2, // http://eslint.org/docs/rules/no-octal - "no-octal-escape": 2, // http://eslint.org/docs/rules/no-octal-escape - "no-param-reassign": 2, // http://eslint.org/docs/rules/no-param-reassign - "no-proto": 2, // http://eslint.org/docs/rules/no-proto - "no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare - "no-return-assign": 2, // http://eslint.org/docs/rules/no-return-assign - "no-script-url": 2, // http://eslint.org/docs/rules/no-script-url - "no-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare - "no-sequences": 2, // http://eslint.org/docs/rules/no-sequences - "no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal - "no-with": 2, // http://eslint.org/docs/rules/no-with - "radix": 2, // http://eslint.org/docs/rules/radix - "vars-on-top": 2, // http://eslint.org/docs/rules/vars-on-top - "wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife - "yoda": 2, // http://eslint.org/docs/rules/yoda - -/** - * Style - */ - "indent": [2, 2], // http://eslint.org/docs/rules/indent - "brace-style": [2, // http://eslint.org/docs/rules/brace-style - "1tbs", { - "allowSingleLine": true - }], - "quotes": [ - 2, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes - ], - "camelcase": [2, { // http://eslint.org/docs/rules/camelcase - "properties": "never" - }], - "comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing - "before": false, - "after": true - }], - "comma-style": [2, "last"], // http://eslint.org/docs/rules/comma-style - "eol-last": 2, // http://eslint.org/docs/rules/eol-last - "func-names": 1, // http://eslint.org/docs/rules/func-names - "key-spacing": [2, { // http://eslint.org/docs/rules/key-spacing - "beforeColon": false, - "afterColon": true - }], - "new-cap": [2, { // http://eslint.org/docs/rules/new-cap - "newIsCap": true - }], - "no-multiple-empty-lines": [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines - "max": 2 - }], - "no-nested-ternary": 2, // http://eslint.org/docs/rules/no-nested-ternary - "no-new-object": 2, // http://eslint.org/docs/rules/no-new-object - "no-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func - "no-trailing-spaces": 2, // http://eslint.org/docs/rules/no-trailing-spaces - "no-extra-parens": [2, "functions"], // http://eslint.org/docs/rules/no-extra-parens - "no-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle - "one-var": [2, "never"], // http://eslint.org/docs/rules/one-var - "padded-blocks": [2, "never"], // http://eslint.org/docs/rules/padded-blocks - "semi": [2, "always"], // http://eslint.org/docs/rules/semi - "semi-spacing": [2, { // http://eslint.org/docs/rules/semi-spacing - "before": false, - "after": true - }], - "space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords - "space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks - "space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren - "space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops - "space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case - "spaced-comment": [2, "always", {// http://eslint.org/docs/rules/spaced-comment - "exceptions": ["-", "+"], - "markers": ["=", "!"] // space here to support sprockets directives - }], - -/** - * JSX style - */ - "react/display-name": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - "react/jsx-boolean-value": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md - "react/jsx-quotes": [2, "double"], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md - "react/jsx-no-undef": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md - "react/jsx-sort-props": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md - "react/jsx-sort-prop-types": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md - "react/jsx-uses-react": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md - "react/jsx-uses-vars": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md - "react/no-did-mount-set-state": [2, "allow-in-func"], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md - "react/no-did-update-set-state": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md - "react/no-multi-comp": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md - "react/no-unknown-property": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md - "react/prop-types": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md - "react/react-in-jsx-scope": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md - "react/self-closing-comp": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md - "react/wrap-multilines": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md - "react/sort-comp": [2, { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md - "order": [ - "displayName", - "propTypes", - "contextTypes", - "childContextTypes", - "mixins", - "statics", - "defaultProps", - "constructor", - "getDefaultProps", - "getInitialState", - "getChildContext", - "componentWillMount", - "componentDidMount", - "componentWillReceiveProps", - "shouldComponentUpdate", - "componentWillUpdate", - "componentDidUpdate", - "componentWillUnmount", - "/^on.+$/", - "/^get.+$/", - "/^render.+$/", - "render" - ] - }] - } -} diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index e69410e3c7..35bc6b07d2 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -1,11 +1,220 @@ -var path = require('path'); -var stripComments = require('strip-json-comments'); -var fs = require('fs'); +module.exports = { + 'parser': 'babel-eslint', // https://github.com/babel/babel-eslint + 'plugins': [ + 'react' // https://github.com/yannickcr/eslint-plugin-react + ], + 'env': { // http://eslint.org/docs/user-guide/configuring.html#specifying-environments + 'browser': true, // browser global variables + 'node': true // Node.js global variables and Node.js-specific rules + }, + '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, + 'spread': true, + 'superInFunctions': true, + 'templateStrings': true, + 'jsx': true + }, + 'rules': { +/** + * Strict mode + */ + // babel inserts 'use strict'; for us + 'strict': [2, 'never'], // http://eslint.org/docs/rules/strict -// you could do this all at once if you wanted to look cool -var filename = path.join(__dirname, '.eslintrc'); -var data = fs.readFileSync(filename, {encoding: 'utf-8'}); -var dataWithoutComments = stripComments(data); -var parsed = JSON.parse(dataWithoutComments); +/** + * ES6 + */ + 'no-var': 2, // http://eslint.org/docs/rules/no-var + 'prefer-const': 2, // http://eslint.org/docs/rules/prefer-const -module.exports = parsed; +/** + * Variables + */ + 'no-shadow': 2, // http://eslint.org/docs/rules/no-shadow + 'no-shadow-restricted-names': 2, // http://eslint.org/docs/rules/no-shadow-restricted-names + 'no-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars + 'vars': 'local', + 'args': 'after-used' + }], + 'no-use-before-define': 2, // http://eslint.org/docs/rules/no-use-before-define + +/** + * Possible errors + */ + 'comma-dangle': [2, 'always-multiline'], // http://eslint.org/docs/rules/comma-dangle + 'no-cond-assign': [2, 'always'], // http://eslint.org/docs/rules/no-cond-assign + 'no-console': 1, // http://eslint.org/docs/rules/no-console + 'no-debugger': 1, // http://eslint.org/docs/rules/no-debugger + 'no-alert': 1, // http://eslint.org/docs/rules/no-alert + 'no-constant-condition': 1, // http://eslint.org/docs/rules/no-constant-condition + 'no-dupe-keys': 2, // http://eslint.org/docs/rules/no-dupe-keys + 'no-duplicate-case': 2, // http://eslint.org/docs/rules/no-duplicate-case + 'no-empty': 2, // http://eslint.org/docs/rules/no-empty + 'no-ex-assign': 2, // http://eslint.org/docs/rules/no-ex-assign + 'no-extra-boolean-cast': 0, // http://eslint.org/docs/rules/no-extra-boolean-cast + 'no-extra-semi': 2, // http://eslint.org/docs/rules/no-extra-semi + 'no-func-assign': 2, // http://eslint.org/docs/rules/no-func-assign + 'no-inner-declarations': 2, // http://eslint.org/docs/rules/no-inner-declarations + 'no-invalid-regexp': 2, // http://eslint.org/docs/rules/no-invalid-regexp + 'no-irregular-whitespace': 2, // http://eslint.org/docs/rules/no-irregular-whitespace + 'no-obj-calls': 2, // http://eslint.org/docs/rules/no-obj-calls + 'no-sparse-arrays': 2, // http://eslint.org/docs/rules/no-sparse-arrays + 'no-unreachable': 2, // http://eslint.org/docs/rules/no-unreachable + 'use-isnan': 2, // http://eslint.org/docs/rules/use-isnan + 'block-scoped-var': 2, // http://eslint.org/docs/rules/block-scoped-var + +/** + * Best practices + */ + 'consistent-return': 2, // http://eslint.org/docs/rules/consistent-return + 'curly': [2, 'multi-line'], // http://eslint.org/docs/rules/curly + 'default-case': 2, // http://eslint.org/docs/rules/default-case + 'dot-notation': [2, { // http://eslint.org/docs/rules/dot-notation + 'allowKeywords': true + }], + 'eqeqeq': 2, // http://eslint.org/docs/rules/eqeqeq + 'guard-for-in': 2, // http://eslint.org/docs/rules/guard-for-in + 'no-caller': 2, // http://eslint.org/docs/rules/no-caller + 'no-else-return': 2, // http://eslint.org/docs/rules/no-else-return + 'no-eq-null': 2, // http://eslint.org/docs/rules/no-eq-null + 'no-eval': 2, // http://eslint.org/docs/rules/no-eval + 'no-extend-native': 2, // http://eslint.org/docs/rules/no-extend-native + 'no-extra-bind': 2, // http://eslint.org/docs/rules/no-extra-bind + 'no-fallthrough': 2, // http://eslint.org/docs/rules/no-fallthrough + 'no-floating-decimal': 2, // http://eslint.org/docs/rules/no-floating-decimal + 'no-implied-eval': 2, // http://eslint.org/docs/rules/no-implied-eval + 'no-lone-blocks': 2, // http://eslint.org/docs/rules/no-lone-blocks + 'no-loop-func': 2, // http://eslint.org/docs/rules/no-loop-func + 'no-multi-str': 2, // http://eslint.org/docs/rules/no-multi-str + 'no-native-reassign': 2, // http://eslint.org/docs/rules/no-native-reassign + 'no-new': 2, // http://eslint.org/docs/rules/no-new + 'no-new-func': 2, // http://eslint.org/docs/rules/no-new-func + 'no-new-wrappers': 2, // http://eslint.org/docs/rules/no-new-wrappers + 'no-octal': 2, // http://eslint.org/docs/rules/no-octal + 'no-octal-escape': 2, // http://eslint.org/docs/rules/no-octal-escape + 'no-param-reassign': 2, // http://eslint.org/docs/rules/no-param-reassign + 'no-proto': 2, // http://eslint.org/docs/rules/no-proto + 'no-redeclare': 2, // http://eslint.org/docs/rules/no-redeclare + 'no-return-assign': 2, // http://eslint.org/docs/rules/no-return-assign + 'no-script-url': 2, // http://eslint.org/docs/rules/no-script-url + 'no-self-compare': 2, // http://eslint.org/docs/rules/no-self-compare + 'no-sequences': 2, // http://eslint.org/docs/rules/no-sequences + 'no-throw-literal': 2, // http://eslint.org/docs/rules/no-throw-literal + 'no-with': 2, // http://eslint.org/docs/rules/no-with + 'radix': 2, // http://eslint.org/docs/rules/radix + 'vars-on-top': 2, // http://eslint.org/docs/rules/vars-on-top + 'wrap-iife': [2, 'any'], // http://eslint.org/docs/rules/wrap-iife + 'yoda': 2, // http://eslint.org/docs/rules/yoda + +/** + * Style + */ + 'indent': [2, 2], // http://eslint.org/docs/rules/indent + 'brace-style': [2, // http://eslint.org/docs/rules/brace-style + '1tbs', { + 'allowSingleLine': true + }], + 'quotes': [ + 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes + ], + 'camelcase': [2, { // http://eslint.org/docs/rules/camelcase + 'properties': 'never' + }], + 'comma-spacing': [2, { // http://eslint.org/docs/rules/comma-spacing + 'before': false, + 'after': true + }], + 'comma-style': [2, 'last'], // http://eslint.org/docs/rules/comma-style + 'eol-last': 2, // http://eslint.org/docs/rules/eol-last + 'func-names': 1, // http://eslint.org/docs/rules/func-names + 'key-spacing': [2, { // http://eslint.org/docs/rules/key-spacing + 'beforeColon': false, + 'afterColon': true + }], + 'new-cap': [2, { // http://eslint.org/docs/rules/new-cap + 'newIsCap': true + }], + 'no-multiple-empty-lines': [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines + 'max': 2 + }], + 'no-nested-ternary': 2, // http://eslint.org/docs/rules/no-nested-ternary + 'no-new-object': 2, // http://eslint.org/docs/rules/no-new-object + 'no-spaced-func': 2, // http://eslint.org/docs/rules/no-spaced-func + 'no-trailing-spaces': 2, // http://eslint.org/docs/rules/no-trailing-spaces + 'no-extra-parens': [2, 'functions'], // http://eslint.org/docs/rules/no-extra-parens + 'no-underscore-dangle': 0, // http://eslint.org/docs/rules/no-underscore-dangle + 'one-var': [2, 'never'], // http://eslint.org/docs/rules/one-var + 'padded-blocks': [2, 'never'], // http://eslint.org/docs/rules/padded-blocks + 'semi': [2, 'always'], // http://eslint.org/docs/rules/semi + 'semi-spacing': [2, { // http://eslint.org/docs/rules/semi-spacing + 'before': false, + 'after': true + }], + 'space-after-keywords': 2, // http://eslint.org/docs/rules/space-after-keywords + 'space-before-blocks': 2, // http://eslint.org/docs/rules/space-before-blocks + 'space-before-function-paren': [2, 'never'], // http://eslint.org/docs/rules/space-before-function-paren + 'space-infix-ops': 2, // http://eslint.org/docs/rules/space-infix-ops + 'space-return-throw-case': 2, // http://eslint.org/docs/rules/space-return-throw-case + 'spaced-comment': [2, 'always', {// http://eslint.org/docs/rules/spaced-comment + 'exceptions': ['-', '+'], + 'markers': ['=', '!'] // space here to support sprockets directives + }], + +/** + * JSX style + */ + 'react/display-name': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md + 'react/jsx-boolean-value': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md + 'react/jsx-quotes': [2, 'double'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md + 'react/jsx-no-undef': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md + 'react/jsx-sort-props': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md + 'react/jsx-sort-prop-types': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md + 'react/jsx-uses-react': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md + 'react/jsx-uses-vars': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md + 'react/no-did-mount-set-state': [2, 'allow-in-func'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md + 'react/no-did-update-set-state': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md + 'react/no-multi-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md + 'react/no-unknown-property': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md + 'react/prop-types': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md + 'react/react-in-jsx-scope': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md + 'react/self-closing-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md + 'react/wrap-multilines': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md + 'react/sort-comp': [2, { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md + 'order': [ + 'displayName', + 'propTypes', + 'contextTypes', + 'childContextTypes', + 'mixins', + 'statics', + 'defaultProps', + 'constructor', + 'getDefaultProps', + 'getInitialState', + 'getChildContext', + 'componentWillMount', + 'componentDidMount', + 'componentWillReceiveProps', + 'shouldComponentUpdate', + 'componentWillUpdate', + 'componentDidUpdate', + 'componentWillUnmount', + '/^on.+$/', + '/^get.+$/', + '/^render.+$/', + 'render' + ] + }] + } +}; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index bc9071dcc5..a082518584 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -23,8 +23,5 @@ "bugs": { "url": "https://github.com/airbnb/javascript/issues" }, - "homepage": "https://github.com/airbnb/javascript", - "dependencies": { - "strip-json-comments": "1.0.2" - } + "homepage": "https://github.com/airbnb/javascript" } From e8b87a5e2164b77ca12d5a534e45d15551fbef25 Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Sun, 9 Aug 2015 19:49:34 -0700 Subject: [PATCH 0004/1318] Updated 25.1 to include a case with a hyphen in the classname --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0e909159da..6c43b2d12c 100644 --- a/README.md +++ b/README.md @@ -1874,6 +1874,9 @@ // good const $sidebar = $('.sidebar'); + + // good + const $sidebarBtn = $('.sidebar-btn'); ``` - [25.2](#25.2) Cache jQuery lookups. From 1e2ed0b0699e1cbe1a203b7cd955795ce0992ebe Mon Sep 17 00:00:00 2001 From: allx Date: Mon, 10 Aug 2015 14:26:43 +0300 Subject: [PATCH 0005/1318] Update README.md deleted unnecessary whitespace after property key --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e909159da..268e78701e 100644 --- a/README.md +++ b/README.md @@ -1852,7 +1852,7 @@ ```javascript // good - $(this).trigger('listingUpdated', { listingId : listing.id }); + $(this).trigger('listingUpdated', { listingId: listing.id }); ... From 52a334404390f8648e21015e409aefe1f983e5db Mon Sep 17 00:00:00 2001 From: Choon-ho Yoon Date: Tue, 11 Aug 2015 17:27:02 -0300 Subject: [PATCH 0006/1318] Add ComparaOnline to 'In The Wild' List --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 461abe1857..5c8e653f36 100644 --- a/README.md +++ b/README.md @@ -2071,6 +2071,7 @@ - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript) - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript) + - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript) - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) From 4957071107a26a4f950c6d180188e5d000d67836 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 12 Aug 2015 11:04:27 +0200 Subject: [PATCH 0007/1318] Allow implicit return + one multiline expression --- README.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0ec7fec17e..48bb3b2fcd 100644 --- a/README.md +++ b/README.md @@ -602,7 +602,9 @@ }); ``` - - [8.2](#8.2) If the function body fits on one line and there is only a single argument, feel free to omit the braces and parentheses, and use the implicit return. Otherwise, add the parentheses, braces, and use a `return` statement. + - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement. + + In case the expression spans over multiple lines, wrap it in parentheses for better readability. > Why? Syntactic sugar. It reads well when multiple functions are chained together. @@ -610,12 +612,25 @@ ```javascript // good - [1, 2, 3].map(x => x * x); + [1, 2, 3].map(number => `A string containing the ${number}.`); // good - [1, 2, 3].reduce((total, n) => { - return total + n; - }, 0); + [1, 2, 3].map(number => ( + `As time went by, the string containing the ${number} became much ` + + 'longer. So we needed to break it over multiple lines.' + )); + + // bad + [1, 2, 3].map(number => { + let nextNumber = number + 1; + `A string containing the ${nextNumber}.`; + }); + + // good + [1, 2, 3].map(number => { + let nextNumber = number + 1; + return `A string containing the ${nextNumber}.`; + }); ``` **[⬆ back to top](#table-of-contents)** From 5634c4c88e5293e83cccf5dd9055666e9400c1de Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 12 Aug 2015 11:04:50 +0200 Subject: [PATCH 0008/1318] Update existing example --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 48bb3b2fcd..9b362d9737 100644 --- a/README.md +++ b/README.md @@ -597,9 +597,7 @@ }); // good - [1, 2, 3].map((x) => { - return x * x; - }); + [1, 2, 3].map(x => x * x); ``` - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement. From 5b8b56ece733543787c07d60c5f93efc5bbb2b6f Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Wed, 12 Aug 2015 11:09:14 +0200 Subject: [PATCH 0009/1318] Upgrade a note about parens to another rule --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 9b362d9737..fb9020ca72 100644 --- a/README.md +++ b/README.md @@ -631,6 +631,18 @@ }); ``` + - [8.3](#8.3) If your function only takes a single argument, feel free to omit the parentheses. + + > Why? Less visual clutter. + + ```js + // good + [1, 2, 3].map(x => x * x); + + // good + [1, 2, 3].reduce((y, x) => x + y); + ``` + **[⬆ back to top](#table-of-contents)** From 3aabe2c6934a2fef474cde5f0e48172b45979fc5 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Thu, 13 Aug 2015 08:43:33 +0200 Subject: [PATCH 0010/1318] Upgrade half of 8.2 to another rule --- README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fb9020ca72..8e0863ca51 100644 --- a/README.md +++ b/README.md @@ -602,8 +602,6 @@ - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement. - In case the expression spans over multiple lines, wrap it in parentheses for better readability. - > Why? Syntactic sugar. It reads well when multiple functions are chained together. > Why not? If you plan on returning an object. @@ -612,12 +610,6 @@ // good [1, 2, 3].map(number => `A string containing the ${number}.`); - // good - [1, 2, 3].map(number => ( - `As time went by, the string containing the ${number} became much ` + - 'longer. So we needed to break it over multiple lines.' - )); - // bad [1, 2, 3].map(number => { let nextNumber = number + 1; @@ -631,7 +623,26 @@ }); ``` - - [8.3](#8.3) If your function only takes a single argument, feel free to omit the parentheses. + - [8.3](#8.3) 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. + + ```js + // bad + [1, 2, 3].map(number => 'As time went by, the string containing the ' + + `${number} became much longer. So we needed to break it over multiple ` + + 'lines.' + ); + + // good + [1, 2, 3].map(number => ( + `As time went by, the string containing the ${number} became much ` + + 'longer. So we needed to break it over multiple lines.' + )); + ``` + + + - [8.4](#8.4) If your function only takes a single argument, feel free to omit the parentheses. > Why? Less visual clutter. From 60360bdedd1c282502af0264130cfde9d5666c17 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Thu, 13 Aug 2015 08:43:59 +0200 Subject: [PATCH 0011/1318] Match 8.4 indentation to other rules --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e0863ca51..3b1bba8503 100644 --- a/README.md +++ b/README.md @@ -644,7 +644,7 @@ - [8.4](#8.4) If your function only takes a single argument, feel free to omit the parentheses. - > Why? Less visual clutter. + > Why? Less visual clutter. ```js // good From 417f9896d0ae1088aafbc5c223ca3596cb9f4811 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Thu, 13 Aug 2015 08:47:48 +0200 Subject: [PATCH 0012/1318] Bring back explicit return in 8.1 example --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b1bba8503..724a4deab9 100644 --- a/README.md +++ b/README.md @@ -593,11 +593,15 @@ ```javascript // bad [1, 2, 3].map(function (x) { - return x * x; + const y = x + 1; + return x * y; }); // good - [1, 2, 3].map(x => x * x); + [1, 2, 3].map((x) => { + const y = x + 1; + return x * y; + }); ``` - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement. From bfbb074ac95e3b277cda3b6a168d6f2c73d845b5 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Thu, 13 Aug 2015 08:51:04 +0200 Subject: [PATCH 0013/1318] Oops, keep to 13.1! --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 724a4deab9..75aff34270 100644 --- a/README.md +++ b/README.md @@ -616,13 +616,13 @@ // bad [1, 2, 3].map(number => { - let nextNumber = number + 1; + const nextNumber = number + 1; `A string containing the ${nextNumber}.`; }); // good [1, 2, 3].map(number => { - let nextNumber = number + 1; + const nextNumber = number + 1; return `A string containing the ${nextNumber}.`; }); ``` From c4fdbc2742367ac33d4297de525f8fa246f5dae6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 17 Aug 2015 20:42:58 -0700 Subject: [PATCH 0014/1318] Recommend exporting `propTypes` as a named export By exporting `propTypes` as a named export *as well* as attaching them to the "class", they can be explicitly imported by tests and other components in a way that aligns with the future ES6 module dependency graph, rather than as an arbitrary property that isn't statically verifiable. Doing both is great imo. Thoughts? --- react/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index 3c01981f8c..8d02bcca7a 100644 --- a/react/README.md +++ b/react/README.md @@ -262,7 +262,7 @@ ```javascript import React, { Component, PropTypes } from 'react'; - const propTypes = { + export const propTypes = { id: PropTypes.number.isRequired, url: PropTypes.string.isRequired, text: PropTypes.string, From 0068cc1d6ef086e605e0421de09d9af7540a0b17 Mon Sep 17 00:00:00 2001 From: Slava Shklyaev Date: Tue, 18 Aug 2015 20:14:24 +0300 Subject: [PATCH 0015/1318] Put custom component methods before render methods --- packages/eslint-config-airbnb/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index 35bc6b07d2..0d87e4ad25 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -211,6 +211,7 @@ module.exports = { 'componentDidUpdate', 'componentWillUnmount', '/^on.+$/', + 'everything-else', '/^get.+$/', '/^render.+$/', 'render' From 6175c67a79af6fab46898b0cef16e474ec40aa1d Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 18 Aug 2015 14:54:29 -0400 Subject: [PATCH 0016/1318] s/Javascript/JavaScript --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b0ffdda6c..b5ff9eb737 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ 1. [In the Wild](#in-the-wild) 1. [Translation](#translation) 1. [The JavaScript Style Guide Guide](#the-javascript-style-guide-guide) - 1. [Chat With Us About Javascript](#chat-with-us-about-javascript) + 1. [Chat With Us About JavaScript](#chat-with-us-about-javascript) 1. [Contributors](#contributors) 1. [License](#license) From 048e22ea989120dc9b6afe715dc24e7762504aa8 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Tue, 18 Aug 2015 18:02:31 -0700 Subject: [PATCH 0017/1318] somewhat modularize eslint-config-airbnb; add some tests --- packages/eslint-config-airbnb/base/index.js | 171 +++++++++++++ packages/eslint-config-airbnb/index.js | 228 +----------------- packages/eslint-config-airbnb/package.json | 12 +- packages/eslint-config-airbnb/react.js | 36 +++ .../eslint-config-airbnb/test/test-base.js | 13 + .../test/test-react-order.js | 83 +++++++ 6 files changed, 323 insertions(+), 220 deletions(-) create mode 100644 packages/eslint-config-airbnb/base/index.js create mode 100644 packages/eslint-config-airbnb/react.js create mode 100644 packages/eslint-config-airbnb/test/test-base.js create mode 100644 packages/eslint-config-airbnb/test/test-react-order.js diff --git a/packages/eslint-config-airbnb/base/index.js b/packages/eslint-config-airbnb/base/index.js new file mode 100644 index 0000000000..c47c2c45dd --- /dev/null +++ b/packages/eslint-config-airbnb/base/index.js @@ -0,0 +1,171 @@ +module.exports = { + 'parser': 'babel-eslint', // https://github.com/babel/babel-eslint + 'env': { // http://eslint.org/docs/user-guide/configuring.html#specifying-environments + 'browser': true, // browser global variables + 'node': true // Node.js global variables and Node.js-specific rules + }, + '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, + 'spread': true, + 'superInFunctions': true, + 'templateStrings': true, + 'jsx': true + }, + 'rules': { +/** + * Strict mode + */ + // babel inserts 'use strict'; for us + 'strict': [2, 'never'], // http://eslint.org/docs/rules/strict + +/** + * ES6 + */ + 'no-var': 2, // http://eslint.org/docs/rules/no-var + 'prefer-const': 2, // http://eslint.org/docs/rules/prefer-const + +/** + * Variables + */ + 'no-shadow': 2, // http://eslint.org/docs/rules/no-shadow + 'no-shadow-restricted-names': 2, // http://eslint.org/docs/rules/no-shadow-restricted-names + 'no-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars + 'vars': 'local', + 'args': 'after-used' + }], + 'no-use-before-define': 2, // http://eslint.org/docs/rules/no-use-before-define + +/** + * Possible errors + */ + 'comma-dangle': [2, 'always-multiline'], // http://eslint.org/docs/rules/comma-dangle + 'no-cond-assign': [2, 'always'], // http://eslint.org/docs/rules/no-cond-assign + 'no-console': 1, // http://eslint.org/docs/rules/no-console + 'no-debugger': 1, // http://eslint.org/docs/rules/no-debugger + 'no-alert': 1, // http://eslint.org/docs/rules/no-alert + 'no-constant-condition': 1, // http://eslint.org/docs/rules/no-constant-condition + 'no-dupe-keys': 2, // http://eslint.org/docs/rules/no-dupe-keys + 'no-duplicate-case': 2, // http://eslint.org/docs/rules/no-duplicate-case + 'no-empty': 2, // http://eslint.org/docs/rules/no-empty + 'no-ex-assign': 2, // http://eslint.org/docs/rules/no-ex-assign + 'no-extra-boolean-cast': 0, // http://eslint.org/docs/rules/no-extra-boolean-cast + 'no-extra-semi': 2, // http://eslint.org/docs/rules/no-extra-semi + 'no-func-assign': 2, // http://eslint.org/docs/rules/no-func-assign + 'no-inner-declarations': 2, // http://eslint.org/docs/rules/no-inner-declarations + 'no-invalid-regexp': 2, // http://eslint.org/docs/rules/no-invalid-regexp + 'no-irregular-whitespace': 2, // http://eslint.org/docs/rules/no-irregular-whitespace + 'no-obj-calls': 2, // http://eslint.org/docs/rules/no-obj-calls + 'no-sparse-arrays': 2, // http://eslint.org/docs/rules/no-sparse-arrays + 'no-unreachable': 2, // http://eslint.org/docs/rules/no-unreachable + 'use-isnan': 2, // http://eslint.org/docs/rules/use-isnan + 'block-scoped-var': 2, // http://eslint.org/docs/rules/block-scoped-var + +/** + * Best practices + */ + 'consistent-return': 2, // http://eslint.org/docs/rules/consistent-return + 'curly': [2, 'multi-line'], // http://eslint.org/docs/rules/curly + 'default-case': 2, // http://eslint.org/docs/rules/default-case + 'dot-notation': [2, { // http://eslint.org/docs/rules/dot-notation + 'allowKeywords': true + }], + 'eqeqeq': 2, // http://eslint.org/docs/rules/eqeqeq + 'guard-for-in': 2, // http://eslint.org/docs/rules/guard-for-in + 'no-caller': 2, // http://eslint.org/docs/rules/no-caller + 'no-else-return': 2, // http://eslint.org/docs/rules/no-else-return + 'no-eq-null': 2, // http://eslint.org/docs/rules/no-eq-null + 'no-eval': 2, // http://eslint.org/docs/rules/no-eval + 'no-extend-native': 2, // http://eslint.org/docs/rules/no-extend-native + 'no-extra-bind': 2, // http://eslint.org/docs/rules/no-extra-bind + 'no-fallthrough': 2, // http://eslint.org/docs/rules/no-fallthrough + 'no-floating-decimal': 2, // http://eslint.org/docs/rules/no-floating-decimal + 'no-implied-eval': 2, // http://eslint.org/docs/rules/no-implied-eval + 'no-lone-blocks': 2, // http://eslint.org/docs/rules/no-lone-blocks + 'no-loop-func': 2, // http://eslint.org/docs/rules/no-loop-func + 'no-multi-str': 2, // http://eslint.org/docs/rules/no-multi-str + 'no-native-reassign': 2, // http://eslint.org/docs/rules/no-native-reassign + 'no-new': 2, // http://eslint.org/docs/rules/no-new + 'no-new-func': 2, // http://eslint.org/docs/rules/no-new-func + 'no-new-wrappers': 2, // http://eslint.org/docs/rules/no-new-wrappers + 'no-octal': 2, // http://eslint.org/docs/rules/no-octal + 'no-octal-escape': 2, // http://eslint.org/docs/rules/no-octal-escape + 'no-param-reassign': 2, // http://eslint.org/docs/rules/no-param-reassign + 'no-proto': 2, // http://eslint.org/docs/rules/no-proto + 'no-redeclare': 2, // http://eslint.org/docs/rules/no-redeclare + 'no-return-assign': 2, // http://eslint.org/docs/rules/no-return-assign + 'no-script-url': 2, // http://eslint.org/docs/rules/no-script-url + 'no-self-compare': 2, // http://eslint.org/docs/rules/no-self-compare + 'no-sequences': 2, // http://eslint.org/docs/rules/no-sequences + 'no-throw-literal': 2, // http://eslint.org/docs/rules/no-throw-literal + 'no-with': 2, // http://eslint.org/docs/rules/no-with + 'radix': 2, // http://eslint.org/docs/rules/radix + 'vars-on-top': 2, // http://eslint.org/docs/rules/vars-on-top + 'wrap-iife': [2, 'any'], // http://eslint.org/docs/rules/wrap-iife + 'yoda': 2, // http://eslint.org/docs/rules/yoda + +/** + * Style + */ + 'indent': [2, 2], // http://eslint.org/docs/rules/indent + 'brace-style': [2, // http://eslint.org/docs/rules/brace-style + '1tbs', { + 'allowSingleLine': true + }], + 'quotes': [ + 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes + ], + 'camelcase': [2, { // http://eslint.org/docs/rules/camelcase + 'properties': 'never' + }], + 'comma-spacing': [2, { // http://eslint.org/docs/rules/comma-spacing + 'before': false, + 'after': true + }], + 'comma-style': [2, 'last'], // http://eslint.org/docs/rules/comma-style + 'eol-last': 2, // http://eslint.org/docs/rules/eol-last + 'func-names': 1, // http://eslint.org/docs/rules/func-names + 'key-spacing': [2, { // http://eslint.org/docs/rules/key-spacing + 'beforeColon': false, + 'afterColon': true + }], + 'new-cap': [2, { // http://eslint.org/docs/rules/new-cap + 'newIsCap': true + }], + 'no-multiple-empty-lines': [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines + 'max': 2 + }], + 'no-nested-ternary': 2, // http://eslint.org/docs/rules/no-nested-ternary + 'no-new-object': 2, // http://eslint.org/docs/rules/no-new-object + 'no-spaced-func': 2, // http://eslint.org/docs/rules/no-spaced-func + 'no-trailing-spaces': 2, // http://eslint.org/docs/rules/no-trailing-spaces + 'no-extra-parens': [2, 'functions'], // http://eslint.org/docs/rules/no-extra-parens + 'no-underscore-dangle': 0, // http://eslint.org/docs/rules/no-underscore-dangle + 'one-var': [2, 'never'], // http://eslint.org/docs/rules/one-var + 'padded-blocks': [2, 'never'], // http://eslint.org/docs/rules/padded-blocks + 'semi': [2, 'always'], // http://eslint.org/docs/rules/semi + 'semi-spacing': [2, { // http://eslint.org/docs/rules/semi-spacing + 'before': false, + 'after': true + }], + 'space-after-keywords': 2, // http://eslint.org/docs/rules/space-after-keywords + 'space-before-blocks': 2, // http://eslint.org/docs/rules/space-before-blocks + 'space-before-function-paren': [2, 'never'], // http://eslint.org/docs/rules/space-before-function-paren + 'space-infix-ops': 2, // http://eslint.org/docs/rules/space-infix-ops + 'space-return-throw-case': 2, // http://eslint.org/docs/rules/space-return-throw-case + 'spaced-comment': [2, 'always', {// http://eslint.org/docs/rules/spaced-comment + 'exceptions': ['-', '+'], + 'markers': ['=', '!'] // space here to support sprockets directives + }], + } +}; diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index 0d87e4ad25..e74501fcd0 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -1,221 +1,13 @@ -module.exports = { - 'parser': 'babel-eslint', // https://github.com/babel/babel-eslint - 'plugins': [ - 'react' // https://github.com/yannickcr/eslint-plugin-react - ], - 'env': { // http://eslint.org/docs/user-guide/configuring.html#specifying-environments - 'browser': true, // browser global variables - 'node': true // Node.js global variables and Node.js-specific rules - }, - '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, - 'spread': true, - 'superInFunctions': true, - 'templateStrings': true, - 'jsx': true - }, - 'rules': { -/** - * Strict mode - */ - // babel inserts 'use strict'; for us - 'strict': [2, 'never'], // http://eslint.org/docs/rules/strict +var reactRules = require('./react'); +var base = require('./base'); -/** - * ES6 - */ - 'no-var': 2, // http://eslint.org/docs/rules/no-var - 'prefer-const': 2, // http://eslint.org/docs/rules/prefer-const +// clone this so we aren't mutating a module +var eslintrc = JSON.parse(JSON.stringify(base)); -/** - * Variables - */ - 'no-shadow': 2, // http://eslint.org/docs/rules/no-shadow - 'no-shadow-restricted-names': 2, // http://eslint.org/docs/rules/no-shadow-restricted-names - 'no-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars - 'vars': 'local', - 'args': 'after-used' - }], - 'no-use-before-define': 2, // http://eslint.org/docs/rules/no-use-before-define +// manually merge in React rules +eslintrc.plugins = reactRules.plugins; +Object.keys(reactRules.rules).forEach(function(ruleId) { + eslintrc.rules[ruleId] = reactRules.rules[ruleId]; +}); -/** - * Possible errors - */ - 'comma-dangle': [2, 'always-multiline'], // http://eslint.org/docs/rules/comma-dangle - 'no-cond-assign': [2, 'always'], // http://eslint.org/docs/rules/no-cond-assign - 'no-console': 1, // http://eslint.org/docs/rules/no-console - 'no-debugger': 1, // http://eslint.org/docs/rules/no-debugger - 'no-alert': 1, // http://eslint.org/docs/rules/no-alert - 'no-constant-condition': 1, // http://eslint.org/docs/rules/no-constant-condition - 'no-dupe-keys': 2, // http://eslint.org/docs/rules/no-dupe-keys - 'no-duplicate-case': 2, // http://eslint.org/docs/rules/no-duplicate-case - 'no-empty': 2, // http://eslint.org/docs/rules/no-empty - 'no-ex-assign': 2, // http://eslint.org/docs/rules/no-ex-assign - 'no-extra-boolean-cast': 0, // http://eslint.org/docs/rules/no-extra-boolean-cast - 'no-extra-semi': 2, // http://eslint.org/docs/rules/no-extra-semi - 'no-func-assign': 2, // http://eslint.org/docs/rules/no-func-assign - 'no-inner-declarations': 2, // http://eslint.org/docs/rules/no-inner-declarations - 'no-invalid-regexp': 2, // http://eslint.org/docs/rules/no-invalid-regexp - 'no-irregular-whitespace': 2, // http://eslint.org/docs/rules/no-irregular-whitespace - 'no-obj-calls': 2, // http://eslint.org/docs/rules/no-obj-calls - 'no-sparse-arrays': 2, // http://eslint.org/docs/rules/no-sparse-arrays - 'no-unreachable': 2, // http://eslint.org/docs/rules/no-unreachable - 'use-isnan': 2, // http://eslint.org/docs/rules/use-isnan - 'block-scoped-var': 2, // http://eslint.org/docs/rules/block-scoped-var - -/** - * Best practices - */ - 'consistent-return': 2, // http://eslint.org/docs/rules/consistent-return - 'curly': [2, 'multi-line'], // http://eslint.org/docs/rules/curly - 'default-case': 2, // http://eslint.org/docs/rules/default-case - 'dot-notation': [2, { // http://eslint.org/docs/rules/dot-notation - 'allowKeywords': true - }], - 'eqeqeq': 2, // http://eslint.org/docs/rules/eqeqeq - 'guard-for-in': 2, // http://eslint.org/docs/rules/guard-for-in - 'no-caller': 2, // http://eslint.org/docs/rules/no-caller - 'no-else-return': 2, // http://eslint.org/docs/rules/no-else-return - 'no-eq-null': 2, // http://eslint.org/docs/rules/no-eq-null - 'no-eval': 2, // http://eslint.org/docs/rules/no-eval - 'no-extend-native': 2, // http://eslint.org/docs/rules/no-extend-native - 'no-extra-bind': 2, // http://eslint.org/docs/rules/no-extra-bind - 'no-fallthrough': 2, // http://eslint.org/docs/rules/no-fallthrough - 'no-floating-decimal': 2, // http://eslint.org/docs/rules/no-floating-decimal - 'no-implied-eval': 2, // http://eslint.org/docs/rules/no-implied-eval - 'no-lone-blocks': 2, // http://eslint.org/docs/rules/no-lone-blocks - 'no-loop-func': 2, // http://eslint.org/docs/rules/no-loop-func - 'no-multi-str': 2, // http://eslint.org/docs/rules/no-multi-str - 'no-native-reassign': 2, // http://eslint.org/docs/rules/no-native-reassign - 'no-new': 2, // http://eslint.org/docs/rules/no-new - 'no-new-func': 2, // http://eslint.org/docs/rules/no-new-func - 'no-new-wrappers': 2, // http://eslint.org/docs/rules/no-new-wrappers - 'no-octal': 2, // http://eslint.org/docs/rules/no-octal - 'no-octal-escape': 2, // http://eslint.org/docs/rules/no-octal-escape - 'no-param-reassign': 2, // http://eslint.org/docs/rules/no-param-reassign - 'no-proto': 2, // http://eslint.org/docs/rules/no-proto - 'no-redeclare': 2, // http://eslint.org/docs/rules/no-redeclare - 'no-return-assign': 2, // http://eslint.org/docs/rules/no-return-assign - 'no-script-url': 2, // http://eslint.org/docs/rules/no-script-url - 'no-self-compare': 2, // http://eslint.org/docs/rules/no-self-compare - 'no-sequences': 2, // http://eslint.org/docs/rules/no-sequences - 'no-throw-literal': 2, // http://eslint.org/docs/rules/no-throw-literal - 'no-with': 2, // http://eslint.org/docs/rules/no-with - 'radix': 2, // http://eslint.org/docs/rules/radix - 'vars-on-top': 2, // http://eslint.org/docs/rules/vars-on-top - 'wrap-iife': [2, 'any'], // http://eslint.org/docs/rules/wrap-iife - 'yoda': 2, // http://eslint.org/docs/rules/yoda - -/** - * Style - */ - 'indent': [2, 2], // http://eslint.org/docs/rules/indent - 'brace-style': [2, // http://eslint.org/docs/rules/brace-style - '1tbs', { - 'allowSingleLine': true - }], - 'quotes': [ - 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes - ], - 'camelcase': [2, { // http://eslint.org/docs/rules/camelcase - 'properties': 'never' - }], - 'comma-spacing': [2, { // http://eslint.org/docs/rules/comma-spacing - 'before': false, - 'after': true - }], - 'comma-style': [2, 'last'], // http://eslint.org/docs/rules/comma-style - 'eol-last': 2, // http://eslint.org/docs/rules/eol-last - 'func-names': 1, // http://eslint.org/docs/rules/func-names - 'key-spacing': [2, { // http://eslint.org/docs/rules/key-spacing - 'beforeColon': false, - 'afterColon': true - }], - 'new-cap': [2, { // http://eslint.org/docs/rules/new-cap - 'newIsCap': true - }], - 'no-multiple-empty-lines': [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines - 'max': 2 - }], - 'no-nested-ternary': 2, // http://eslint.org/docs/rules/no-nested-ternary - 'no-new-object': 2, // http://eslint.org/docs/rules/no-new-object - 'no-spaced-func': 2, // http://eslint.org/docs/rules/no-spaced-func - 'no-trailing-spaces': 2, // http://eslint.org/docs/rules/no-trailing-spaces - 'no-extra-parens': [2, 'functions'], // http://eslint.org/docs/rules/no-extra-parens - 'no-underscore-dangle': 0, // http://eslint.org/docs/rules/no-underscore-dangle - 'one-var': [2, 'never'], // http://eslint.org/docs/rules/one-var - 'padded-blocks': [2, 'never'], // http://eslint.org/docs/rules/padded-blocks - 'semi': [2, 'always'], // http://eslint.org/docs/rules/semi - 'semi-spacing': [2, { // http://eslint.org/docs/rules/semi-spacing - 'before': false, - 'after': true - }], - 'space-after-keywords': 2, // http://eslint.org/docs/rules/space-after-keywords - 'space-before-blocks': 2, // http://eslint.org/docs/rules/space-before-blocks - 'space-before-function-paren': [2, 'never'], // http://eslint.org/docs/rules/space-before-function-paren - 'space-infix-ops': 2, // http://eslint.org/docs/rules/space-infix-ops - 'space-return-throw-case': 2, // http://eslint.org/docs/rules/space-return-throw-case - 'spaced-comment': [2, 'always', {// http://eslint.org/docs/rules/spaced-comment - 'exceptions': ['-', '+'], - 'markers': ['=', '!'] // space here to support sprockets directives - }], - -/** - * JSX style - */ - 'react/display-name': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - 'react/jsx-boolean-value': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md - 'react/jsx-quotes': [2, 'double'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md - 'react/jsx-no-undef': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md - 'react/jsx-sort-props': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md - 'react/jsx-sort-prop-types': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md - 'react/jsx-uses-react': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md - 'react/jsx-uses-vars': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md - 'react/no-did-mount-set-state': [2, 'allow-in-func'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md - 'react/no-did-update-set-state': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md - 'react/no-multi-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md - 'react/no-unknown-property': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md - 'react/prop-types': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md - 'react/react-in-jsx-scope': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md - 'react/self-closing-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md - 'react/wrap-multilines': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md - 'react/sort-comp': [2, { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md - 'order': [ - 'displayName', - 'propTypes', - 'contextTypes', - 'childContextTypes', - 'mixins', - 'statics', - 'defaultProps', - 'constructor', - 'getDefaultProps', - 'getInitialState', - 'getChildContext', - 'componentWillMount', - 'componentDidMount', - 'componentWillReceiveProps', - 'shouldComponentUpdate', - 'componentWillUpdate', - 'componentDidUpdate', - 'componentWillUnmount', - '/^on.+$/', - 'everything-else', - '/^get.+$/', - '/^render.+$/', - 'render' - ] - }] - } -}; +module.exports = eslintrc; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index a082518584..3af4564f9b 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -4,7 +4,7 @@ "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "./node_modules/.bin/babel-tape-runner ./test/test-*.js" }, "repository": { "type": "git", @@ -23,5 +23,13 @@ "bugs": { "url": "https://github.com/airbnb/javascript/issues" }, - "homepage": "https://github.com/airbnb/javascript" + "homepage": "https://github.com/airbnb/javascript", + "devDependencies": { + "babel-eslint": "4.0.10", + "babel-tape-runner": "1.2.0", + "eslint": "1.1.0", + "eslint-plugin-react": "3.2.3", + "react": "0.13.3", + "tape": "4.2.0" + } } diff --git a/packages/eslint-config-airbnb/react.js b/packages/eslint-config-airbnb/react.js new file mode 100644 index 0000000000..a0ab17f396 --- /dev/null +++ b/packages/eslint-config-airbnb/react.js @@ -0,0 +1,36 @@ +module.exports = { + 'plugins': [ + 'react' // https://github.com/yannickcr/eslint-plugin-react + ], + rules: { + /** + * JSX style + */ + 'react/display-name': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md + 'react/jsx-boolean-value': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md + 'react/jsx-quotes': [2, 'double'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md + 'react/jsx-no-undef': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md + 'react/jsx-sort-props': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md + 'react/jsx-sort-prop-types': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md + 'react/jsx-uses-react': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md + 'react/jsx-uses-vars': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md + 'react/no-did-mount-set-state': [2, 'allow-in-func'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md + 'react/no-did-update-set-state': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md + 'react/no-multi-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md + 'react/no-unknown-property': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md + 'react/prop-types': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md + 'react/react-in-jsx-scope': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md + 'react/self-closing-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md + 'react/wrap-multilines': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md + 'react/sort-comp': [2, { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md + 'order': [ + 'lifecycle', + '/^on.+$/', + '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', + 'everything-else', + '/^render.+$/', + 'render' + ] + }] + } +}; diff --git a/packages/eslint-config-airbnb/test/test-base.js b/packages/eslint-config-airbnb/test/test-base.js new file mode 100644 index 0000000000..ecf06cdf58 --- /dev/null +++ b/packages/eslint-config-airbnb/test/test-base.js @@ -0,0 +1,13 @@ +import test from 'tape'; +import base from '../base'; + +test('base: does not reference react', t => { + t.plan(2); + + t.notOk(base.plugins, 'plugins is unspecified'); + + // scan rules for react/ and fail if any exist + const reactRuleIds = Object.keys(base.rules) + .filter(ruleId => ruleId.indexOf('react/') === 0); + t.deepEquals(reactRuleIds, [], 'there are no react/ rules'); +}); diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js new file mode 100644 index 0000000000..83df3b1b70 --- /dev/null +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -0,0 +1,83 @@ +import test from 'tape'; +import { CLIEngine, linter } from 'eslint'; +import eslintrc from '../'; + +const cli = new CLIEngine({ + useEslintrc: false, + baseConfig: eslintrc, +}); + +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]; +} + +function wrapComponent(body) { + return ` +import React from 'react'; +export default class MyComponent extends React.Component { +${body} +} +`; +} + +test('validate react prop order', t => { + t.test('make sure our eslintrc has React linting dependencies', t => { + t.plan(2); + t.equal(eslintrc.parser, 'babel-eslint', 'uses babel-eslint'); + t.equal(eslintrc.plugins[0], 'react', 'uses eslint-plugin-react'); + }); + + t.test('passes a good component', t => { + t.plan(3); + const result = lint(wrapComponent(` + componentWillMount() { } + componentDidMount() { } + setFoo() { } + getFoo() { } + setBar() { } + someMethod() { } + renderDogs() { } + render() { return
; } +`)); + + t.notOk(result.warningCount, 'no warnings'); + t.notOk(result.errorCount, 'no errors'); + t.deepEquals(result.messages, [], 'no messages in results'); + }); + + t.test('order: when random method is first', t => { + t.plan(2); + const result = lint(wrapComponent(` + someMethod() { } + componentWillMount() { } + componentDidMount() { } + setFoo() { } + getFoo() { } + setBar() { } + renderDogs() { } + render() { return
; } +`)); + + t.ok(result.errorCount, 'fails'); + t.equal(result.messages[0].ruleId, 'react/sort-comp', 'fails due to sort'); + }); + + t.test('order: when random method after lifecycle methods', t => { + t.plan(2); + const result = lint(wrapComponent(` + componentWillMount() { } + componentDidMount() { } + someMethod() { } + setFoo() { } + getFoo() { } + setBar() { } + renderDogs() { } + render() { return
; } +`)); + + t.ok(result.errorCount, 'fails'); + t.equal(result.messages[0].ruleId, 'react/sort-comp', 'fails due to sort'); + }); +}); From 7646a8619bf7546a05a33556404060869e64ac16 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Wed, 19 Aug 2015 13:42:10 -0700 Subject: [PATCH 0018/1318] lint eslint-config-airbnb with eslint-config-airbnb/base --- packages/eslint-config-airbnb/.eslintrc | 11 +++++ packages/eslint-config-airbnb/base/index.js | 48 ++++++++++--------- packages/eslint-config-airbnb/index.js | 8 ++-- .../node_modules/eslint-config-airbnb | 1 + packages/eslint-config-airbnb/package.json | 1 + .../test/test-react-order.js | 2 +- 6 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 packages/eslint-config-airbnb/.eslintrc create mode 120000 packages/eslint-config-airbnb/node_modules/eslint-config-airbnb diff --git a/packages/eslint-config-airbnb/.eslintrc b/packages/eslint-config-airbnb/.eslintrc new file mode 100644 index 0000000000..cbf450f01f --- /dev/null +++ b/packages/eslint-config-airbnb/.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": "airbnb", + "rules": { + // disable requiring trailing commas because it might be nice to revert to + // being JSON at some point, and I don't want to make big changes now. + "comma-dangle": 0, + // disabled because I find it tedious to write tests while following this + // rule + "no-shadow": 0 + } +} diff --git a/packages/eslint-config-airbnb/base/index.js b/packages/eslint-config-airbnb/base/index.js index c47c2c45dd..65174d856e 100644 --- a/packages/eslint-config-airbnb/base/index.js +++ b/packages/eslint-config-airbnb/base/index.js @@ -23,21 +23,21 @@ module.exports = { 'jsx': true }, 'rules': { -/** - * Strict mode - */ + /** + * Strict mode + */ // babel inserts 'use strict'; for us 'strict': [2, 'never'], // http://eslint.org/docs/rules/strict -/** - * ES6 - */ + /** + * ES6 + */ 'no-var': 2, // http://eslint.org/docs/rules/no-var 'prefer-const': 2, // http://eslint.org/docs/rules/prefer-const -/** - * Variables - */ + /** + * Variables + */ 'no-shadow': 2, // http://eslint.org/docs/rules/no-shadow 'no-shadow-restricted-names': 2, // http://eslint.org/docs/rules/no-shadow-restricted-names 'no-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars @@ -46,9 +46,9 @@ module.exports = { }], 'no-use-before-define': 2, // http://eslint.org/docs/rules/no-use-before-define -/** - * Possible errors - */ + /** + * Possible errors + */ 'comma-dangle': [2, 'always-multiline'], // http://eslint.org/docs/rules/comma-dangle 'no-cond-assign': [2, 'always'], // http://eslint.org/docs/rules/no-cond-assign 'no-console': 1, // http://eslint.org/docs/rules/no-console @@ -71,9 +71,9 @@ module.exports = { 'use-isnan': 2, // http://eslint.org/docs/rules/use-isnan 'block-scoped-var': 2, // http://eslint.org/docs/rules/block-scoped-var -/** - * Best practices - */ + /** + * Best practices + */ 'consistent-return': 2, // http://eslint.org/docs/rules/consistent-return 'curly': [2, 'multi-line'], // http://eslint.org/docs/rules/curly 'default-case': 2, // http://eslint.org/docs/rules/default-case @@ -114,14 +114,16 @@ module.exports = { 'wrap-iife': [2, 'any'], // http://eslint.org/docs/rules/wrap-iife 'yoda': 2, // http://eslint.org/docs/rules/yoda -/** - * Style - */ + /** + * Style + */ 'indent': [2, 2], // http://eslint.org/docs/rules/indent - 'brace-style': [2, // http://eslint.org/docs/rules/brace-style + 'brace-style': [ + 2, // http://eslint.org/docs/rules/brace-style '1tbs', { - 'allowSingleLine': true - }], + 'allowSingleLine': true + } + ], 'quotes': [ 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes ], @@ -136,8 +138,8 @@ module.exports = { 'eol-last': 2, // http://eslint.org/docs/rules/eol-last 'func-names': 1, // http://eslint.org/docs/rules/func-names 'key-spacing': [2, { // http://eslint.org/docs/rules/key-spacing - 'beforeColon': false, - 'afterColon': true + 'beforeColon': false, + 'afterColon': true }], 'new-cap': [2, { // http://eslint.org/docs/rules/new-cap 'newIsCap': true diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index e74501fcd0..3cda9b0f9c 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -1,12 +1,12 @@ -var reactRules = require('./react'); -var base = require('./base'); +const reactRules = require('./react'); +const base = require('./base'); // clone this so we aren't mutating a module -var eslintrc = JSON.parse(JSON.stringify(base)); +const eslintrc = JSON.parse(JSON.stringify(base)); // manually merge in React rules eslintrc.plugins = reactRules.plugins; -Object.keys(reactRules.rules).forEach(function(ruleId) { +Object.keys(reactRules.rules).forEach(function assignRule(ruleId) { eslintrc.rules[ruleId] = reactRules.rules[ruleId]; }); diff --git a/packages/eslint-config-airbnb/node_modules/eslint-config-airbnb b/packages/eslint-config-airbnb/node_modules/eslint-config-airbnb new file mode 120000 index 0000000000..a96aa0ea9d --- /dev/null +++ b/packages/eslint-config-airbnb/node_modules/eslint-config-airbnb @@ -0,0 +1 @@ +.. \ No newline at end of file diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 3af4564f9b..f277fa248f 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -4,6 +4,7 @@ "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { + "lint": "./node_modules/.bin/eslint .", "test": "./node_modules/.bin/babel-tape-runner ./test/test-*.js" }, "repository": { diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index 83df3b1b70..9ef23f6737 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -1,5 +1,5 @@ import test from 'tape'; -import { CLIEngine, linter } from 'eslint'; +import { CLIEngine } from 'eslint'; import eslintrc from '../'; const cli = new CLIEngine({ From 2d90ebf11b06788f7d686a183182eeacaa767a5c Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Wed, 19 Aug 2015 14:01:14 -0700 Subject: [PATCH 0019/1318] update README with new package structure --- packages/eslint-config-airbnb/README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index 6edb34f355..3bc20dc4f0 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -4,9 +4,26 @@ This package provides Airbnb's .eslintrc as an extensible shared config. ## Usage +### With React Style + 1. `npm install --save-dev eslint-config-airbnb babel-eslint eslint-plugin-react` -2. add `"extends": "eslint-config-airbnb"` to your .eslintrc +2. add `"extends": "airbnb"` to your .eslintrc + +### Without React Style + +1. `npm install --save-dev eslint-config-airbnb babel-eslint ` +2. add `"extends": "airbnb/base"` to your .eslintrc See [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript) and the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information. + +## Improving this config + +Consider adding test cases if you're making complicated rules changes, like +anything involving regexes. Perhaps in a distant future, we could use literate +programming to structure our README as test cases for our .eslintrc? + +You can run tests with `npm test`. + +You can make sure this module lints with itself using `npm run lint`. From 64e13a20df2cc5bc91e5f99e7afaeedd629ceb97 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Fri, 21 Aug 2015 14:22:03 -0700 Subject: [PATCH 0020/1318] eslint-config-airbnb 0.0.8 --- packages/eslint-config-airbnb/README.md | 6 ++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index 3bc20dc4f0..ac184f1adb 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -27,3 +27,9 @@ programming to structure our README as test cases for our .eslintrc? You can run tests with `npm test`. You can make sure this module lints with itself using `npm run lint`. + +## Changelog + +### 0.0.8 + - now has a changelog + - now is modular (see instructions above for with react and without react versions) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index f277fa248f..050567251f 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "0.0.7", + "version": "0.0.8", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 761bac606a0d7308c2d8bc843472fa65845b0fce Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 21 Aug 2015 15:08:09 -0700 Subject: [PATCH 0021/1318] [other] add links to other style guides --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b5ff9eb737..df006d0323 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,11 @@ [![Downloads](https://img.shields.io/npm/dm/eslint-config-airbnb.svg)](https://www.npmjs.com/package/eslint-config-airbnb) [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -[For the ES5-only guide click here](es5/). +Other Style Guides + - [ES5](es5/) + - [React](react/) + - [css/scss](https://github.com/airbnb/css) + - [Ruby](https://github.com/airbnb/ruby) ## Table of Contents From 844d3cf38a5a057fe0a3dbf10de99ab8ff9121de Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 21 Aug 2015 15:27:10 -0700 Subject: [PATCH 0022/1318] [other] css/scss => CSS & Sass --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df006d0323..73f3dbfdb8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Other Style Guides - [ES5](es5/) - [React](react/) - - [css/scss](https://github.com/airbnb/css) + - [CSS & Sass](https://github.com/airbnb/css) - [Ruby](https://github.com/airbnb/ruby) ## Table of Contents From c95af97e612db57a242c7c1de29fd4a9754211d4 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Sat, 22 Aug 2015 23:59:50 -0700 Subject: [PATCH 0023/1318] Add no-undef Fixes #454 Fixes #473 --- packages/eslint-config-airbnb/base/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb/base/index.js b/packages/eslint-config-airbnb/base/index.js index 65174d856e..ee578638f0 100644 --- a/packages/eslint-config-airbnb/base/index.js +++ b/packages/eslint-config-airbnb/base/index.js @@ -40,6 +40,7 @@ module.exports = { */ 'no-shadow': 2, // http://eslint.org/docs/rules/no-shadow 'no-shadow-restricted-names': 2, // http://eslint.org/docs/rules/no-shadow-restricted-names + 'no-undef': 2, // http://eslint.org/docs/rules/no-undef 'no-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars 'vars': 'local', 'args': 'after-used' From 933b367e6ccec48b13096b243980f2497516e653 Mon Sep 17 00:00:00 2001 From: Dace Willmott Date: Thu, 27 Aug 2015 14:51:24 -0400 Subject: [PATCH 0024/1318] update spelling to clarify JSX rather than JS --- react/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index 8d02bcca7a..b09e8473fe 100644 --- a/react/README.md +++ b/react/README.md @@ -92,7 +92,7 @@ ``` ## Alignment - - Follow these alignment styles for JS syntax + - Follow these alignment styles for JSX syntax ```javascript // bad From 1733557ac4c175da6eccba0535fb342e7345c22a Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Fri, 28 Aug 2015 11:15:32 -0700 Subject: [PATCH 0025/1318] [react] inline export syntax --- react/README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/react/README.md b/react/README.md index b09e8473fe..43c9baf2c5 100644 --- a/react/README.md +++ b/react/README.md @@ -85,10 +85,8 @@ }); // good - class ReservationCard extends React.Component { + export default class ReservationCard extends React.Component { } - - export default ReservationCard; ``` ## Alignment @@ -272,7 +270,7 @@ text: 'Hello World', }; - class Link extends Component { + export default class Link extends Component { static methodsAreOk() { return true; } @@ -284,8 +282,6 @@ Link.propTypes = propTypes; Link.defaultProps = defaultProps; - - export default Link; ``` - Ordering for React.createClass: From 3307caf5a091d2cb4f68e8b31fd6cc027b96a321 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 28 Aug 2015 13:57:30 -0700 Subject: [PATCH 0026/1318] do not export propTypes We decided to stick with the decision to not export `propTypes`, and leave them as only a static property on the default export. /@josh-perez @gilbox --- react/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index b09e8473fe..f1ea8fb34f 100644 --- a/react/README.md +++ b/react/README.md @@ -262,7 +262,7 @@ ```javascript import React, { Component, PropTypes } from 'react'; - export const propTypes = { + const propTypes = { id: PropTypes.number.isRequired, url: PropTypes.string.isRequired, text: PropTypes.string, From 701cbb954d75a9d99f15c9cf8cbc4e75b9e678ca Mon Sep 17 00:00:00 2001 From: johnmanong Date: Sun, 30 Aug 2015 14:19:20 -0400 Subject: [PATCH 0027/1318] [ong] Default parameters go last. --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73f3dbfdb8..c41183af21 100644 --- a/README.md +++ b/README.md @@ -556,7 +556,21 @@ Other Style Guides } ``` - - [7.8](#7.8) Avoid side effects with default parameters + - [7.8](#7.8) Always put default parameters last. + + ```javascript + // bad + function handleThings(opts = {}, name) { + // ... + } + + // good + function handleThings(name, opts = {}) { + // ... + } + ``` + + - [7.9](#7.9) Avoid side effects with default parameters. > Why? They are confusing to reason about. @@ -572,7 +586,7 @@ Other Style Guides count(); // 3 ``` -- [7.9](#7.9) Never use the Function constructor to create a new function. +- [7.10](#7.10) 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. From eeed55c1545e0794fbbbf3496cd9f7c865c9eb02 Mon Sep 17 00:00:00 2001 From: johnmanong Date: Mon, 31 Aug 2015 18:29:35 -0400 Subject: [PATCH 0028/1318] [ong] swap order of new entry --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c41183af21..43ce70db83 100644 --- a/README.md +++ b/README.md @@ -556,21 +556,7 @@ Other Style Guides } ``` - - [7.8](#7.8) Always put default parameters last. - - ```javascript - // bad - function handleThings(opts = {}, name) { - // ... - } - - // good - function handleThings(name, opts = {}) { - // ... - } - ``` - - - [7.9](#7.9) Avoid side effects with default parameters. + - [7.8](#7.8) Avoid side effects with default parameters. > Why? They are confusing to reason about. @@ -586,6 +572,20 @@ Other Style Guides count(); // 3 ``` + - [7.9](#7.9) Always put default parameters last. + + ```javascript + // bad + function handleThings(opts = {}, name) { + // ... + } + + // good + function handleThings(name, opts = {}) { + // ... + } + ``` + - [7.10](#7.10) 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. From 5695dc12df1d6292e7e93027d46e43f6aa3c4369 Mon Sep 17 00:00:00 2001 From: Andreas Brekken Date: Fri, 4 Sep 2015 09:35:23 -0700 Subject: [PATCH 0029/1318] Make eslintrc dependencies copy-pasteable --- linters/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/linters/README.md b/linters/README.md index b027a5dcd2..1deac701c7 100644 --- a/linters/README.md +++ b/linters/README.md @@ -2,7 +2,10 @@ Our `.eslintrc` requires the following NPM packages: -- `eslint-config-airbnb` -- `eslint` -- `babel-eslint` -- `eslint-plugin-react` +``` +npm install --save-dev \ + eslint-config-airbnb \ + eslint \ + babel-eslint \ + eslint-plugin-react +``` From 2aaaa3ddff84b8fc83fac3077b4c90daa44b9ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ho=C5=99ava?= Date: Tue, 8 Sep 2015 20:21:38 -0700 Subject: [PATCH 0030/1318] improve formatting of Chinese language links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43ce70db83..f5e1de1edd 100644 --- a/README.md +++ b/README.md @@ -2187,8 +2187,8 @@ Other Style Guides - ![br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide) - ![bg](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Bulgaria.png) **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript) - ![ca](https://raw.githubusercontent.com/fpmweb/javascript-style-guide/master/img/catala.png) **Catalan**: [fpmweb/javascript-style-guide](https://github.com/fpmweb/javascript-style-guide) - - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese(Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript) - - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese(Simplified)**: [sivan/javascript-style-guide](https://github.com/sivan/javascript-style-guide) + - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [sivan/javascript-style-guide](https://github.com/sivan/javascript-style-guide) + - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript) - ![fr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/France.png) **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide) - ![de](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png) **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide) - ![it](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png) **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide) From b043025bf69586743f316051fd2c3399746756da Mon Sep 17 00:00:00 2001 From: Weblors Date: Wed, 9 Sep 2015 12:33:18 +0530 Subject: [PATCH 0031/1318] Add to list of In the Wild organizations Added Super as one of the organizations using the styleguide. --- es5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/es5/README.md b/es5/README.md index f961d8e0d6..2d24f1a4a2 100644 --- a/es5/README.md +++ b/es5/README.md @@ -1671,6 +1671,7 @@ - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide) - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/javascript) + - **Super**: [SuperJobs/javascript](https://github.com/SuperJobs/javascript) - **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 9405b1d396bd7c0158a214336004c66f88a00eb3 Mon Sep 17 00:00:00 2001 From: Al Pal Date: Wed, 9 Sep 2015 20:38:43 -0700 Subject: [PATCH 0032/1318] add semicolons to const declarations in 19.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43ce70db83..ab8b9b28ae 100644 --- a/README.md +++ b/README.md @@ -1561,14 +1561,14 @@ Other Style Guides - lastName: 'Nightingale' + lastName: 'Nightingale', + inventorOf: ['coxcomb graph', 'modern nursing'] - } + }; // good - git diff with trailing comma const hero = { firstName: 'Florence', lastName: 'Nightingale', + inventorOf: ['coxcomb chart', 'modern nursing'], - } + }; // bad const hero = { From 867bfdeace20e93c0730349ba6042c4609979731 Mon Sep 17 00:00:00 2001 From: Ankit Sardesai Date: Sat, 12 Sep 2015 21:05:50 -0400 Subject: [PATCH 0033/1318] Added id-length rule to style guide --- packages/eslint-config-airbnb/base/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/eslint-config-airbnb/base/index.js b/packages/eslint-config-airbnb/base/index.js index ee578638f0..ce6bd481b5 100644 --- a/packages/eslint-config-airbnb/base/index.js +++ b/packages/eslint-config-airbnb/base/index.js @@ -128,6 +128,10 @@ module.exports = { 'quotes': [ 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes ], + 'id-length': [2, { + 'min': 2, + 'properties': 'never' + }], 'camelcase': [2, { // http://eslint.org/docs/rules/camelcase 'properties': 'never' }], From 15780d52843a6dd6f51f69768f0ed0f228ee2d13 Mon Sep 17 00:00:00 2001 From: Ankit Sardesai Date: Mon, 14 Sep 2015 17:26:16 -0400 Subject: [PATCH 0034/1318] Added id-length documentation url --- packages/eslint-config-airbnb/base/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/base/index.js b/packages/eslint-config-airbnb/base/index.js index ce6bd481b5..dad7ce9e01 100644 --- a/packages/eslint-config-airbnb/base/index.js +++ b/packages/eslint-config-airbnb/base/index.js @@ -128,7 +128,7 @@ module.exports = { 'quotes': [ 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes ], - 'id-length': [2, { + 'id-length': [2, { // http://eslint.org/docs/rules/id-length 'min': 2, 'properties': 'never' }], From af180978bf8c56135c7cc8d694ed7c6b0b40b77b Mon Sep 17 00:00:00 2001 From: Sindre Moen Date: Thu, 17 Sep 2015 11:21:37 +0200 Subject: [PATCH 0035/1318] =?UTF-8?q?Add=20Hyper=20to=20the=20=E2=80=9Cin?= =?UTF-8?q?=20the=20wild=E2=80=9D=20list=20in=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d06edd70ac..04157e0c9f 100644 --- a/README.md +++ b/README.md @@ -2146,6 +2146,7 @@ Other Style Guides - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript) - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript) - **Huballin**: [huballin/javascript](https://github.com/huballin/javascript) + - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md) - **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide) - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript) - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions) From 7619b854b21c6ffdb14ae7d2294f23cb79e0259f Mon Sep 17 00:00:00 2001 From: Sindre Moen Date: Thu, 17 Sep 2015 11:40:43 +0200 Subject: [PATCH 0036/1318] =?UTF-8?q?Remove=20issues=20from=20how=20to=20a?= =?UTF-8?q?dd=20to=20=E2=80=9Cin=20the=20wild=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d06edd70ac..104c3596fd 100644 --- a/README.md +++ b/README.md @@ -2123,7 +2123,7 @@ Other Style Guides ## In the Wild - This is a list of organizations that are using this style guide. Send us a pull request or open an issue and we'll add you to the list. + This is a list of organizations that are using this style guide. Send us a pull request and we'll add you to the list. - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript) - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript) From f25c85ef2e827f3d3892a0831775807e4bfc727f Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Thu, 24 Sep 2015 12:12:32 -0700 Subject: [PATCH 0037/1318] eslint-config-airbnb 0.0.9 --- 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 050567251f..3325b424cf 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "0.0.8", + "version": "0.0.9", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From e40ea1c24e09c9fba1b4d95b63ab6283dabd4ef6 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Thu, 24 Sep 2015 12:18:34 -0700 Subject: [PATCH 0038/1318] update readme for eslint-config-airbnb 0.0.9 --- packages/eslint-config-airbnb/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index ac184f1adb..1a8be54427 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -30,6 +30,11 @@ You can make sure this module lints with itself using `npm run lint`. ## Changelog +### 0.0.9 + +- add rule no-undef +- add rule id-length + ### 0.0.8 - now has a changelog - now is modular (see instructions above for with react and without react versions) From 58c901c3303610639327a6525613c5c8dfb8f949 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Thu, 24 Sep 2015 12:25:34 -0700 Subject: [PATCH 0039/1318] use eslint 1.3.0 (fixes #515) --- 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 3325b424cf..c59c9e4cbe 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -28,7 +28,7 @@ "devDependencies": { "babel-eslint": "4.0.10", "babel-tape-runner": "1.2.0", - "eslint": "1.1.0", + "eslint": "1.3.0", "eslint-plugin-react": "3.2.3", "react": "0.13.3", "tape": "4.2.0" From 7d0e236b596e85ec42a8747913b0cf57c113522b Mon Sep 17 00:00:00 2001 From: Danny Nemer Date: Fri, 25 Sep 2015 09:59:08 -0400 Subject: [PATCH 0040/1318] Clarify proper type casting for Numbers Clarifies when to use `Number` vs. `parseInt` for Number type casting. Fixes: #523 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c3762839a..243311b703 100644 --- a/README.md +++ b/README.md @@ -1640,7 +1640,7 @@ Other Style Guides const totalScore = String(this.reviewScore); ``` - - [21.3](#21.3) Use `parseInt` for Numbers and always with a radix for type casting. + - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. ```javascript const inputValue = '4'; From daea8a638f1f42cd609f1b68b748ad323be31c10 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Fri, 25 Sep 2015 16:15:38 -0400 Subject: [PATCH 0041/1318] Use rules from eslint-config-defaults --- packages/eslint-config-airbnb/.eslintrc | 5 +- packages/eslint-config-airbnb/base.js | 23 +++ packages/eslint-config-airbnb/base/index.js | 178 ------------------ packages/eslint-config-airbnb/index.js | 20 +- packages/eslint-config-airbnb/package.json | 4 +- packages/eslint-config-airbnb/react.js | 36 ---- .../rules/best-practices.js | 113 +++++++++++ packages/eslint-config-airbnb/rules/errors.js | 60 ++++++ packages/eslint-config-airbnb/rules/es6.js | 51 +++++ packages/eslint-config-airbnb/rules/legacy.js | 16 ++ packages/eslint-config-airbnb/rules/node.js | 23 +++ packages/eslint-config-airbnb/rules/react.js | 78 ++++++++ packages/eslint-config-airbnb/rules/strict.js | 6 + packages/eslint-config-airbnb/rules/style.js | 111 +++++++++++ .../eslint-config-airbnb/rules/variables.js | 26 +++ packages/eslint-config-airbnb/test/.eslintrc | 7 + .../eslint-config-airbnb/test/test-base.js | 33 +++- .../test/test-react-order.js | 9 +- 18 files changed, 556 insertions(+), 243 deletions(-) create mode 100644 packages/eslint-config-airbnb/base.js delete mode 100644 packages/eslint-config-airbnb/base/index.js delete mode 100644 packages/eslint-config-airbnb/react.js create mode 100644 packages/eslint-config-airbnb/rules/best-practices.js create mode 100644 packages/eslint-config-airbnb/rules/errors.js create mode 100644 packages/eslint-config-airbnb/rules/es6.js create mode 100644 packages/eslint-config-airbnb/rules/legacy.js create mode 100644 packages/eslint-config-airbnb/rules/node.js create mode 100644 packages/eslint-config-airbnb/rules/react.js create mode 100644 packages/eslint-config-airbnb/rules/strict.js create mode 100644 packages/eslint-config-airbnb/rules/style.js create mode 100644 packages/eslint-config-airbnb/rules/variables.js create mode 100644 packages/eslint-config-airbnb/test/.eslintrc diff --git a/packages/eslint-config-airbnb/.eslintrc b/packages/eslint-config-airbnb/.eslintrc index cbf450f01f..4b3b1fa429 100644 --- a/packages/eslint-config-airbnb/.eslintrc +++ b/packages/eslint-config-airbnb/.eslintrc @@ -3,9 +3,6 @@ "rules": { // disable requiring trailing commas because it might be nice to revert to // being JSON at some point, and I don't want to make big changes now. - "comma-dangle": 0, - // disabled because I find it tedious to write tests while following this - // rule - "no-shadow": 0 + "comma-dangle": 0 } } diff --git a/packages/eslint-config-airbnb/base.js b/packages/eslint-config-airbnb/base.js new file mode 100644 index 0000000000..f3cbf295ac --- /dev/null +++ b/packages/eslint-config-airbnb/base.js @@ -0,0 +1,23 @@ +module.exports = { + 'extends': [ + './rules/best-practices.js', + './rules/errors.js', + './rules/es6.js', + './rules/legacy.js', + './rules/node.js', + './rules/strict.js', + './rules/style.js', + './rules/variables.js' + ], + 'parser': 'babel-eslint', + 'env': { + 'browser': true, + 'node': true, + 'amd': false, + 'mocha': false, + 'jasmine': false + }, + 'ecmaFeatures': {}, + 'globals': {}, + 'rules': {} +}; diff --git a/packages/eslint-config-airbnb/base/index.js b/packages/eslint-config-airbnb/base/index.js deleted file mode 100644 index dad7ce9e01..0000000000 --- a/packages/eslint-config-airbnb/base/index.js +++ /dev/null @@ -1,178 +0,0 @@ -module.exports = { - 'parser': 'babel-eslint', // https://github.com/babel/babel-eslint - 'env': { // http://eslint.org/docs/user-guide/configuring.html#specifying-environments - 'browser': true, // browser global variables - 'node': true // Node.js global variables and Node.js-specific rules - }, - '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, - 'spread': true, - 'superInFunctions': true, - 'templateStrings': true, - 'jsx': true - }, - 'rules': { - /** - * Strict mode - */ - // babel inserts 'use strict'; for us - 'strict': [2, 'never'], // http://eslint.org/docs/rules/strict - - /** - * ES6 - */ - 'no-var': 2, // http://eslint.org/docs/rules/no-var - 'prefer-const': 2, // http://eslint.org/docs/rules/prefer-const - - /** - * Variables - */ - 'no-shadow': 2, // http://eslint.org/docs/rules/no-shadow - 'no-shadow-restricted-names': 2, // http://eslint.org/docs/rules/no-shadow-restricted-names - 'no-undef': 2, // http://eslint.org/docs/rules/no-undef - 'no-unused-vars': [2, { // http://eslint.org/docs/rules/no-unused-vars - 'vars': 'local', - 'args': 'after-used' - }], - 'no-use-before-define': 2, // http://eslint.org/docs/rules/no-use-before-define - - /** - * Possible errors - */ - 'comma-dangle': [2, 'always-multiline'], // http://eslint.org/docs/rules/comma-dangle - 'no-cond-assign': [2, 'always'], // http://eslint.org/docs/rules/no-cond-assign - 'no-console': 1, // http://eslint.org/docs/rules/no-console - 'no-debugger': 1, // http://eslint.org/docs/rules/no-debugger - 'no-alert': 1, // http://eslint.org/docs/rules/no-alert - 'no-constant-condition': 1, // http://eslint.org/docs/rules/no-constant-condition - 'no-dupe-keys': 2, // http://eslint.org/docs/rules/no-dupe-keys - 'no-duplicate-case': 2, // http://eslint.org/docs/rules/no-duplicate-case - 'no-empty': 2, // http://eslint.org/docs/rules/no-empty - 'no-ex-assign': 2, // http://eslint.org/docs/rules/no-ex-assign - 'no-extra-boolean-cast': 0, // http://eslint.org/docs/rules/no-extra-boolean-cast - 'no-extra-semi': 2, // http://eslint.org/docs/rules/no-extra-semi - 'no-func-assign': 2, // http://eslint.org/docs/rules/no-func-assign - 'no-inner-declarations': 2, // http://eslint.org/docs/rules/no-inner-declarations - 'no-invalid-regexp': 2, // http://eslint.org/docs/rules/no-invalid-regexp - 'no-irregular-whitespace': 2, // http://eslint.org/docs/rules/no-irregular-whitespace - 'no-obj-calls': 2, // http://eslint.org/docs/rules/no-obj-calls - 'no-sparse-arrays': 2, // http://eslint.org/docs/rules/no-sparse-arrays - 'no-unreachable': 2, // http://eslint.org/docs/rules/no-unreachable - 'use-isnan': 2, // http://eslint.org/docs/rules/use-isnan - 'block-scoped-var': 2, // http://eslint.org/docs/rules/block-scoped-var - - /** - * Best practices - */ - 'consistent-return': 2, // http://eslint.org/docs/rules/consistent-return - 'curly': [2, 'multi-line'], // http://eslint.org/docs/rules/curly - 'default-case': 2, // http://eslint.org/docs/rules/default-case - 'dot-notation': [2, { // http://eslint.org/docs/rules/dot-notation - 'allowKeywords': true - }], - 'eqeqeq': 2, // http://eslint.org/docs/rules/eqeqeq - 'guard-for-in': 2, // http://eslint.org/docs/rules/guard-for-in - 'no-caller': 2, // http://eslint.org/docs/rules/no-caller - 'no-else-return': 2, // http://eslint.org/docs/rules/no-else-return - 'no-eq-null': 2, // http://eslint.org/docs/rules/no-eq-null - 'no-eval': 2, // http://eslint.org/docs/rules/no-eval - 'no-extend-native': 2, // http://eslint.org/docs/rules/no-extend-native - 'no-extra-bind': 2, // http://eslint.org/docs/rules/no-extra-bind - 'no-fallthrough': 2, // http://eslint.org/docs/rules/no-fallthrough - 'no-floating-decimal': 2, // http://eslint.org/docs/rules/no-floating-decimal - 'no-implied-eval': 2, // http://eslint.org/docs/rules/no-implied-eval - 'no-lone-blocks': 2, // http://eslint.org/docs/rules/no-lone-blocks - 'no-loop-func': 2, // http://eslint.org/docs/rules/no-loop-func - 'no-multi-str': 2, // http://eslint.org/docs/rules/no-multi-str - 'no-native-reassign': 2, // http://eslint.org/docs/rules/no-native-reassign - 'no-new': 2, // http://eslint.org/docs/rules/no-new - 'no-new-func': 2, // http://eslint.org/docs/rules/no-new-func - 'no-new-wrappers': 2, // http://eslint.org/docs/rules/no-new-wrappers - 'no-octal': 2, // http://eslint.org/docs/rules/no-octal - 'no-octal-escape': 2, // http://eslint.org/docs/rules/no-octal-escape - 'no-param-reassign': 2, // http://eslint.org/docs/rules/no-param-reassign - 'no-proto': 2, // http://eslint.org/docs/rules/no-proto - 'no-redeclare': 2, // http://eslint.org/docs/rules/no-redeclare - 'no-return-assign': 2, // http://eslint.org/docs/rules/no-return-assign - 'no-script-url': 2, // http://eslint.org/docs/rules/no-script-url - 'no-self-compare': 2, // http://eslint.org/docs/rules/no-self-compare - 'no-sequences': 2, // http://eslint.org/docs/rules/no-sequences - 'no-throw-literal': 2, // http://eslint.org/docs/rules/no-throw-literal - 'no-with': 2, // http://eslint.org/docs/rules/no-with - 'radix': 2, // http://eslint.org/docs/rules/radix - 'vars-on-top': 2, // http://eslint.org/docs/rules/vars-on-top - 'wrap-iife': [2, 'any'], // http://eslint.org/docs/rules/wrap-iife - 'yoda': 2, // http://eslint.org/docs/rules/yoda - - /** - * Style - */ - 'indent': [2, 2], // http://eslint.org/docs/rules/indent - 'brace-style': [ - 2, // http://eslint.org/docs/rules/brace-style - '1tbs', { - 'allowSingleLine': true - } - ], - 'quotes': [ - 2, 'single', 'avoid-escape' // http://eslint.org/docs/rules/quotes - ], - 'id-length': [2, { // http://eslint.org/docs/rules/id-length - 'min': 2, - 'properties': 'never' - }], - 'camelcase': [2, { // http://eslint.org/docs/rules/camelcase - 'properties': 'never' - }], - 'comma-spacing': [2, { // http://eslint.org/docs/rules/comma-spacing - 'before': false, - 'after': true - }], - 'comma-style': [2, 'last'], // http://eslint.org/docs/rules/comma-style - 'eol-last': 2, // http://eslint.org/docs/rules/eol-last - 'func-names': 1, // http://eslint.org/docs/rules/func-names - 'key-spacing': [2, { // http://eslint.org/docs/rules/key-spacing - 'beforeColon': false, - 'afterColon': true - }], - 'new-cap': [2, { // http://eslint.org/docs/rules/new-cap - 'newIsCap': true - }], - 'no-multiple-empty-lines': [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines - 'max': 2 - }], - 'no-nested-ternary': 2, // http://eslint.org/docs/rules/no-nested-ternary - 'no-new-object': 2, // http://eslint.org/docs/rules/no-new-object - 'no-spaced-func': 2, // http://eslint.org/docs/rules/no-spaced-func - 'no-trailing-spaces': 2, // http://eslint.org/docs/rules/no-trailing-spaces - 'no-extra-parens': [2, 'functions'], // http://eslint.org/docs/rules/no-extra-parens - 'no-underscore-dangle': 0, // http://eslint.org/docs/rules/no-underscore-dangle - 'one-var': [2, 'never'], // http://eslint.org/docs/rules/one-var - 'padded-blocks': [2, 'never'], // http://eslint.org/docs/rules/padded-blocks - 'semi': [2, 'always'], // http://eslint.org/docs/rules/semi - 'semi-spacing': [2, { // http://eslint.org/docs/rules/semi-spacing - 'before': false, - 'after': true - }], - 'space-after-keywords': 2, // http://eslint.org/docs/rules/space-after-keywords - 'space-before-blocks': 2, // http://eslint.org/docs/rules/space-before-blocks - 'space-before-function-paren': [2, 'never'], // http://eslint.org/docs/rules/space-before-function-paren - 'space-infix-ops': 2, // http://eslint.org/docs/rules/space-infix-ops - 'space-return-throw-case': 2, // http://eslint.org/docs/rules/space-return-throw-case - 'spaced-comment': [2, 'always', {// http://eslint.org/docs/rules/spaced-comment - 'exceptions': ['-', '+'], - 'markers': ['=', '!'] // space here to support sprockets directives - }], - } -}; diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index 3cda9b0f9c..74d6f3455e 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -1,13 +1,7 @@ -const reactRules = require('./react'); -const base = require('./base'); - -// clone this so we aren't mutating a module -const eslintrc = JSON.parse(JSON.stringify(base)); - -// manually merge in React rules -eslintrc.plugins = reactRules.plugins; -Object.keys(reactRules.rules).forEach(function assignRule(ruleId) { - eslintrc.rules[ruleId] = reactRules.rules[ruleId]; -}); - -module.exports = eslintrc; +module.exports = { + 'extends': [ + // Need to qualify these here for ESLint to resolve them properly. + 'airbnb/base', + 'airbnb/rules/react.js' + ] +}; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index c59c9e4cbe..87c9da2e9e 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -4,8 +4,8 @@ "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { - "lint": "./node_modules/.bin/eslint .", - "test": "./node_modules/.bin/babel-tape-runner ./test/test-*.js" + "lint": "eslint .", + "test": "babel-tape-runner ./test/test-*.js" }, "repository": { "type": "git", diff --git a/packages/eslint-config-airbnb/react.js b/packages/eslint-config-airbnb/react.js deleted file mode 100644 index a0ab17f396..0000000000 --- a/packages/eslint-config-airbnb/react.js +++ /dev/null @@ -1,36 +0,0 @@ -module.exports = { - 'plugins': [ - 'react' // https://github.com/yannickcr/eslint-plugin-react - ], - rules: { - /** - * JSX style - */ - 'react/display-name': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md - 'react/jsx-boolean-value': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md - 'react/jsx-quotes': [2, 'double'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md - 'react/jsx-no-undef': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md - 'react/jsx-sort-props': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md - 'react/jsx-sort-prop-types': 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md - 'react/jsx-uses-react': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md - 'react/jsx-uses-vars': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md - 'react/no-did-mount-set-state': [2, 'allow-in-func'], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md - 'react/no-did-update-set-state': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md - 'react/no-multi-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md - 'react/no-unknown-property': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md - 'react/prop-types': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md - 'react/react-in-jsx-scope': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md - 'react/self-closing-comp': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md - 'react/wrap-multilines': 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md - 'react/sort-comp': [2, { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md - 'order': [ - 'lifecycle', - '/^on.+$/', - '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', - 'everything-else', - '/^render.+$/', - 'render' - ] - }] - } -}; diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js new file mode 100644 index 0000000000..dfb50473b1 --- /dev/null +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -0,0 +1,113 @@ +module.exports = { + 'rules': { + // Enforces getter/setter pairs in objects + 'accessor-pairs': 0, + // treat var statements as if they were block scoped + 'block-scoped-var': 2, + // specify the maximum cyclomatic complexity allowed in a program + 'complexity': [0, 11], + // require return statements to either always or never specify values + 'consistent-return': 2, + // specify curly brace conventions for all control statements + 'curly': [2, 'multi-line'], + // require default case in switch statements + 'default-case': 2, + // encourages use of dot notation whenever possible + 'dot-notation': [2, { 'allowKeywords': true}], + // enforces consistent newlines before or after dots + 'dot-location': 0, + // require the use of === and !== + 'eqeqeq': 2, + // make sure for-in loops have an if statement + 'guard-for-in': 2, + // disallow the use of alert, confirm, and prompt + 'no-alert': 1, + // disallow use of arguments.caller or arguments.callee + 'no-caller': 2, + // disallow division operators explicitly at beginning of regular expression + '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-empty-label': 2, + // disallow comparisons to null without a type-checking operator + 'no-eq-null': 2, + // disallow use of eval() + 'no-eval': 2, + // disallow adding to native types + 'no-extend-native': 2, + // disallow unnecessary function binding + 'no-extra-bind': 2, + // disallow fallthrough of case statements + 'no-fallthrough': 2, + // disallow the use of leading or trailing decimal points in numeric literals + 'no-floating-decimal': 2, + // disallow the type conversions with shorter notations + 'no-implicit-coercion': 0, + // disallow use of eval()-like methods + 'no-implied-eval': 2, + // disallow this keywords outside of classes or class-like objects + '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 + 'no-loop-func': 2, + // disallow use of multiple spaces + 'no-multi-spaces': 2, + // disallow use of multiline strings + 'no-multi-str': 2, + // disallow reassignments of native objects + 'no-native-reassign': 2, + // disallow use of new operator when not part of the assignment or comparison + 'no-new': 2, + // disallow use of new operator for Function object + 'no-new-func': 2, + // disallows creating new instances of String,Number, and Boolean + 'no-new-wrappers': 2, + // disallow use of (old style) octal literals + 'no-octal': 2, + // disallow use of octal escape sequences in string literals, such as + // var foo = 'Copyright \251'; + 'no-octal-escape': 2, + // disallow reassignment of function parameters + 'no-param-reassign': 2, + // disallow use of process.env + 'no-process-env': 0, + // disallow usage of __proto__ property + 'no-proto': 2, + // disallow declaring the same variable more then once + 'no-redeclare': 2, + // disallow use of assignment in return statement + 'no-return-assign': 2, + // disallow use of `javascript:` urls. + 'no-script-url': 2, + // disallow comparisons where both sides are exactly the same + 'no-self-compare': 2, + // disallow use of comma operator + 'no-sequences': 2, + // restrict what can be thrown as an exception + 'no-throw-literal': 2, + // disallow usage of expressions in statement position + 'no-unused-expressions': 2, + // disallow unnecessary .call() and .apply() + 'no-useless-call': 0, + // disallow use of void operator + 'no-void': 0, + // disallow usage of configurable warning terms in comments: e.g. todo + 'no-warning-comments': [0, { 'terms': ['todo', 'fixme', 'xxx'], 'location': 'start' }], + // disallow use of the with statement + 'no-with': 2, + // require use of the second argument for parseInt() + 'radix': 2, + // 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'], + // require or disallow Yoda conditions + 'yoda': 2 + } +}; diff --git a/packages/eslint-config-airbnb/rules/errors.js b/packages/eslint-config-airbnb/rules/errors.js new file mode 100644 index 0000000000..ec1b1aab0e --- /dev/null +++ b/packages/eslint-config-airbnb/rules/errors.js @@ -0,0 +1,60 @@ +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 + 'no-console': 1, + // disallow use of constant expressions in conditions + 'no-constant-condition': 1, + // disallow control characters in regular expressions + 'no-control-regex': 2, + // disallow use of debugger + 'no-debugger': 1, + // disallow duplicate arguments in functions + 'no-dupe-args': 2, + // disallow duplicate keys when creating object literals + 'no-dupe-keys': 2, + // disallow a duplicate case label. + 'no-duplicate-case': 2, + // disallow the use of empty character classes in regular expressions + 'no-empty-character-class': 2, + // disallow empty statements + 'no-empty': 2, + // disallow assigning to the exception in a catch block + 'no-ex-assign': 2, + // disallow double-negation boolean casts in a boolean context + 'no-extra-boolean-cast': 0, + // disallow unnecessary parentheses + 'no-extra-parens': [2, 'functions'], + // disallow unnecessary semicolons + 'no-extra-semi': 2, + // disallow overwriting functions written as function declarations + 'no-func-assign': 2, + // disallow function or variable declarations in nested blocks + 'no-inner-declarations': 2, + // disallow invalid regular expression strings in the RegExp constructor + 'no-invalid-regexp': 2, + // disallow irregular whitespace outside of strings and comments + 'no-irregular-whitespace': 2, + // disallow negation of the left operand of an in expression + 'no-negated-in-lhs': 2, + // disallow the use of object properties of the global object (Math and JSON) as functions + 'no-obj-calls': 2, + // disallow multiple spaces in a regular expression literal + 'no-regex-spaces': 2, + // disallow sparse arrays + 'no-sparse-arrays': 2, + // disallow unreachable statements after a return, throw, continue, or break statement + 'no-unreachable': 2, + // disallow comparisons with the value NaN + 'use-isnan': 2, + // ensure JSDoc comments are valid + 'valid-jsdoc': 0, + // ensure that the results of typeof are compared against a valid string + 'valid-typeof': 2, + // Avoid code that looks like two expressions but is actually one + 'no-unexpected-multiline': 0 + } +}; diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js new file mode 100644 index 0000000000..b672d4aae1 --- /dev/null +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -0,0 +1,51 @@ +module.exports = { + 'env': { + 'es6': false + }, + '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, + 'spread': true, + 'superInFunctions': true, + 'templateStrings': true, + 'jsx': true + }, + 'rules': { + // require parens in arrow function arguments + 'arrow-parens': 0, + // require space before/after arrow function's arrow + 'arrow-spacing': 0, + // verify super() callings in constructors + 'constructor-super': 0, + // enforce the spacing around the * in generator functions + 'generator-star-spacing': 0, + // disallow modifying variables of class declarations + 'no-class-assign': 0, + // disallow modifying variables that are declared using const + 'no-const-assign': 0, + // disallow to use this/super before super() calling in constructors. + 'no-this-before-super': 0, + // require let or const instead of var + 'no-var': 2, + // require method and property shorthand syntax for object literals + 'object-shorthand': 0, + // suggest using of const declaration for variables that are never modified after declared + 'prefer-const': 2, + // suggest using the spread operator instead of .apply() + 'prefer-spread': 0, + // suggest using Reflect methods where applicable + 'prefer-reflect': 0, + // disallow generator functions that do not have yield + 'require-yield': 0 + } +}; diff --git a/packages/eslint-config-airbnb/rules/legacy.js b/packages/eslint-config-airbnb/rules/legacy.js new file mode 100644 index 0000000000..1d0c518316 --- /dev/null +++ b/packages/eslint-config-airbnb/rules/legacy.js @@ -0,0 +1,16 @@ +module.exports = { + 'rules': { + // specify the maximum depth that blocks can be nested + 'max-depth': [0, 4], + // specify the maximum length of a line in your program + 'max-len': [0, 80, 4], + // limits the number of parameters that can be used in the function declaration. + 'max-params': [0, 3], + // specify the maximum number of statement allowed in a function + 'max-statements': [0, 10], + // disallow use of bitwise operators + 'no-bitwise': 0, + // disallow use of unary operators, ++ and -- + 'no-plusplus': 0 + } +}; diff --git a/packages/eslint-config-airbnb/rules/node.js b/packages/eslint-config-airbnb/rules/node.js new file mode 100644 index 0000000000..16b6f20d45 --- /dev/null +++ b/packages/eslint-config-airbnb/rules/node.js @@ -0,0 +1,23 @@ +module.exports = { + 'env': { + 'node': true + }, + 'rules': { + // enforce return after a callback + 'callback-return': 0, + // enforces error handling in callbacks (node environment) + 'handle-callback-err': 0, + // disallow mixing regular variable and require declarations + 'no-mixed-requires': [0, false], + // disallow use of new operator with the require function + 'no-new-require': 0, + // disallow string concatenation with __dirname and __filename + 'no-path-concat': 0, + // disallow process.exit() + 'no-process-exit': 0, + // restrict usage of specified node modules + 'no-restricted-modules': 0, + // disallow use of synchronous methods (off by default) + 'no-sync': 0 + } +}; diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js new file mode 100644 index 0000000000..30783f0e12 --- /dev/null +++ b/packages/eslint-config-airbnb/rules/react.js @@ -0,0 +1,78 @@ +module.exports = { + 'parser': 'babel-eslint', + 'plugins': [ + 'react' + ], + 'ecmaFeatures': { + 'jsx': false + }, + 'rules': { + // Prevent missing displayName in a React component definition + 'react/display-name': 0, + // Enforce boolean attributes notation in JSX + 'react/jsx-boolean-value': 2, + // Enforce or disallow spaces inside of curly braces in JSX attributes + 'react/jsx-curly-spacing': 0, + // Prevent duplicate props in JSX + 'react/jsx-no-duplicate-props': 0, + // Disallow undeclared variables in JSX + 'react/jsx-no-undef': 2, + // Enforce quote style for JSX attributes + 'react/jsx-quotes': [2, 'double'], + // Enforce propTypes declarations alphabetical sorting + 'react/jsx-sort-prop-types': 0, + // Enforce props alphabetical sorting + 'react/jsx-sort-props': 0, + // Prevent React to be incorrectly marked as unused + 'react/jsx-uses-react': 2, + // Prevent variables used in JSX to be incorrectly marked as unused + 'react/jsx-uses-vars': 2, + // Prevent usage of dangerous JSX properties + 'react/no-danger': 0, + // Prevent usage of setState in componentDidMount + 'react/no-did-mount-set-state': [2, 'allow-in-func'], + // Prevent usage of setState in componentDidUpdate + 'react/no-did-update-set-state': 2, + // Prevent multiple component definition per file + 'react/no-multi-comp': 2, + // Prevent usage of unknown DOM property + 'react/no-unknown-property': 2, + // Prevent missing props validation in a React component definition + 'react/prop-types': 2, + // Prevent missing React when using JSX + 'react/react-in-jsx-scope': 2, + // Restrict file extensions that may be required + 'react/require-extension': 0, + // Prevent extra closing tags for components without children + 'react/self-closing-comp': 2, + // Enforce component methods order + 'react/sort-comp': [2, { + 'order': [ + 'displayName', + 'propTypes', + 'contextTypes', + 'childContextTypes', + 'mixins', + 'statics', + 'defaultProps', + 'constructor', + 'getDefaultProps', + 'getInitialState', + 'getChildContext', + 'componentWillMount', + 'componentDidMount', + 'componentWillReceiveProps', + 'shouldComponentUpdate', + 'componentWillUpdate', + 'componentDidUpdate', + 'componentWillUnmount', + '/^on.+$/', + '/^get.+$/', + '/^render.+$/', + 'render' + ] + }], + // Prevent missing parentheses around multilines JSX + 'react/wrap-multilines': 2 + } +}; diff --git a/packages/eslint-config-airbnb/rules/strict.js b/packages/eslint-config-airbnb/rules/strict.js new file mode 100644 index 0000000000..90ac43608c --- /dev/null +++ b/packages/eslint-config-airbnb/rules/strict.js @@ -0,0 +1,6 @@ +module.exports = { + 'rules': { + // require that all functions are run in strict mode + 'strict': [2, 'never'] + } +}; diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js new file mode 100644 index 0000000000..107b940ba9 --- /dev/null +++ b/packages/eslint-config-airbnb/rules/style.js @@ -0,0 +1,111 @@ +module.exports = { + 'rules': { + // enforce spacing inside array brackets + 'array-bracket-spacing': 0, + // enforce one true brace style + 'brace-style': [2, '1tbs', {'allowSingleLine': true }], + // require camel case names + 'camelcase': [2, {'properties': 'never'}], + // enforce spacing before and after comma + 'comma-spacing': [2, {'before': false, 'after': true}], + // enforce one true comma style + 'comma-style': [2, 'last'], + // require or disallow padding inside computed properties + 'computed-property-spacing': 0, + // enforces consistent naming when capturing the current execution context + 'consistent-this': 0, + // enforce newline at the end of file, with no multiple empty lines + 'eol-last': 2, + // require function expressions to have a name + '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.) + 'id-length': 0, + // this option sets a specific tab width for your code + 'indent': [2, 2], + // enforces spacing between keys and values in object literal properties + 'key-spacing': [2, {'beforeColon': false, 'afterColon': true}], + // enforces empty lines around comments + 'lines-around-comment': 0, + // disallow mixed 'LF' and 'CRLF' as linebreaks + 'linebreak-style': 0, + // specify the maximum depth callbacks can be nested + 'max-nested-callbacks': 0, + // require a capital letter for constructors + '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 + 'newline-after-var': 0, + // disallow use of the Array constructor + 'no-array-constructor': 0, + // disallow use of the continue statement + 'no-continue': 0, + // disallow comments inline after code + 'no-inline-comments': 0, + // disallow if as the only statement in an else block + 'no-lonely-if': 0, + // disallow mixed spaces and tabs for indentation + 'no-mixed-spaces-and-tabs': 0, + // disallow multiple empty lines + 'no-multiple-empty-lines': [2, {'max': 2}], + // disallow nested ternary expressions + 'no-nested-ternary': 2, + // disallow use of the Object constructor + 'no-new-object': 2, + // disallow space between function identifier and application + 'no-spaced-func': 2, + // disallow the use of ternary operators + 'no-ternary': 0, + // disallow trailing whitespace at the end of lines + 'no-trailing-spaces': 2, + // disallow dangling underscores in identifiers + 'no-underscore-dangle': 0, + // disallow the use of Boolean literals in conditional expressions + 'no-unneeded-ternary': 0, + // require or disallow padding inside curly braces + 'object-curly-spacing': 0, + // allow just one var statement per function + 'one-var': [2, 'never'], + // require assignment operator shorthand where possible or prohibit it entirely + 'operator-assignment': 0, + // enforce operators to be placed before or after line breaks + 'operator-linebreak': 0, + // enforce padding within blocks + 'padded-blocks': [2, 'never'], + // require quotes around object literal property names + 'quote-props': 0, + // specify whether double or single quotes should be used + 'quotes': [2, 'single', 'avoid-escape'], + // require identifiers to match the provided regular expression + 'id-match': 0, + // enforce spacing before and after semicolons + '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 + 'sort-vars': 0, + // require a space after certain keywords + 'space-after-keywords': 2, + // require or disallow space before blocks + 'space-before-blocks': 2, + // require or disallow space before function opening parenthesis + 'space-before-function-paren': [2, 'never'], + // require or disallow spaces inside parentheses + 'space-in-parens': 0, + // 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 + 'spaced-comment': [2, 'always', { + 'exceptions': ['-', '+'], + 'markers': ['=', '!'] // space here to support sprockets directives + }], + // require regex literals to be wrapped in parentheses + 'wrap-regex': 0 + } +}; diff --git a/packages/eslint-config-airbnb/rules/variables.js b/packages/eslint-config-airbnb/rules/variables.js new file mode 100644 index 0000000000..3da93fe826 --- /dev/null +++ b/packages/eslint-config-airbnb/rules/variables.js @@ -0,0 +1,26 @@ +module.exports = { + 'rules': { + // enforce or disallow variable initializations at definition + 'init-declarations': 0, + // disallow the catch clause parameter name being the same as a variable in the outer scope + 'no-catch-shadow': 0, + // disallow deletion of variables + 'no-delete-var': 2, + // disallow labels that share a name with a variable + 'no-label-var': 0, + // disallow shadowing of names such as arguments + 'no-shadow-restricted-names': 2, + // disallow declaration of variables already declared in the outer scope + 'no-shadow': 2, + // disallow use of undefined when initializing variables + 'no-undef-init': 0, + // disallow use of undeclared variables unless mentioned in a /*global */ block + 'no-undef': 2, + // 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'}], + // disallow use of variables before they are defined + 'no-use-before-define': 2 + } +}; diff --git a/packages/eslint-config-airbnb/test/.eslintrc b/packages/eslint-config-airbnb/test/.eslintrc new file mode 100644 index 0000000000..bb9f4d60bf --- /dev/null +++ b/packages/eslint-config-airbnb/test/.eslintrc @@ -0,0 +1,7 @@ +{ + "rules": { + // disabled because I find it tedious to write tests while following this + // rule + "no-shadow": 0 + } +} diff --git a/packages/eslint-config-airbnb/test/test-base.js b/packages/eslint-config-airbnb/test/test-base.js index ecf06cdf58..24aa884cd0 100644 --- a/packages/eslint-config-airbnb/test/test-base.js +++ b/packages/eslint-config-airbnb/test/test-base.js @@ -1,13 +1,30 @@ +import fs from 'fs'; +import path from 'path'; import test from 'tape'; -import base from '../base'; -test('base: does not reference react', t => { - t.plan(2); +const files = { + base: require('../base') +}; - t.notOk(base.plugins, 'plugins is unspecified'); +fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => { + if (name === 'react.js') { + return; + } - // scan rules for react/ and fail if any exist - const reactRuleIds = Object.keys(base.rules) - .filter(ruleId => ruleId.indexOf('react/') === 0); - t.deepEquals(reactRuleIds, [], 'there are no react/ rules'); + files[name] = require(`../rules/${name}`); +}); + +Object.keys(files).forEach(name => { + const config = files[name]; + + test(`${name}: does not reference react`, t => { + t.plan(2); + + t.notOk(config.plugins, 'plugins is unspecified'); + + // scan rules for react/ and fail if any exist + const reactRuleIds = Object.keys(config.rules) + .filter(ruleId => ruleId.indexOf('react/') === 0); + t.deepEquals(reactRuleIds, [], 'there are no react/ rules'); + }); }); diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index 9ef23f6737..2778b2dbc4 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -1,10 +1,15 @@ import test from 'tape'; import { CLIEngine } from 'eslint'; import eslintrc from '../'; +import baseConfig from '../base'; +import reactRules from '../rules/react'; const cli = new CLIEngine({ useEslintrc: false, baseConfig: eslintrc, + + // This rule fails when executing on text. + rules: {indent: 0}, }); function lint(text) { @@ -25,8 +30,8 @@ ${body} test('validate react prop order', t => { t.test('make sure our eslintrc has React linting dependencies', t => { t.plan(2); - t.equal(eslintrc.parser, 'babel-eslint', 'uses babel-eslint'); - t.equal(eslintrc.plugins[0], 'react', 'uses eslint-plugin-react'); + t.equal(baseConfig.parser, 'babel-eslint', 'uses babel-eslint'); + t.equal(reactRules.plugins[0], 'react', 'uses eslint-plugin-react'); }); t.test('passes a good component', t => { From db6c4a8b4e7153f6df84e84eb82204c7e41e0c78 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Fri, 25 Sep 2015 16:22:22 -0400 Subject: [PATCH 0042/1318] Remove differences from eslint-config-defaults --- packages/eslint-config-airbnb/rules/react.js | 24 ++--------- packages/eslint-config-airbnb/rules/style.js | 2 +- packages/eslint-config-airbnb/test/.eslintrc | 4 +- .../test/test-react-order.js | 42 +++++++++---------- 4 files changed, 29 insertions(+), 43 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 30783f0e12..0091c3023b 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -4,7 +4,7 @@ module.exports = { 'react' ], 'ecmaFeatures': { - 'jsx': false + 'jsx': true }, 'rules': { // Prevent missing displayName in a React component definition @@ -48,26 +48,10 @@ module.exports = { // Enforce component methods order 'react/sort-comp': [2, { 'order': [ - 'displayName', - 'propTypes', - 'contextTypes', - 'childContextTypes', - 'mixins', - 'statics', - 'defaultProps', - 'constructor', - 'getDefaultProps', - 'getInitialState', - 'getChildContext', - 'componentWillMount', - 'componentDidMount', - 'componentWillReceiveProps', - 'shouldComponentUpdate', - 'componentWillUpdate', - 'componentDidUpdate', - 'componentWillUnmount', + 'lifecycle', '/^on.+$/', - '/^get.+$/', + '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', + 'everything-else', '/^render.+$/', 'render' ] diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 107b940ba9..519227eeef 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -21,7 +21,7 @@ module.exports = { // enforces use of function declarations or expressions 'func-style': 0, // this option enforces minimum and maximum identifier lengths (variable names, property names etc.) - 'id-length': 0, + 'id-length': [2, {'min': 2, 'properties': 'never'}], // this option sets a specific tab width for your code 'indent': [2, 2], // enforces spacing between keys and values in object literal properties diff --git a/packages/eslint-config-airbnb/test/.eslintrc b/packages/eslint-config-airbnb/test/.eslintrc index bb9f4d60bf..7f79874e41 100644 --- a/packages/eslint-config-airbnb/test/.eslintrc +++ b/packages/eslint-config-airbnb/test/.eslintrc @@ -2,6 +2,8 @@ "rules": { // disabled because I find it tedious to write tests while following this // rule - "no-shadow": 0 + "no-shadow": 0, + // tests uses `t` for tape + "id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}] } } diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index 2778b2dbc4..606f723671 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -37,13 +37,13 @@ test('validate react prop order', t => { t.test('passes a good component', t => { t.plan(3); const result = lint(wrapComponent(` - componentWillMount() { } - componentDidMount() { } - setFoo() { } - getFoo() { } - setBar() { } - someMethod() { } - renderDogs() { } + componentWillMount() {} + componentDidMount() {} + setFoo() {} + getFoo() {} + setBar() {} + someMethod() {} + renderDogs() {} render() { return
; } `)); @@ -55,13 +55,13 @@ test('validate react prop order', t => { t.test('order: when random method is first', t => { t.plan(2); const result = lint(wrapComponent(` - someMethod() { } - componentWillMount() { } - componentDidMount() { } - setFoo() { } - getFoo() { } - setBar() { } - renderDogs() { } + someMethod() {} + componentWillMount() {} + componentDidMount() {} + setFoo() {} + getFoo() {} + setBar() {} + renderDogs() {} render() { return
; } `)); @@ -72,13 +72,13 @@ test('validate react prop order', t => { t.test('order: when random method after lifecycle methods', t => { t.plan(2); const result = lint(wrapComponent(` - componentWillMount() { } - componentDidMount() { } - someMethod() { } - setFoo() { } - getFoo() { } - setBar() { } - renderDogs() { } + componentWillMount() {} + componentDidMount() {} + someMethod() {} + setFoo() {} + getFoo() {} + setBar() {} + renderDogs() {} render() { return
; } `)); From 9c7674a7b3daad3f26e4a0bb6cf6d8fbec6789be Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Fri, 25 Sep 2015 16:27:48 -0400 Subject: [PATCH 0043/1318] Update for upstream dependencies - react/jsx-quotes has been superseded by jsx-quotes - eqeqeq now covers comparisons to null --- packages/eslint-config-airbnb/package.json | 6 +++--- packages/eslint-config-airbnb/rules/best-practices.js | 2 +- packages/eslint-config-airbnb/rules/react.js | 2 +- packages/eslint-config-airbnb/rules/style.js | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 87c9da2e9e..39f5126288 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -26,10 +26,10 @@ }, "homepage": "https://github.com/airbnb/javascript", "devDependencies": { - "babel-eslint": "4.0.10", + "babel-eslint": "4.1.3", "babel-tape-runner": "1.2.0", - "eslint": "1.3.0", - "eslint-plugin-react": "3.2.3", + "eslint": "1.5.1", + "eslint-plugin-react": "3.4.2", "react": "0.13.3", "tape": "4.2.0" } diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index dfb50473b1..9d8199eb77 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -31,7 +31,7 @@ module.exports = { // disallow use of labels for anything other then loops and switches 'no-empty-label': 2, // disallow comparisons to null without a type-checking operator - 'no-eq-null': 2, + 'no-eq-null': 0, // disallow use of eval() 'no-eval': 2, // disallow adding to native types diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 0091c3023b..01aa64c30a 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -18,7 +18,7 @@ module.exports = { // Disallow undeclared variables in JSX 'react/jsx-no-undef': 2, // Enforce quote style for JSX attributes - 'react/jsx-quotes': [2, 'double'], + 'react/jsx-quotes': 0, // Enforce propTypes declarations alphabetical sorting 'react/jsx-sort-prop-types': 0, // Enforce props alphabetical sorting diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 519227eeef..fa22403d8b 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -24,6 +24,8 @@ module.exports = { 'id-length': [2, {'min': 2, 'properties': 'never'}], // this option sets a specific tab width for your code 'indent': [2, 2], + // specify whether double or single quotes should be used in JSX attributes + 'jsx-quotes': 2, // enforces spacing between keys and values in object literal properties 'key-spacing': [2, {'beforeColon': false, 'afterColon': true}], // enforces empty lines around comments From de90317a6dd027cdc7a2300687a0c7b2dc533037 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Sun, 27 Sep 2015 18:47:13 -0700 Subject: [PATCH 0044/1318] create legacy.js to export es5 rules --- packages/eslint-config-airbnb/base.js | 18 +----------------- packages/eslint-config-airbnb/index.js | 5 ++--- packages/eslint-config-airbnb/legacy.js | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 packages/eslint-config-airbnb/legacy.js diff --git a/packages/eslint-config-airbnb/base.js b/packages/eslint-config-airbnb/base.js index f3cbf295ac..cc30af4a8d 100644 --- a/packages/eslint-config-airbnb/base.js +++ b/packages/eslint-config-airbnb/base.js @@ -1,23 +1,7 @@ module.exports = { 'extends': [ - './rules/best-practices.js', - './rules/errors.js', + './legacy.js', './rules/es6.js', - './rules/legacy.js', - './rules/node.js', - './rules/strict.js', - './rules/style.js', - './rules/variables.js' ], 'parser': 'babel-eslint', - 'env': { - 'browser': true, - 'node': true, - 'amd': false, - 'mocha': false, - 'jasmine': false - }, - 'ecmaFeatures': {}, - 'globals': {}, - 'rules': {} }; diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index 74d6f3455e..aa13a960ad 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -1,7 +1,6 @@ module.exports = { 'extends': [ - // Need to qualify these here for ESLint to resolve them properly. - 'airbnb/base', - 'airbnb/rules/react.js' + './base.js', + './rules/react.js', ] }; diff --git a/packages/eslint-config-airbnb/legacy.js b/packages/eslint-config-airbnb/legacy.js new file mode 100644 index 0000000000..e85d6a5088 --- /dev/null +++ b/packages/eslint-config-airbnb/legacy.js @@ -0,0 +1,21 @@ +module.exports = { + 'extends': [ + './rules/best-practices.js', + './rules/errors.js', + './rules/legacy.js', + './rules/node.js', + './rules/strict.js', + './rules/style.js', + './rules/variables.js' + ], + 'env': { + 'browser': true, + 'node': true, + 'amd': false, + 'mocha': false, + 'jasmine': false + }, + 'ecmaFeatures': {}, + 'globals': {}, + 'rules': {} +}; From 170dbeb5d45e2fb226efdad9f04bd939e6756393 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Sun, 27 Sep 2015 19:32:34 -0700 Subject: [PATCH 0045/1318] make exported rulesets extend relative to eslint-config-airbnb --- packages/eslint-config-airbnb/base.js | 5 +++-- packages/eslint-config-airbnb/index.js | 7 ++++--- packages/eslint-config-airbnb/legacy.js | 14 +++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/eslint-config-airbnb/base.js b/packages/eslint-config-airbnb/base.js index cc30af4a8d..ff9904e775 100644 --- a/packages/eslint-config-airbnb/base.js +++ b/packages/eslint-config-airbnb/base.js @@ -1,7 +1,8 @@ module.exports = { 'extends': [ - './legacy.js', - './rules/es6.js', + 'eslint-config-airbnb/legacy', + 'eslint-config-airbnb/rules/es6', ], 'parser': 'babel-eslint', + 'rules': {} }; diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index aa13a960ad..46d601fe3f 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -1,6 +1,7 @@ module.exports = { 'extends': [ - './base.js', - './rules/react.js', - ] + 'eslint-config-airbnb/base', + 'eslint-config-airbnb/rules/react', + ], + rules: {} }; diff --git a/packages/eslint-config-airbnb/legacy.js b/packages/eslint-config-airbnb/legacy.js index e85d6a5088..83a4931e84 100644 --- a/packages/eslint-config-airbnb/legacy.js +++ b/packages/eslint-config-airbnb/legacy.js @@ -1,12 +1,12 @@ module.exports = { 'extends': [ - './rules/best-practices.js', - './rules/errors.js', - './rules/legacy.js', - './rules/node.js', - './rules/strict.js', - './rules/style.js', - './rules/variables.js' + 'eslint-config-airbnb/rules/best-practices', + 'eslint-config-airbnb/rules/errors', + 'eslint-config-airbnb/rules/legacy', + 'eslint-config-airbnb/rules/node', + 'eslint-config-airbnb/rules/strict', + 'eslint-config-airbnb/rules/style', + 'eslint-config-airbnb/rules/variables' ], 'env': { 'browser': true, From b42e9b82dd33649a6a9b839d727ae287afc2f145 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Sun, 27 Sep 2015 19:45:52 -0700 Subject: [PATCH 0046/1318] explain eslint-config-airbnb rule choices --- packages/eslint-config-airbnb/README.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index 1a8be54427..d8af31f6a4 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -4,16 +4,30 @@ This package provides Airbnb's .eslintrc as an extensible shared config. ## Usage -### With React Style +We export three ESLint configurations for your usage. -1. `npm install --save-dev eslint-config-airbnb babel-eslint eslint-plugin-react` +### eslint-config-airbnb + +Our default export contains all of our ESLint rules, including EcmaScript 6+ +and React. It requires `eslint`, `babel-eslint`, and `eslint-plugin-react`. + +1. `npm install --save-dev eslint-config-airbnb babel-eslint eslint-plugin-react eslint` 2. add `"extends": "airbnb"` to your .eslintrc -### Without React Style +### eslint-config-airbnb/base + +Lints ES6+ but does not lint React. Requires `eslint` and `babel-eslint`. -1. `npm install --save-dev eslint-config-airbnb babel-eslint ` +1. `npm install --save-dev eslint-config-airbnb babel-eslint eslint` 2. add `"extends": "airbnb/base"` to your .eslintrc +### eslint-config-airbnb/legacy + +Lints ES5 and below. Only requires `eslint`. + +1. `npm install --save-dev eslint-config-airbnb eslint` +2. add `"extends": "airbnb/legacy"` to your .eslintrc + See [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript) and the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information. From e65c6afe443b1d6f761d7ffda9c90e90b9b1a94c Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Sun, 27 Sep 2015 20:00:06 -0700 Subject: [PATCH 0047/1318] eslint-config-airbnb v0.1.0 --- packages/eslint-config-airbnb/README.md | 13 +++++++++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index d8af31f6a4..f142c5a894 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -44,6 +44,19 @@ You can make sure this module lints with itself using `npm run lint`. ## Changelog +### 0.1.0 + +- 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] + +[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 + ### 0.0.9 - add rule no-undef diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 39f5126288..e7cd1bcc3c 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "0.0.9", + "version": "0.1.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 8da7adbdd422530ebbd84b2974076ea594ef249c Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Tue, 29 Sep 2015 12:19:49 -0400 Subject: [PATCH 0048/1318] Clarify strict ESLint rule --- packages/eslint-config-airbnb/rules/strict.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/strict.js b/packages/eslint-config-airbnb/rules/strict.js index 90ac43608c..6d32f8ca59 100644 --- a/packages/eslint-config-airbnb/rules/strict.js +++ b/packages/eslint-config-airbnb/rules/strict.js @@ -1,6 +1,6 @@ module.exports = { 'rules': { - // require that all functions are run in strict mode + // babel inserts `'use strict';` for us 'strict': [2, 'never'] } }; From be61bbd53c93b4937be7c313c87a0a24c6f64be5 Mon Sep 17 00:00:00 2001 From: Gregory McCue Date: Thu, 1 Oct 2015 11:35:30 +0200 Subject: [PATCH 0049/1318] Add Ecosia to "In the Wild" section. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 243311b703..55da2887d9 100644 --- a/README.md +++ b/README.md @@ -2136,6 +2136,7 @@ Other Style Guides - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) + - **Ecosia**: [evernote/javascript](https://github.com/ecosia/javascript) - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide) - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript) - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md) From 3c3c9a299d8986819af2387e5a4766196480f1e7 Mon Sep 17 00:00:00 2001 From: Gregory McCue Date: Thu, 1 Oct 2015 19:08:05 +0200 Subject: [PATCH 0050/1318] Fix link text. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55da2887d9..731c54f810 100644 --- a/README.md +++ b/README.md @@ -2136,7 +2136,7 @@ Other Style Guides - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript) - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) - - **Ecosia**: [evernote/javascript](https://github.com/ecosia/javascript) + - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript) - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide) - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript) - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md) From d4f69efeecc81b1d7a99725d6c6c8e4f494dd738 Mon Sep 17 00:00:00 2001 From: Kevin Cooper Date: Thu, 1 Oct 2015 14:56:39 -0700 Subject: [PATCH 0051/1318] Add reasoning for using double quotes in JSX --- react/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/react/README.md b/react/README.md index d1ce8c73da..b261d8cd89 100644 --- a/react/README.md +++ b/react/README.md @@ -117,6 +117,9 @@ ## Quotes - Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. + + > 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. + ```javascript // bad From ef7fbea3d94bc01907aedf26c686d00383d2201a Mon Sep 17 00:00:00 2001 From: Kevin Cooper Date: Thu, 1 Oct 2015 16:53:49 -0700 Subject: [PATCH 0052/1318] Add further reasoning for using double quotes in JSX --- react/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/react/README.md b/react/README.md index b261d8cd89..dd5592f4ed 100644 --- a/react/README.md +++ b/react/README.md @@ -119,6 +119,7 @@ - Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. > 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 // bad From 1b46be032edcd1dd3a6f993df2a886cbd83a0bdd Mon Sep 17 00:00:00 2001 From: Ankit Sardesai Date: Sun, 4 Oct 2015 03:15:09 -0400 Subject: [PATCH 0053/1318] Added version badge to eslint-config-airbnb --- packages/eslint-config-airbnb/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index f142c5a894..2eedfb5e97 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -1,5 +1,7 @@ # eslint-config-airbnb +[![npm version](https://badge.fury.io/js/eslint-config-airbnb.svg)](http://badge.fury.io/js/eslint-config-airbnb) + This package provides Airbnb's .eslintrc as an extensible shared config. ## Usage From 8dd0b758f3d0f1a5b3643d6c45bc4ba5c5d0a985 Mon Sep 17 00:00:00 2001 From: Nick Hwang Date: Tue, 13 Oct 2015 23:21:02 -0400 Subject: [PATCH 0054/1318] Add HubSpot to 'In The Wild' section --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 731c54f810..fdcdccae2b 100644 --- a/README.md +++ b/README.md @@ -2147,6 +2147,7 @@ Other Style Guides - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript) - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript) - **Huballin**: [huballin/javascript](https://github.com/huballin/javascript) + - **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript) - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md) - **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide) - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript) From 9897e7d8d1d90d5aed622dc52326eb7af3ab0ba0 Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Thu, 15 Oct 2015 18:10:25 -0700 Subject: [PATCH 0055/1318] Add Section 18.8 - No padded blocks This addresses #483 --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index fdcdccae2b..f91884f9b5 100644 --- a/README.md +++ b/README.md @@ -1511,6 +1511,34 @@ Other Style Guides return arr; ``` + - [18.8](#18.8) Do not pad your blocks with blank lines. + + ```javascript + // bad + function bar() { + + console.log(foo); + + } + + // also bad + function bar() { + + console.log(foo); + } + + // still bad + function bar() { + console.log(foo); + + } + + // good + function bar() { + console.log(foo); + } + ``` + **[⬆ back to top](#table-of-contents)** From d276b0c3890e3c6523d91a919b311679800a1a74 Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Thu, 15 Oct 2015 18:15:54 -0700 Subject: [PATCH 0056/1318] Update 17.2 to allow comments in the first line of a block In #483, justjake said that we should update the style guide to allow single line comments in the first line of a block. --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f91884f9b5..c199359500 100644 --- a/README.md +++ b/README.md @@ -1248,7 +1248,7 @@ 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. + - [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. ```javascript // bad @@ -1276,6 +1276,14 @@ Other Style Guides return type; } + + // also good + function getType() { + // set the default type to 'no type' + const type = this._type || 'no type'; + + return type; + } ``` - [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`. From 4b5348a5fc597e2f6084aaec76f346e48d957fd2 Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Fri, 16 Oct 2015 10:35:14 -0700 Subject: [PATCH 0057/1318] Add examples with if statements to 18.8 --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c199359500..028f7295ca 100644 --- a/README.md +++ b/README.md @@ -1530,19 +1530,23 @@ Other Style Guides } // also bad - function bar() { + if (baz) { + console.log(qux); + } else { console.log(foo); + } - // still bad + // good function bar() { console.log(foo); - } // good - function bar() { + if (baz) { + console.log(qux); + } else { console.log(foo); } ``` From efe7507e65a6ef95f04ffa33297ae397e8b63399 Mon Sep 17 00:00:00 2001 From: Maja Wichrowska Date: Tue, 20 Oct 2015 17:31:01 -0700 Subject: [PATCH 0058/1318] export default should not be inline with the class declaration When there are static variables like `propTypes` and `defaultProps`, we shouldn't export them until we have actually set them onto the `Component`. This may change if the current ES7 proposal for static class properties gets accepts, and we update to support it. --- react/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index dd5592f4ed..6b0a8e13e9 100644 --- a/react/README.md +++ b/react/README.md @@ -274,7 +274,7 @@ text: 'Hello World', }; - export default class Link extends Component { + class Link extends Component { static methodsAreOk() { return true; } @@ -286,6 +286,8 @@ Link.propTypes = propTypes; Link.defaultProps = defaultProps; + + export default Link; ``` - Ordering for React.createClass: From ab0a6ca92ba7c43bcb7abb96b6630c46e3a0b2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 23 Oct 2015 10:32:16 +0200 Subject: [PATCH 0059/1318] eslint: Add missing `space-before-keywords` rule All examples in README.md seem to agree on avoiding missing whitespaces before keywords such as: if (cond) { }else { // no space before 'else' } try { }catch (e) { // no space before 'catch' } This patchs adds the `space-before-keywords` rule as an error (as is `space-after-keywords` already). --- packages/eslint-config-airbnb/rules/style.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index fa22403d8b..68d76d4c9d 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -88,8 +88,10 @@ 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, + 'space-after-keywords': [2, 'always'], // require or disallow space before blocks 'space-before-blocks': 2, // require or disallow space before function opening parenthesis From b056ad09bb321169729ce1c6487056716154fe2e Mon Sep 17 00:00:00 2001 From: RH Becker Date: Thu, 29 Oct 2015 22:43:33 -0700 Subject: [PATCH 0060/1318] Flag modification of variables that are declared using `const` keyword as an error. --- 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 b672d4aae1..f192556a33 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -32,7 +32,7 @@ module.exports = { // disallow modifying variables of class declarations 'no-class-assign': 0, // disallow modifying variables that are declared using const - 'no-const-assign': 0, + 'no-const-assign': 2, // disallow to use this/super before super() calling in constructors. 'no-this-before-super': 0, // require let or const instead of var From 7b834b989c9829ba0693ff7e3c74eb5ec058c18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 30 Oct 2015 17:00:14 +0100 Subject: [PATCH 0061/1318] eslint: Fix `no-mixed-spaces-and-tabs` turn off Currently the way the rule is defined, mixing spaces and tabulations in indentation is allowed. However, the comments and documents seems to say the opposite. This patchs turns the rule on so mixing spaces and tabs is NOT allowed. Fixes: #539 --- 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 68d76d4c9d..6fce467280 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -49,7 +49,7 @@ module.exports = { // disallow if as the only statement in an else block 'no-lonely-if': 0, // disallow mixed spaces and tabs for indentation - 'no-mixed-spaces-and-tabs': 0, + 'no-mixed-spaces-and-tabs': 2, // disallow multiple empty lines 'no-multiple-empty-lines': [2, {'max': 2}], // disallow nested ternary expressions From f2f8186d0f878c29209430dd0860745728ee4b53 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 7 Oct 2015 18:18:04 -0700 Subject: [PATCH 0062/1318] Start to write a realistic "testing" section --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fdcdccae2b..278cd1963e 100644 --- a/README.md +++ b/README.md @@ -2015,14 +2015,22 @@ Other Style Guides ## Testing - - [28.1](#28.1) **Yup.** + - [28.1](#28.1) **Yup.** ```javascript - function() { + function () { return true; } ``` + - [28.2](#28.2) **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. + - We primarily use [`mocha`](https://www.npmjs.com/package/mocha) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules. + - 100% test coverage is a good goal to strive for, even if it's not always practical to reach it. + - Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future. + **[⬆ back to top](#table-of-contents)** From 49293bbf8c589966a28298fe4845ad50f9ee39a4 Mon Sep 17 00:00:00 2001 From: frankenbot Date: Mon, 2 Nov 2015 20:11:56 -0800 Subject: [PATCH 0063/1318] Update redirects --- README.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index fdcdccae2b..1a5e54116a 100644 --- a/README.md +++ b/README.md @@ -1109,7 +1109,7 @@ Other Style Guides } ``` - - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/). + - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/). **[⬆ back to top](#table-of-contents)** @@ -1620,7 +1620,7 @@ Other Style Guides })(); ``` - [Read more](http://stackoverflow.com/a/7365214/1712802). + [Read more](http://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214%237365214). **[⬆ back to top](#table-of-contents)** @@ -1989,7 +1989,7 @@ Other Style Guides ## ECMAScript 5 Compatibility - - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/). + - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/). **[⬆ back to top](#table-of-contents)** @@ -2028,7 +2028,7 @@ Other Style Guides ## Performance - - [On Layout & Web Performance](http://kellegous.com/j/2013/01/26/layout-performance/) + - [On Layout & Web Performance](http://www.kellegous.com/j/2013/01/26/layout-performance/) - [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2) - [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost) - [Bang Function](http://jsperf.com/bang-function) @@ -2057,18 +2057,18 @@ Other Style Guides - Code Style Linters + [ESlint](http://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc) - + [JSHint](http://www.jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc) + + [JSHint](http://jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc) + [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json) **Other Style Guides** - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml) - - [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines) - - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/) + - [jQuery Core Style Guidelines](http://contribute.jquery.org/style-guide/js/) + - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js) **Other Styles** - - [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen + - [Naming this in nested functions](https://gist.github.com/cjohansen/4135065) - Christian Johansen - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - Ross Allen - [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun - [Multiple var statements in JavaScript, not superfluous](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman @@ -2095,7 +2095,7 @@ Other Style Guides - [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg - [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy - [JSBooks](http://jsbooks.revolunet.com/) - Julien Bouquillon - - [Third Party JavaScript](http://manning.com/vinegar/) - Ben Vinegar and Anton Kovalyov + - [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov - [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman - [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke - [You Don't Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson @@ -2105,18 +2105,18 @@ Other Style Guides - [DailyJS](http://dailyjs.com/) - [JavaScript Weekly](http://javascriptweekly.com/) - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/) - - [Bocoup Weblog](http://weblog.bocoup.com/) + - [Bocoup Weblog](https://bocoup.com/weblog) - [Adequately Good](http://www.adequatelygood.com/) - - [NCZOnline](http://www.nczonline.net/) + - [NCZOnline](https://www.nczonline.net/) - [Perfection Kills](http://perfectionkills.com/) - [Ben Alman](http://benalman.com/) - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/) - [Dustin Diaz](http://dustindiaz.com/) - - [nettuts](http://net.tutsplus.com/?s=javascript) + - [nettuts](http://code.tutsplus.com/?s=javascript) **Podcasts** - - [JavaScript Jabber](http://devchat.tv/js-jabber/) + - [JavaScript Jabber](https://devchat.tv/js-jabber/) **[⬆ back to top](#table-of-contents)** @@ -2132,7 +2132,7 @@ Other Style Guides - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript) - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript) - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript) - - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/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) - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) @@ -2145,7 +2145,7 @@ Other Style Guides - **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript) - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style) - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript) - - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript) + - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide) - **Huballin**: [huballin/javascript](https://github.com/huballin/javascript) - **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript) - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md) @@ -2153,7 +2153,7 @@ Other Style Guides - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript) - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions) - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript) - - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/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) - **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript) @@ -2172,7 +2172,7 @@ Other Style Guides - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide) - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - **Springload**: [springload/javascript](https://github.com/springload/javascript) - - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/javascript) + - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript) - **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 f130c0ffa26ae24f2e18bac33bc5cf7f62a2d938 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Wed, 4 Nov 2015 11:12:45 +0100 Subject: [PATCH 0064/1318] [6.5] add backticks around stray eval. fixes #556 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2639e44172..5014f94097 100644 --- a/README.md +++ b/README.md @@ -447,7 +447,7 @@ 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](#6.5) Never use `eval()` on a string, it opens too many vulnerabilities. **[⬆ back to top](#table-of-contents)** From 06ed38d57f70df7aeb7514672a9c205a4eae77d9 Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Thu, 5 Nov 2015 15:18:59 -0800 Subject: [PATCH 0065/1318] [eslint] remove id length rule (too much nutrage) --- 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 6fce467280..c1d9ab9df8 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -21,7 +21,7 @@ module.exports = { // enforces use of function declarations or expressions 'func-style': 0, // this option enforces minimum and maximum identifier lengths (variable names, property names etc.) - 'id-length': [2, {'min': 2, 'properties': 'never'}], + 'id-length': 0, // this option sets a specific tab width for your code 'indent': [2, 2], // specify whether double or single quotes should be used in JSX attributes From 7b0ff1246ee209f45e1d35068eb5817116a421de Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Thu, 5 Nov 2015 15:36:01 -0800 Subject: [PATCH 0066/1318] eslint-config-airbnb 0.1.1 --- 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 e7cd1bcc3c..f29f4c2255 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "0.1.0", + "version": "0.1.1", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 88603b84452ade320f5db09b9971b729ec53d490 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 6 Nov 2015 13:09:34 -0800 Subject: [PATCH 0067/1318] [eslint] update `eslint`, `eslint-plugin-react`, `react`, `tape`. --- 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 f29f4c2255..87b117d44d 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -28,9 +28,9 @@ "devDependencies": { "babel-eslint": "4.1.3", "babel-tape-runner": "1.2.0", - "eslint": "1.5.1", - "eslint-plugin-react": "3.4.2", - "react": "0.13.3", - "tape": "4.2.0" + "eslint": "^1.8.0", + "eslint-plugin-react": "^3.7.1", + "react": "^0.13.3", + "tape": "^4.2.2" } } From 0b7c979d82797c0ef54faa63e0a24ca596328c4f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 6 Nov 2015 15:16:49 -0800 Subject: [PATCH 0068/1318] [eslint] Remove `babel-eslint` dependency. --- packages/eslint-config-airbnb/base.js | 1 - packages/eslint-config-airbnb/package.json | 1 - packages/eslint-config-airbnb/rules/react.js | 1 - packages/eslint-config-airbnb/test/test-react-order.js | 3 +-- 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/eslint-config-airbnb/base.js b/packages/eslint-config-airbnb/base.js index ff9904e775..db661c5d1a 100644 --- a/packages/eslint-config-airbnb/base.js +++ b/packages/eslint-config-airbnb/base.js @@ -3,6 +3,5 @@ module.exports = { 'eslint-config-airbnb/legacy', 'eslint-config-airbnb/rules/es6', ], - 'parser': 'babel-eslint', 'rules': {} }; diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 87b117d44d..6236383673 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -26,7 +26,6 @@ }, "homepage": "https://github.com/airbnb/javascript", "devDependencies": { - "babel-eslint": "4.1.3", "babel-tape-runner": "1.2.0", "eslint": "^1.8.0", "eslint-plugin-react": "^3.7.1", diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 01aa64c30a..6e18e1c252 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -1,5 +1,4 @@ module.exports = { - 'parser': 'babel-eslint', 'plugins': [ 'react' ], diff --git a/packages/eslint-config-airbnb/test/test-react-order.js b/packages/eslint-config-airbnb/test/test-react-order.js index 606f723671..1a84b59230 100644 --- a/packages/eslint-config-airbnb/test/test-react-order.js +++ b/packages/eslint-config-airbnb/test/test-react-order.js @@ -29,8 +29,7 @@ ${body} test('validate react prop order', t => { t.test('make sure our eslintrc has React linting dependencies', t => { - t.plan(2); - t.equal(baseConfig.parser, 'babel-eslint', 'uses babel-eslint'); + t.plan(1); t.equal(reactRules.plugins[0], 'react', 'uses eslint-plugin-react'); }); From d432f58655bc28d79ffab591b7d03e37d19823d6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 6 Nov 2015 16:32:28 -0800 Subject: [PATCH 0069/1318] Add `eslint` as a peer dep, 1.0 or greater --- packages/eslint-config-airbnb/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 6236383673..a62acf3d26 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -31,5 +31,8 @@ "eslint-plugin-react": "^3.7.1", "react": "^0.13.3", "tape": "^4.2.2" + }, + "peerDependencies": { + "eslint": ">=1.0.0" } } From d9b5585be4cf3f3c0627b4daab47388f46a1c571 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 6 Nov 2015 16:53:10 -0800 Subject: [PATCH 0070/1318] [eslint config] v1.0.0 --- packages/eslint-config-airbnb/README.md | 10 ++++++++++ packages/eslint-config-airbnb/package.json | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index f142c5a894..cde6950b4d 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -44,6 +44,16 @@ You can make sure this module lints with itself using `npm run lint`. ## Changelog +### 1.0.0 +- require `eslint` `v1.0.0` or higher +- removes `babel-eslint` dependency + +### 0.1.1 +- remove id-length rule (#569) +- enable `no-mixed-spaces-and-tabs` (#539) +- enable `no-const-assign` (#560) +- enable `space-before-keywords` (#554) + ### 0.1.0 - switch to modular rules files courtesy the [eslint-config-default][ecd] diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index a62acf3d26..7eaca47e71 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "0.1.1", + "version": "1.0.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { @@ -20,6 +20,17 @@ "styleguide" ], "author": "Jake Teton-Landis (https://twitter.com/@jitl)", + "contributors": [ + { + "name": "Jake Teton-Landis", + "url": "https://twitter.com/jitl" + }, + { + "name": "Jordan Harband", + "email": "ljharb@gmail.com", + "url": "http://ljharb.codes/" + } + ], "license": "MIT", "bugs": { "url": "https://github.com/airbnb/javascript/issues" From aa6ca6ff68a893b57573709b893ace911cc426ec Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Mon, 9 Nov 2015 14:44:17 +1100 Subject: [PATCH 0071/1318] docs: babel-eslint not neede since 1.0.0 any more --- packages/eslint-config-airbnb/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index cde6950b4d..b328aa9eb6 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -9,16 +9,16 @@ We export three ESLint configurations for your usage. ### eslint-config-airbnb Our default export contains all of our ESLint rules, including EcmaScript 6+ -and React. It requires `eslint`, `babel-eslint`, and `eslint-plugin-react`. +and React. It requires `eslint` and `eslint-plugin-react`. -1. `npm install --save-dev eslint-config-airbnb babel-eslint eslint-plugin-react eslint` +1. `npm install --save-dev eslint-config-airbnb eslint-plugin-react eslint` 2. add `"extends": "airbnb"` to your .eslintrc ### eslint-config-airbnb/base -Lints ES6+ but does not lint React. Requires `eslint` and `babel-eslint`. +Lints ES6+ but does not lint React. Requires `eslint`. -1. `npm install --save-dev eslint-config-airbnb babel-eslint eslint` +1. `npm install --save-dev eslint-config-airbnb eslint` 2. add `"extends": "airbnb/base"` to your .eslintrc ### eslint-config-airbnb/legacy From 4c1fbf2bec202f22eed3de6c99de17dc6bab447a Mon Sep 17 00:00:00 2001 From: Janis Zarzeckis Date: Wed, 11 Nov 2015 14:14:18 +0200 Subject: [PATCH 0072/1318] Add Evolution Gaming to 'In The Wild' section --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index faadf80e4e..e120e5ed55 100644 --- a/README.md +++ b/README.md @@ -2186,6 +2186,7 @@ Other Style Guides - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript) - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide) + - **Evolution Gaming**: [Evolution-Gaming/javascript](https://github.com/Evolution-Gaming/javascript) - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript) - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md) - **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide) From 96b0057b30eaead919e076b25e299f4f68c10ac9 Mon Sep 17 00:00:00 2001 From: Janis Zarzeckis Date: Wed, 11 Nov 2015 17:48:50 +0200 Subject: [PATCH 0073/1318] Organisation renamed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e120e5ed55..a13640cbb9 100644 --- a/README.md +++ b/README.md @@ -2186,7 +2186,7 @@ Other Style Guides - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript) - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript) - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide) - - **Evolution Gaming**: [Evolution-Gaming/javascript](https://github.com/Evolution-Gaming/javascript) + - **Evolution Gaming**: [evolution-gaming/javascript](https://github.com/evolution-gaming/javascript) - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript) - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md) - **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide) From 09c8589e440f841690eb95c0787ed1d5ebf96f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Wed, 11 Nov 2015 10:24:34 -0800 Subject: [PATCH 0074/1318] [eslint] Enforce rule 18.5 Rule 18.5 [1] states that files shall end with a single newline character. Until now, this was not checked because there was no such option in eslint. Since version 1.8.0, eslint provides the ability to do that. See pull request on eslint [2] for details on implementation and usage. Let's use it in airbnb eslint plugin now! [1]: https://github.com/airbnb/javascript#18.5 [2]: https://github.com/eslint/eslint/pull/4266 --- packages/eslint-config-airbnb/rules/style.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index c1d9ab9df8..c9df867f37 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -50,8 +50,8 @@ module.exports = { 'no-lonely-if': 0, // disallow mixed spaces and tabs for indentation 'no-mixed-spaces-and-tabs': 2, - // disallow multiple empty lines - 'no-multiple-empty-lines': [2, {'max': 2}], + // disallow multiple empty lines and only one newline at the end + 'no-multiple-empty-lines': [2, {'max': 2, 'maxEOF': 1}], // disallow nested ternary expressions 'no-nested-ternary': 2, // disallow use of the Object constructor From c501e0d5a667045635938b5ba433eee340b6ffff Mon Sep 17 00:00:00 2001 From: Jan Krems Date: Mon, 16 Nov 2015 13:40:38 -0800 Subject: [PATCH 0075/1318] Use require.resolve to allow nested extend --- packages/eslint-config-airbnb/base.js | 2 +- packages/eslint-config-airbnb/index.js | 2 +- packages/eslint-config-airbnb/legacy.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/base.js b/packages/eslint-config-airbnb/base.js index db661c5d1a..093bd541be 100644 --- a/packages/eslint-config-airbnb/base.js +++ b/packages/eslint-config-airbnb/base.js @@ -2,6 +2,6 @@ module.exports = { 'extends': [ 'eslint-config-airbnb/legacy', 'eslint-config-airbnb/rules/es6', - ], + ].map(require.resolve), 'rules': {} }; diff --git a/packages/eslint-config-airbnb/index.js b/packages/eslint-config-airbnb/index.js index 46d601fe3f..a5a6c5e287 100644 --- a/packages/eslint-config-airbnb/index.js +++ b/packages/eslint-config-airbnb/index.js @@ -2,6 +2,6 @@ module.exports = { 'extends': [ 'eslint-config-airbnb/base', 'eslint-config-airbnb/rules/react', - ], + ].map(require.resolve), rules: {} }; diff --git a/packages/eslint-config-airbnb/legacy.js b/packages/eslint-config-airbnb/legacy.js index 83a4931e84..d01122bc8d 100644 --- a/packages/eslint-config-airbnb/legacy.js +++ b/packages/eslint-config-airbnb/legacy.js @@ -7,7 +7,7 @@ module.exports = { 'eslint-config-airbnb/rules/strict', 'eslint-config-airbnb/rules/style', 'eslint-config-airbnb/rules/variables' - ], + ].map(require.resolve), 'env': { 'browser': true, 'node': true, From a3495e07f484513db203e5d5654e47b221c19f4a Mon Sep 17 00:00:00 2001 From: jpersson Date: Tue, 17 Nov 2015 13:12:02 -0500 Subject: [PATCH 0076/1318] Avoid the word "mutate" while explaining `const` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index faadf80e4e..9f895b9a55 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Other Style Guides - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. - > Why? This ensures that you can't reassign your references (mutation), which can lead to bugs and difficult to comprehend code. + > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. ```javascript // bad @@ -101,7 +101,7 @@ Other Style Guides const b = 2; ``` - - [2.2](#2.2) If you must mutate references, use `let` instead of `var`. + - [2.2](#2.2) If you must reassign references, use `let` instead of `var`. > Why? `let` is block-scoped rather than function-scoped like `var`. From e424a249e31cee495ac4583871856db6e4b4d7c3 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Wed, 25 Nov 2015 20:48:48 -0800 Subject: [PATCH 0077/1318] Enable rest params! --- packages/eslint-config-airbnb/rules/es6.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index f192556a33..b7fde7bf44 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -15,6 +15,7 @@ module.exports = { 'objectLiteralDuplicateProperties': false, 'objectLiteralShorthandMethods': true, 'objectLiteralShorthandProperties': true, + 'restParams': true, 'spread': true, 'superInFunctions': true, 'templateStrings': true, From e0326137d40437a5f727a8e86bab2b97a691b7de Mon Sep 17 00:00:00 2001 From: Jake Teton-Landis Date: Thu, 26 Nov 2015 15:26:17 -0800 Subject: [PATCH 0078/1318] [eslint config] v1.0.2 --- packages/eslint-config-airbnb/README.md | 8 ++++++++ packages/eslint-config-airbnb/package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index b328aa9eb6..1466cf5b99 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -44,6 +44,14 @@ You can make sure this module lints with itself using `npm run lint`. ## Changelog +### 1.0.2 +- enable rest params in linter, derp. (#592) +- enforce rule 18.5, ensuring files end with a single newline character. (#578) + +### 1.0.1 + +oops + ### 1.0.0 - require `eslint` `v1.0.0` or higher - removes `babel-eslint` dependency diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 7eaca47e71..764e648a8f 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "1.0.0", + "version": "1.0.2", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 2557a5bca6b66108d27684ae25c6471e899b0cd7 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 28 Nov 2015 13:25:49 +0100 Subject: [PATCH 0079/1318] Add Section 18.9 - No spaces inside parentheses See #593 --- README.md | 23 ++++++++++++++++++++ packages/eslint-config-airbnb/rules/style.js | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f895b9a55..0c0822d024 100644 --- a/README.md +++ b/README.md @@ -1551,6 +1551,29 @@ Other Style Guides } ``` + - [18.9](#18.9) Do not add spaces inside parentheses. + + ```javascript + // bad + function bar( foo ) { + return foo; + } + + // good + function bar(foo) { + return foo; + } + + // bad + if ( foo ) { + console.log(foo); + } + + // good + if (foo) { + console.log(foo); + } + ``` **[⬆ 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 c9df867f37..54a9e2fef4 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -96,8 +96,8 @@ module.exports = { 'space-before-blocks': 2, // require or disallow space before function opening parenthesis 'space-before-function-paren': [2, 'never'], - // require or disallow spaces inside parentheses - 'space-in-parens': 0, + // disallow spaces inside parentheses + 'space-in-parens': [2, 'never'], // require spaces around operators 'space-infix-ops': 2, // require a space after return, throw, and case From ee3759a7eddd2ba96210c90b0d2ff87d9ba6d209 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 28 Nov 2015 13:28:28 +0100 Subject: [PATCH 0080/1318] Add Section 18.10 - No spaces inside brackets See #593 --- README.md | 12 ++++++++++++ packages/eslint-config-airbnb/rules/style.js | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c0822d024..c5d42505e3 100644 --- a/README.md +++ b/README.md @@ -1575,6 +1575,18 @@ Other Style Guides } ``` + - [18.10](#18.10) Do not add spaces inside brackets. + + ```javascript + // bad + const foo = [ 1, 2, 3 ]; + console.log(foo[ 0 ]); + + // good + const foo = [1, 2, 3]; + console.log(foo[0]); + ``` + **[⬆ back to top](#table-of-contents)** ## Commas diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 54a9e2fef4..0b6fad09c4 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -1,7 +1,7 @@ module.exports = { 'rules': { // enforce spacing inside array brackets - 'array-bracket-spacing': 0, + 'array-bracket-spacing': [2, 'never'], // enforce one true brace style 'brace-style': [2, '1tbs', {'allowSingleLine': true }], // require camel case names @@ -10,8 +10,8 @@ module.exports = { 'comma-spacing': [2, {'before': false, 'after': true}], // enforce one true comma style 'comma-style': [2, 'last'], - // require or disallow padding inside computed properties - 'computed-property-spacing': 0, + // disallow padding inside computed properties + 'computed-property-spacing': [2, 'never'], // enforces consistent naming when capturing the current execution context 'consistent-this': 0, // enforce newline at the end of file, with no multiple empty lines From 6debbcdd733bd00fb7c7f155d86e130337f9709b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 28 Nov 2015 13:29:12 +0100 Subject: [PATCH 0081/1318] Add Section 18.11 - Add spaces inside curly braces Fixes #593 --- README.md | 10 ++++++++++ packages/eslint-config-airbnb/rules/style.js | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c5d42505e3..a953188d0a 100644 --- a/README.md +++ b/README.md @@ -1587,6 +1587,16 @@ Other Style Guides console.log(foo[0]); ``` + - [18.11](#18.11) Add spaces inside curly braces. + + ```javascript + // bad + const foo = {clark: 'kent'}; + + // good + const foo = { clark: 'kent' }; + ``` + **[⬆ back to top](#table-of-contents)** ## Commas diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 0b6fad09c4..90e5aae3b9 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -66,8 +66,8 @@ module.exports = { 'no-underscore-dangle': 0, // disallow the use of Boolean literals in conditional expressions 'no-unneeded-ternary': 0, - // require or disallow padding inside curly braces - 'object-curly-spacing': 0, + // require padding inside curly braces + 'object-curly-spacing': [2, 'always'], // allow just one var statement per function 'one-var': [2, 'never'], // require assignment operator shorthand where possible or prohibit it entirely From 287dee40e5a2fd4ede4ba5b3db380a34d723809e Mon Sep 17 00:00:00 2001 From: zwhitchcox Date: Wed, 2 Dec 2015 12:48:46 -0500 Subject: [PATCH 0082/1318] Add facebook's react to "In the Wild" I can't believe you guys didn't have that one! That's probably your best one. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a953188d0a..2784631227 100644 --- a/README.md +++ b/README.md @@ -2260,6 +2260,7 @@ Other Style Guides - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript) - **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) - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide) - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide) From 2944b9b47b453220b709d2235c63b52addf76a15 Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Wed, 2 Dec 2015 12:24:01 -0800 Subject: [PATCH 0083/1318] Adding jeopardybot to styleguide users. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a953188d0a..ea1dfe78d3 100644 --- a/README.md +++ b/README.md @@ -2245,6 +2245,7 @@ Other Style Guides - **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide) - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript) - **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) - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide) - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript) From e754dcc7cf29b767f1aae615bdc99b78b54b044b Mon Sep 17 00:00:00 2001 From: Gerardo Renovales Date: Wed, 2 Dec 2015 16:40:41 -0500 Subject: [PATCH 0084/1318] Update README.md Adding Bisk to the list of organizations --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ea1dfe78d3..8b2ed0c2b2 100644 --- a/README.md +++ b/README.md @@ -2224,6 +2224,7 @@ Other Style Guides - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript) - **Avalara**: [avalara/javascript](https://github.com/avalara/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) - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide) - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide) From 599ca4f1238ed3b57f4f5b721f253d2d1b75cda2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 2 Dec 2015 22:58:11 -0800 Subject: [PATCH 0085/1318] Require a space between `function` and `(`, and `function` and the function's name, and disallow spaces between the function's name and `(`. --- README.md | 56 ++++++++++++-------- packages/eslint-config-airbnb/rules/style.js | 5 +- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0ed984acf5..a6158c41b3 100644 --- a/README.md +++ b/README.md @@ -598,6 +598,20 @@ Other Style Guides var subtract = Function('a', 'b', 'return a - b'); ``` +- [7.11](#7.11) Spacing in a function signature. + + > Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name. + ```javascript + // bad + const f = function(){}; + const g = function (){}; + const h = function() {}; + + // good + const x = function () {}; + const y = function a() {}; + ``` + **[⬆ back to top](#table-of-contents)** ## Arrow Functions @@ -690,7 +704,7 @@ Other Style Guides function Queue(contents = []) { this._queue = [...contents]; } - Queue.prototype.pop = function() { + Queue.prototype.pop = function () { const value = this._queue[0]; this._queue.splice(0, 1); return value; @@ -721,7 +735,7 @@ Other Style Guides Queue.apply(this, contents); } inherits(PeekableQueue, Queue); - PeekableQueue.prototype.peek = function() { + PeekableQueue.prototype.peek = function () { return this._queue[0]; } @@ -737,12 +751,12 @@ Other Style Guides ```javascript // bad - Jedi.prototype.jump = function() { + Jedi.prototype.jump = function () { this.jumping = true; return true; }; - Jedi.prototype.setHeight = function(height) { + Jedi.prototype.setHeight = function (height) { this.height = height; }; @@ -974,7 +988,7 @@ Other Style Guides ```javascript // good - function() { + function () { test(); console.log('doing stuff..'); @@ -990,7 +1004,7 @@ Other Style Guides } // bad - unnecessary function call - function(hasName) { + function (hasName) { const name = getName(); if (!hasName) { @@ -1003,7 +1017,7 @@ Other Style Guides } // good - function(hasName) { + function (hasName) { if (!hasName) { return false; } @@ -1063,7 +1077,7 @@ Other Style Guides anonymous(); // => TypeError anonymous is not a function - var anonymous = function() { + var anonymous = function () { console.log('anonymous function expression'); }; } @@ -1180,10 +1194,10 @@ Other Style Guides } // bad - function() { return false; } + function () { return false; } // good - function() { + function () { return false; } ``` @@ -1323,17 +1337,17 @@ Other Style Guides ```javascript // bad - function() { + function () { ∙∙∙∙const name; } // bad - function() { + function () { ∙const name; } // good - function() { + function () { ∙∙const name; } ``` @@ -1402,14 +1416,14 @@ Other Style Guides ```javascript // bad - (function(global) { + (function (global) { // ...stuff... })(this); ``` ```javascript // bad - (function(global) { + (function (global) { // ...stuff... })(this);↵ ↵ @@ -1417,7 +1431,7 @@ Other Style Guides ```javascript // good - (function(global) { + (function (global) { // ...stuff... })(this);↵ ``` @@ -1687,7 +1701,7 @@ Other Style Guides ```javascript // bad - (function() { + (function () { const name = 'Skywalker' return name })() @@ -1857,7 +1871,7 @@ Other Style Guides // bad function foo() { const self = this; - return function() { + return function () { console.log(self); }; } @@ -1865,7 +1879,7 @@ Other Style Guides // bad function foo() { const that = this; - return function() { + return function () { console.log(that); }; } @@ -1986,7 +2000,7 @@ Other Style Guides ... - $(this).on('listingUpdated', function(e, listingId) { + $(this).on('listingUpdated', function (e, listingId) { // do something with listingId }); ``` @@ -1999,7 +2013,7 @@ Other Style Guides ... - $(this).on('listingUpdated', function(e, data) { + $(this).on('listingUpdated', function (e, data) { // do something with data.listingId }); ``` diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 90e5aae3b9..54449e9c2c 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -95,8 +95,9 @@ module.exports = { // require or disallow space before blocks 'space-before-blocks': 2, // require or disallow space before function opening parenthesis - 'space-before-function-paren': [2, 'never'], - // disallow spaces inside parentheses + // https://github.com/eslint/eslint/blob/master/docs/rules/space-before-function-paren.md + 'space-before-function-paren': [2, { 'anonymous': 'always', 'named': 'never' }], + // require or disallow spaces inside parentheses 'space-in-parens': [2, 'never'], // require spaces around operators 'space-infix-ops': 2, From 4ccd04b69a8ca915b9637ac63e6f792f73f57553 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 3 Dec 2015 00:09:12 -0800 Subject: [PATCH 0086/1318] I abhor switch statements, but their indentation should be: ```js switch (foo) { case 'bar': break; } ``` not what the plugin currently requires: ```js switch (foo) { case: 'bar': break; } ``` --- packages/eslint-config-airbnb/rules/style.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 90e5aae3b9..b24943750e 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -23,7 +23,8 @@ module.exports = { // 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 - 'indent': [2, 2], + // https://github.com/eslint/eslint/blob/master/docs/rules/indent.md + 'indent': [2, 2, { "SwitchCase": 1, "VariableDeclarator": 1 }], // specify whether double or single quotes should be used in JSX attributes 'jsx-quotes': 2, // enforces spacing between keys and values in object literal properties From 4c0a70e4358704f4eb39a287bc8a3106825db19c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 3 Dec 2015 13:55:09 -0800 Subject: [PATCH 0087/1318] [eslint config] v2.0.0 - separate changelog --- packages/eslint-config-airbnb/CHANGELOG.md | 52 ++++++++++++++++++++++ packages/eslint-config-airbnb/README.md | 42 ----------------- packages/eslint-config-airbnb/package.json | 2 +- 3 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 packages/eslint-config-airbnb/CHANGELOG.md diff --git a/packages/eslint-config-airbnb/CHANGELOG.md b/packages/eslint-config-airbnb/CHANGELOG.md new file mode 100644 index 0000000000..c6504072bf --- /dev/null +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -0,0 +1,52 @@ +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) + +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) + +1.0.1 / 2015-11-25 +================== + - *erroneous publish* + +1.0.0 / 2015-11-08 +================== + - 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) + +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] + +0.0.9 / 2015-09-24 +================== +- add rule `no-undef` +- add rule `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) + +0.0.7 / 2015-07-30 +================== + - 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 diff --git a/packages/eslint-config-airbnb/README.md b/packages/eslint-config-airbnb/README.md index 1466cf5b99..f795c86bea 100644 --- a/packages/eslint-config-airbnb/README.md +++ b/packages/eslint-config-airbnb/README.md @@ -41,45 +41,3 @@ programming to structure our README as test cases for our .eslintrc? You can run tests with `npm test`. You can make sure this module lints with itself using `npm run lint`. - -## Changelog - -### 1.0.2 -- enable rest params in linter, derp. (#592) -- enforce rule 18.5, ensuring files end with a single newline character. (#578) - -### 1.0.1 - -oops - -### 1.0.0 -- require `eslint` `v1.0.0` or higher -- removes `babel-eslint` dependency - -### 0.1.1 -- remove id-length rule (#569) -- enable `no-mixed-spaces-and-tabs` (#539) -- enable `no-const-assign` (#560) -- enable `space-before-keywords` (#554) - -### 0.1.0 - -- 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] - -[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 - -### 0.0.9 - -- add rule no-undef -- add rule id-length - -### 0.0.8 - - now has a changelog - - now is modular (see instructions above for with react and without react versions) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 764e648a8f..6e4d1b64a2 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "1.0.2", + "version": "2.0.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From a31c72a1e5fa56891b35bf63741b34868a66a9b3 Mon Sep 17 00:00:00 2001 From: Jon Abrams Date: Thu, 3 Dec 2015 14:37:52 -0800 Subject: [PATCH 0088/1318] Fix example for section 7.11 The missing newline caused the markdown parser to misinterpret the beginning and end of the code block. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a6158c41b3..cce04248be 100644 --- a/README.md +++ b/README.md @@ -601,6 +601,7 @@ Other Style Guides - [7.11](#7.11) Spacing in a function signature. > Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name. + ```javascript // bad const f = function(){}; From a1efff9f6de3adca4ffac49e521f596cc24e7df8 Mon Sep 17 00:00:00 2001 From: Josh Perez Date: Thu, 3 Dec 2015 15:39:49 -0800 Subject: [PATCH 0089/1318] Documents corresponding eslint rules --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cce04248be..f854fed8e7 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,8 @@ Other Style Guides > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. + eslint rules: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html). + ```javascript // bad var a = 1; @@ -105,6 +107,8 @@ Other Style Guides > Why? `let` is block-scoped rather than function-scoped like `var`. + eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html). + ```javascript // bad var count = 1; @@ -137,6 +141,8 @@ Other Style Guides - [3.1](#3.1) Use the literal syntax for object creation. + eslint rules: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html). + ```javascript // bad const item = new Object(); @@ -209,6 +215,8 @@ Other Style Guides - [3.5](#3.5) Use object method shorthand. + eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). + ```javascript // bad const atom = { @@ -234,6 +242,8 @@ Other Style Guides > Why? It is shorter to write and descriptive. + eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html). + ```javascript const lukeSkywalker = 'Luke Skywalker'; @@ -283,6 +293,8 @@ Other Style Guides - [4.1](#4.1) Use the literal syntax for array creation. + eslint rules: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html). + ```javascript // bad const items = new Array(); @@ -399,6 +411,8 @@ Other Style Guides - [6.1](#6.1) Use single quotes `''` for strings. + eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html). + ```javascript // bad const name = "Capt. Janeway"; @@ -431,6 +445,8 @@ Other Style Guides > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. + eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html). + ```javascript // bad function sayHi(name) { @@ -601,7 +617,7 @@ Other Style Guides - [7.11](#7.11) Spacing in a function signature. > Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name. - + ```javascript // bad const f = function(){}; @@ -623,6 +639,8 @@ Other Style Guides > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration. + eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html). + ```javascript // bad [1, 2, 3].map(function (x) { @@ -643,6 +661,8 @@ Other Style Guides > Why not? If you plan on returning an object. + eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html). + ```javascript // good [1, 2, 3].map(number => `A string containing the ${number}.`); @@ -683,6 +703,8 @@ Other Style Guides > Why? Less visual clutter. + eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html). + ```js // good [1, 2, 3].map(x => x * x); @@ -861,6 +883,8 @@ Other Style Guides > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects. + eslint rules: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html). + ```javascript const numbers = [1, 2, 3, 4, 5]; @@ -893,6 +917,8 @@ Other Style Guides - [12.1](#12.1) Use dot notation when accessing properties. + eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html). + ```javascript const luke = { jedi: true, @@ -940,6 +966,8 @@ Other Style Guides > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. + eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html). + ```javascript // bad const items = getItems(), @@ -1134,6 +1162,8 @@ Other Style Guides - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: + eslint rules: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html). + + **Objects** evaluate to **true** + **Undefined** evaluates to **false** + **Null** evaluates to **false** @@ -1206,6 +1236,8 @@ Other Style Guides - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your `if` block's closing brace. + eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html). + ```javascript // bad if (test) { @@ -1336,6 +1368,8 @@ Other Style Guides - [18.1](#18.1) Use soft tabs set to 2 spaces. + eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html). + ```javascript // bad function () { @@ -1355,6 +1389,8 @@ Other Style Guides - [18.2](#18.2) Place 1 space before the leading brace. + eslint rules: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html). + ```javascript // bad function test(){ @@ -1381,6 +1417,8 @@ Other Style Guides - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations. + eslint rules: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html). + ```javascript // bad if(isJedi) { @@ -1405,6 +1443,8 @@ Other Style Guides - [18.4](#18.4) Set off operators with spaces. + eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html). + ```javascript // bad const x=y+5; @@ -1536,6 +1576,8 @@ Other Style Guides - [18.8](#18.8) Do not pad your blocks with blank lines. + eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html). + ```javascript // bad function bar() { @@ -1568,6 +1610,8 @@ Other Style Guides - [18.9](#18.9) Do not add spaces inside parentheses. + eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html). + ```javascript // bad function bar( foo ) { @@ -1592,6 +1636,8 @@ Other Style Guides - [18.10](#18.10) Do not add spaces inside brackets. + eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html). + ```javascript // bad const foo = [ 1, 2, 3 ]; @@ -1604,6 +1650,8 @@ Other Style Guides - [18.11](#18.11) Add spaces inside curly braces. + eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html). + ```javascript // bad const foo = {clark: 'kent'}; @@ -1618,6 +1666,8 @@ Other Style Guides - [19.1](#19.1) Leading commas: **Nope.** + eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html). + ```javascript // bad const story = [ @@ -1652,6 +1702,8 @@ Other Style Guides - [19.2](#19.2) Additional trailing comma: **Yup.** + eslint rules: [`no-comma-dangle`](http://eslint.org/docs/rules/no-comma-dangle.html). + > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. ```javascript @@ -1700,6 +1752,8 @@ Other Style Guides - [20.1](#20.1) **Yup.** + eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html). + ```javascript // bad (function () { @@ -1820,6 +1874,8 @@ Other Style Guides - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. + eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html). + ```javascript // bad const OBJEcttsssss = {}; @@ -1857,6 +1913,8 @@ Other Style Guides - [22.4](#22.4) Use a leading underscore `_` when naming private properties. + eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html). + ```javascript // bad this.__firstName__ = 'Panda'; @@ -1894,6 +1952,7 @@ Other Style Guides ``` - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class. + ```javascript // file contents class CheckBox { From 721b8cd01fe44aa9167699a041dd7695b38aa64a Mon Sep 17 00:00:00 2001 From: Benjamin Winterberg Date: Wed, 9 Dec 2015 10:51:49 +0100 Subject: [PATCH 0090/1318] Fix syntax highlighting in section 15 --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f854fed8e7..5276f4a932 100644 --- a/README.md +++ b/README.md @@ -1164,12 +1164,12 @@ Other Style Guides eslint rules: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html). - + **Objects** evaluate to **true** - + **Undefined** evaluates to **false** - + **Null** evaluates to **false** - + **Booleans** evaluate to **the value of the boolean** - + **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true** - + **Strings** evaluate to **false** if an empty string `''`, otherwise **true** + + **Objects** evaluate to **true** + + **Undefined** evaluates to **false** + + **Null** evaluates to **false** + + **Booleans** evaluate to **the value of the boolean** + + **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true** + + **Strings** evaluate to **false** if an empty string `''`, otherwise **true** ```javascript if ([0]) { From 514bd87d1a8d96f7259ed4d1bcc9eb64618811a0 Mon Sep 17 00:00:00 2001 From: Vladimir Kutepov Date: Fri, 11 Dec 2015 13:39:03 +0500 Subject: [PATCH 0091/1318] Require space before/after arrow function's arrow (arrow-spacing) Enable [arrow-spacing](http://eslint.org/docs/rules/arrow-spacing.html) rule, code with space before/after arrow function's arrow is easier to read. ```js () => {}; (a) => {}; a => a; () => {'\n'}; ()=> {}; /*error Missing space before =>*/ () =>{}; /*error Missing space after =>*/ (a)=> {}; /*error Missing space before =>*/ (a) =>{}; /*error Missing space after =>*/ a =>a; /*error Missing space after =>*/ a=> a; /*error Missing space before =>*/ ()=> {'\n'}; /*error Missing space before =>*/ () =>{'\n'}; /*error Missing space after =>*/ ``` --- packages/eslint-config-airbnb/rules/es6.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index b7fde7bf44..fde86e8f0f 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -25,7 +25,8 @@ module.exports = { // require parens in arrow function arguments 'arrow-parens': 0, // require space before/after arrow function's arrow - 'arrow-spacing': 0, + // https://github.com/eslint/eslint/blob/master/docs/rules/arrow-spacing.md + 'arrow-spacing': [2, { 'before': true, 'after': true }], // verify super() callings in constructors 'constructor-super': 0, // enforce the spacing around the * in generator functions From d5a636f298c89c5e70dd45ff964505a03e31b92e Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Fri, 11 Dec 2015 18:47:48 -0800 Subject: [PATCH 0092/1318] [react] Including missing defaults to the react eslint --- packages/eslint-config-airbnb/rules/react.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 6e18e1c252..fc40ef908a 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -9,7 +9,7 @@ module.exports = { // Prevent missing displayName in a React component definition 'react/display-name': 0, // Enforce boolean attributes notation in JSX - 'react/jsx-boolean-value': 2, + 'react/jsx-boolean-value': [2, 'never'], // Enforce or disallow spaces inside of curly braces in JSX attributes 'react/jsx-curly-spacing': 0, // Prevent duplicate props in JSX @@ -31,7 +31,7 @@ module.exports = { // Prevent usage of setState in componentDidMount 'react/no-did-mount-set-state': [2, 'allow-in-func'], // Prevent usage of setState in componentDidUpdate - 'react/no-did-update-set-state': 2, + 'react/no-did-update-set-state': [2, 'allow-in-func'], // Prevent multiple component definition per file 'react/no-multi-comp': 2, // Prevent usage of unknown DOM property @@ -56,6 +56,10 @@ module.exports = { ] }], // Prevent missing parentheses around multilines JSX - 'react/wrap-multilines': 2 + 'react/wrap-multilines': [2, { + declaration: true, + assignment: true, + return: true + }] } }; From e9b1ef92bf956e8359305039721950863abdf81b Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Fri, 11 Dec 2015 23:00:10 -0800 Subject: [PATCH 0093/1318] Adding links to lint rules in react styleguide. --- packages/eslint-config-airbnb/package.json | 2 +- packages/eslint-config-airbnb/rules/react.js | 6 ++- react/README.md | 44 ++++++++++++++------ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index 6e4d1b64a2..eb501f9651 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -39,7 +39,7 @@ "devDependencies": { "babel-tape-runner": "1.2.0", "eslint": "^1.8.0", - "eslint-plugin-react": "^3.7.1", + "eslint-plugin-react": "^3.11.3", "react": "^0.13.3", "tape": "^4.2.2" }, diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index fc40ef908a..7246087ec8 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -10,14 +10,18 @@ module.exports = { 'react/display-name': 0, // Enforce boolean attributes notation in JSX 'react/jsx-boolean-value': [2, 'never'], + // Validate closing bracket location in JSX + 'react/jsx-closing-bracket-location': [2, 'line-aligned'], // Enforce or disallow spaces inside of curly braces in JSX attributes 'react/jsx-curly-spacing': 0, + // Validate props indentation in JSX + 'react/jsx-indent-props': [2, 2], // Prevent duplicate props in JSX 'react/jsx-no-duplicate-props': 0, // Disallow undeclared variables in JSX 'react/jsx-no-undef': 2, // Enforce quote style for JSX attributes - 'react/jsx-quotes': 0, + 'react/jsx-quotes': [2, 'double'], // Enforce propTypes declarations alphabetical sorting 'react/jsx-sort-prop-types': 0, // Enforce props alphabetical sorting diff --git a/react/README.md b/react/README.md index 6b0a8e13e9..dde064c58c 100644 --- a/react/README.md +++ b/react/README.md @@ -26,6 +26,8 @@ - Use class extends React.Component 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({ @@ -33,7 +35,7 @@ return
; } }); - + // good class Listing extends React.Component { render() { @@ -46,7 +48,10 @@ - **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: + - **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). + ```javascript // bad const reservationCard = require('./ReservationCard'); @@ -92,6 +97,8 @@ ## 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). + ```javascript // bad 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: [`react/jsx-quotes`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md). + ```javascript // bad @@ -169,7 +178,10 @@ ``` ## Parentheses - - Wrap JSX tags in parentheses when they span more than one line: + - 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). + ```javascript /// bad render() { @@ -196,6 +208,9 @@ ## 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). + ```javascript // bad @@ -205,6 +220,9 @@ ``` - 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). + ```javascript // bad {this.props.text} } } - + Link.propTypes = propTypes; Link.defaultProps = defaultProps; - + export default Link; ``` @@ -314,4 +332,6 @@ 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). + **[⬆ back to top](#table-of-contents)** From d02a50637763c40dc50af2c033f288f4c7643b41 Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Fri, 11 Dec 2015 23:13:30 -0800 Subject: [PATCH 0094/1318] Adding links to react rules for quick reference. --- packages/eslint-config-airbnb/rules/react.js | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 7246087ec8..d5c82c7949 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -7,48 +7,70 @@ 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, // 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'], // Validate closing bracket location in JSX + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md '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, // Validate props indentation in JSX + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md 'react/jsx-indent-props': [2, 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, // Disallow undeclared variables in JSX + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md 'react/jsx-no-undef': 2, // Enforce quote style for JSX attributes + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quote.md 'react/jsx-quotes': [2, 'double'], // 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, // Enforce props alphabetical sorting + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md 'react/jsx-sort-props': 0, // 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, // 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, // Prevent usage of dangerous JSX properties + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md 'react/no-danger': 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'], // Prevent usage of setState in componentDidUpdate + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md 'react/no-did-update-set-state': [2, 'allow-in-func'], // 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, // Prevent usage of unknown DOM property + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md 'react/no-unknown-property': 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, // 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, // 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 component methods order + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md 'react/sort-comp': [2, { 'order': [ 'lifecycle', @@ -60,6 +82,7 @@ module.exports = { ] }], // Prevent missing parentheses around multilines JSX + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md 'react/wrap-multilines': [2, { declaration: true, assignment: true, From 2ab6253f85cb40f799da7c003e13c18ecf6775f8 Mon Sep 17 00:00:00 2001 From: Gerardo Renovales Date: Mon, 14 Dec 2015 15:06:57 -0500 Subject: [PATCH 0095/1318] Update README.md Add OutBoxSoft to the list of organizations --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5276f4a932..2b860dae56 100644 --- a/README.md +++ b/README.md @@ -2333,6 +2333,7 @@ Other Style Guides - **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript) - **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript) - **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript) + - **OutBoxSoft**: [OutBoxSoft/javascript](https://github.com/OutBoxSoft/javascript) - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript) - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide) - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript) From b1500397e1bba4120b10b850038bfff3177fda42 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 14 Dec 2015 22:21:52 -0800 Subject: [PATCH 0096/1318] [eslint config] enable `object-shorthand` rule. Fixes #621. --- packages/eslint-config-airbnb/rules/es6.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/es6.js b/packages/eslint-config-airbnb/rules/es6.js index fde86e8f0f..e1102f259f 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -40,7 +40,8 @@ module.exports = { // require let or const instead of var 'no-var': 2, // require method and property shorthand syntax for object literals - 'object-shorthand': 0, + // https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md + 'object-shorthand': [2, "always", { "ignoreConstructors": true }], // 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 4ab41ede1bb800fc50defa357a889d3a9aa0667a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 14 Dec 2015 23:55:21 -0800 Subject: [PATCH 0097/1318] [eslint config] [Dev Deps] update `eslint` --- 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 eb501f9651..fb4e8cbbd1 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -38,7 +38,7 @@ "homepage": "https://github.com/airbnb/javascript", "devDependencies": { "babel-tape-runner": "1.2.0", - "eslint": "^1.8.0", + "eslint": "^1.10.3", "eslint-plugin-react": "^3.11.3", "react": "^0.13.3", "tape": "^4.2.2" From 0fc31eaf1cd554bb8a0118168c761ace0ad788e0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 15 Dec 2015 01:19:32 -0800 Subject: [PATCH 0098/1318] [eslint config] fix b1500397e1bba4120b10b850038bfff3177fda42 --- 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 e1102f259f..3c277064b6 100644 --- a/packages/eslint-config-airbnb/rules/es6.js +++ b/packages/eslint-config-airbnb/rules/es6.js @@ -41,7 +41,7 @@ module.exports = { 'no-var': 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", { "ignoreConstructors": true }], + 'object-shorthand': [2, 'always'], // 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 60b01bdfb9de42be2032f14bc3fd41b5f6da61a7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 15 Dec 2015 01:22:30 -0800 Subject: [PATCH 0099/1318] [eslint config] v2.1.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 c6504072bf..0017832ca2 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,3 +1,10 @@ +2.1.0 / 2015-12-03 +================== + - [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) + 2.0.0 / 2015-12-03 ================== - [breaking] `space-before-function-paren`: require function spacing: `function (` (#605) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index fb4e8cbbd1..b61d4ee5c8 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "2.0.0", + "version": "2.1.0", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From bbcb1371e57b926f25324d4ea0d24b446f164aa1 Mon Sep 17 00:00:00 2001 From: Billy Janitsch Date: Tue, 15 Dec 2015 15:59:40 -0500 Subject: [PATCH 0100/1318] Remove deprecated react/jsx-quotes --- packages/eslint-config-airbnb/rules/react.js | 3 --- react/README.md | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index d5c82c7949..ffff4a2c15 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -27,9 +27,6 @@ module.exports = { // Disallow undeclared variables in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md 'react/jsx-no-undef': 2, - // Enforce quote style for JSX attributes - // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quote.md - 'react/jsx-quotes': [2, 'double'], // 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, diff --git a/react/README.md b/react/README.md index dde064c58c..3b53d2c0f4 100644 --- a/react/README.md +++ b/react/README.md @@ -128,7 +128,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. - eslint rules: [`react/jsx-quotes`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md). + eslint rules: [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes). ```javascript // bad From 28476a25d8609d3a80d130b8a4dadc4d0a84ca47 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 15 Dec 2015 13:06:28 -0800 Subject: [PATCH 0101/1318] [eslint config] add rule link and defaults to `jsx-quotes` rule --- packages/eslint-config-airbnb/rules/style.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 204d69c5b3..e65e0f3e08 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -26,7 +26,8 @@ module.exports = { // https://github.com/eslint/eslint/blob/master/docs/rules/indent.md 'indent': [2, 2, { "SwitchCase": 1, "VariableDeclarator": 1 }], // specify whether double or single quotes should be used in JSX attributes - 'jsx-quotes': 2, + // 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}], // enforces empty lines around comments From fcc41eecd76480f34f7bb9084d8cdfcf71528625 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 15 Dec 2015 13:07:24 -0800 Subject: [PATCH 0102/1318] v2.1.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 0017832ca2..bc269e9222 100644 --- a/packages/eslint-config-airbnb/CHANGELOG.md +++ b/packages/eslint-config-airbnb/CHANGELOG.md @@ -1,4 +1,8 @@ -2.1.0 / 2015-12-03 +2.1.1 / 2015-12-15 +================== + - [fix] Remove deprecated react/jsx-quotes (#622) + +2.1.0 / 2015-12-15 ================== - [fix] use `require.resolve` to allow nested `extend`s (#582) - [new] enable `object-shorthand` rule (#621) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index b61d4ee5c8..4a22d6d021 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-airbnb", - "version": "2.1.0", + "version": "2.1.1", "description": "Airbnb's ESLint config, following our styleguide", "main": "index.js", "scripts": { From 2589c67b0c392a118aba3e3938856ddfead26baa Mon Sep 17 00:00:00 2001 From: Thomas Shafer Date: Wed, 16 Dec 2015 15:40:26 -0800 Subject: [PATCH 0103/1318] update best-practices config to prevent parameter object manipulation added good/bad examples of parameter mutation to the readme --- README.md | 29 +++++++++++++++++++ .../rules/best-practices.js | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b860dae56..f64fe911a0 100644 --- a/README.md +++ b/README.md @@ -629,6 +629,35 @@ Other Style Guides const y = function a() {}; ``` +- [7.12](#7.12) Never mutate parameters. + + > Why? Overwriting parameters can lead to unexpected behavior, especially when accessing the `arguments` object. 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 f(a){ + a = 1; + } + function f(a){ + if (!a) { a = 1; } + } + function f(obj){ + obj.key = 1; + }; + + // good + function f(a){ + const b = (a || 1); + } + function f(a = 1){ + } + function f(obj){ + const key = obj.hasOwnProperty('key') ? obj.key ? 1; + }; + ``` + **[⬆ back to top](#table-of-contents)** ## Arrow Functions diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 9d8199eb77..e511f9b15e 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -74,7 +74,8 @@ module.exports = { // var foo = 'Copyright \251'; 'no-octal-escape': 2, // disallow reassignment of function parameters - 'no-param-reassign': 2, + // disallow parameter object manipulation + 'no-param-reassign': [2, { 'props': true }], // disallow use of process.env 'no-process-env': 0, // disallow usage of __proto__ property From f7971301b08d8fc870a127167804059ab2b7c71b Mon Sep 17 00:00:00 2001 From: Thomas Shafer Date: Wed, 16 Dec 2015 20:21:38 -0800 Subject: [PATCH 0104/1318] update examples for style add link to no-param-reassign rule documentation --- README.md | 16 ++++++++-------- .../eslint-config-airbnb/rules/best-practices.js | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f64fe911a0..ba2bcd0aed 100644 --- a/README.md +++ b/README.md @@ -637,24 +637,24 @@ Other Style Guides ```javascript // bad - function f(a){ + function f1(a) { a = 1; } - function f(a){ + function f2(a) { if (!a) { a = 1; } } - function f(obj){ + function f3(obj) { obj.key = 1; }; // good - function f(a){ - const b = (a || 1); + function f4(a) { + const b = a || 1; } - function f(a = 1){ + function f5(a = 1) { } - function f(obj){ - const key = obj.hasOwnProperty('key') ? obj.key ? 1; + function f6(obj) { + const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1; }; ``` diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index e511f9b15e..82e5f9e289 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -75,6 +75,7 @@ module.exports = { 'no-octal-escape': 2, // disallow reassignment of function parameters // disallow parameter object manipulation + // rule: http://eslint.org/docs/rules/no-param-reassign.html 'no-param-reassign': [2, { 'props': true }], // disallow use of process.env 'no-process-env': 0, From a533a4fb93c6f1385c2e3ede07a922df6a50dc6a Mon Sep 17 00:00:00 2001 From: Thomas Shafer Date: Thu, 17 Dec 2015 11:18:36 -0800 Subject: [PATCH 0105/1318] added newlines after each function --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ba2bcd0aed..98b0bee495 100644 --- a/README.md +++ b/README.md @@ -640,9 +640,11 @@ Other Style Guides function f1(a) { a = 1; } + function f2(a) { if (!a) { a = 1; } } + function f3(obj) { obj.key = 1; }; @@ -651,8 +653,10 @@ Other Style Guides function f4(a) { const b = a || 1; } + function f5(a = 1) { } + function f6(obj) { const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1; }; From c584319df8de09ff458adb24103dc0b3bcc4adbf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 22 Dec 2015 09:44:07 -0800 Subject: [PATCH 0106/1318] [eslint config] [Dev Deps] update `eslint-plugin-react` --- 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 4a22d6d021..89e745b44f 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -39,7 +39,7 @@ "devDependencies": { "babel-tape-runner": "1.2.0", "eslint": "^1.10.3", - "eslint-plugin-react": "^3.11.3", + "eslint-plugin-react": "^3.12.0", "react": "^0.13.3", "tape": "^4.2.2" }, From c98990c0f957edeb943a992e3dda4e755004d57b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 22 Dec 2015 09:44:26 -0800 Subject: [PATCH 0107/1318] [eslint config] [minor] enable react/prefer-es6-class rule --- packages/eslint-config-airbnb/rules/react.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index ffff4a2c15..4cc9e0d1ad 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -84,6 +84,9 @@ module.exports = { declaration: true, assignment: true, return: true - }] + }], + // 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'], } }; From 4cdc3fe4831c57b0eadd8127ab03a4753382ff78 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 22 Dec 2015 09:49:25 -0800 Subject: [PATCH 0108/1318] [eslint config] [breaking] enable `quote-props` rule. --- README.md | 22 ++++++++++++++++++++ packages/eslint-config-airbnb/rules/style.js | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cebc053bcc..d2378926d9 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,28 @@ Other Style Guides }; ``` + - [3.8](#3.8) Only quote properties that are invalid identifiers. + + > 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). + + ```javascript + // bad + const bad = { + 'foo': 3, + 'bar': 4, + 'data-blah': 5, + }; + + // good + const good = { + foo: 3, + bar: 4, + 'data-blah': 5, + }; + ``` + **[⬆ back to top](#table-of-contents)** ## Arrays diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 284aac483f..66e3a3f7a9 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -85,7 +85,8 @@ module.exports = { // enforce padding within blocks 'padded-blocks': [2, 'never'], // require quotes around object literal property names - 'quote-props': 0, + // http://eslint.org/docs/rules/quote-props.html + 'quote-props': [2, 'as-needed', { 'keywords': true, 'unnecessary': true, 'numbers': false }], // specify whether double or single quotes should be used 'quotes': [2, 'single', 'avoid-escape'], // require identifiers to match the provided regular expression From 6602586a20868ca1eab2e5ca38c715e69136c455 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 22 Dec 2015 11:42:24 -0800 Subject: [PATCH 0109/1318] [eslint config] [minor] Sort react/prefer-es6-class alphabetically All of the other rules in this file are in alphabetical order, but this one was added by c98990c0f out of order at the end. Keeping these in alphabetical order will help developers find the rules that they are looking for. --- packages/eslint-config-airbnb/rules/react.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 4cc9e0d1ad..9722b67869 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -54,6 +54,9 @@ module.exports = { // Prevent usage of unknown DOM property // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md 'react/no-unknown-property': 2, + // 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'], // 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, @@ -85,8 +88,5 @@ module.exports = { assignment: true, return: true }], - // 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'], } }; From f2dc5043a1038a2db58c3e9c59102f96c960d8f2 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 22 Dec 2015 11:46:17 -0800 Subject: [PATCH 0110/1318] [eslint-config] [minor] Enable react/no-is-mounted rule isMounted is an anti-pattern [0], is not available when using ES6 classes, and is on its way to being officially deprecated. eslint-plugin-react recently added the react/no-is-mounted rule in 3.12.0 that prevents its use. [0]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html Finishes #633 --- packages/eslint-config-airbnb/rules/react.js | 3 +++ react/README.md | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 4cc9e0d1ad..bc71327c0a 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -48,6 +48,9 @@ module.exports = { // Prevent usage of setState in componentDidUpdate // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md 'react/no-did-update-set-state': [2, 'allow-in-func'], + // Prevent usage of isMounted + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md + '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, diff --git a/react/README.md b/react/README.md index 3b53d2c0f4..549e853db0 100644 --- a/react/README.md +++ b/react/README.md @@ -15,6 +15,7 @@ 1. [Tags](#tags) 1. [Methods](#methods) 1. [Ordering](#ordering) + 1. [`isMounted`](#ismounted) ## Basic Rules @@ -334,4 +335,12 @@ eslint rules: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md). +## `isMounted` + + [`isMounted` is an anti-pattern][anti-pattern], is not available when using ES6 classes, and is on its way to being officially deprecated. Its use should be avoided. + + [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 055aa14518bd7c31cd54b633bf58c63ec3d962f7 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 22 Dec 2015 22:28:09 -0800 Subject: [PATCH 0111/1318] [readme] Clean up isMounted section in react readme When I added this section in f2dc5043a I didn't do a very good job of following the style used in other parts of this repo. This commit remedies that. --- react/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/react/README.md b/react/README.md index 549e853db0..7491c46be3 100644 --- a/react/README.md +++ b/react/README.md @@ -337,7 +337,9 @@ ## `isMounted` - [`isMounted` is an anti-pattern][anti-pattern], is not available when using ES6 classes, and is on its way to being officially deprecated. Its use should be avoided. + - Do not use `isMounted`. + + > 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 From 76ff913d2648d3613fcdd6438a18886bedf2bf06 Mon Sep 17 00:00:00 2001 From: Aleksey Kislov Date: Wed, 23 Dec 2015 17:34:31 +0300 Subject: [PATCH 0112/1318] Permit strict mode Permit strict mode for legacy configuration as it is not intended to be used with Babel. --- packages/eslint-config-airbnb/legacy.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/eslint-config-airbnb/legacy.js b/packages/eslint-config-airbnb/legacy.js index d01122bc8d..257b9dd868 100644 --- a/packages/eslint-config-airbnb/legacy.js +++ b/packages/eslint-config-airbnb/legacy.js @@ -4,7 +4,6 @@ module.exports = { 'eslint-config-airbnb/rules/errors', 'eslint-config-airbnb/rules/legacy', 'eslint-config-airbnb/rules/node', - 'eslint-config-airbnb/rules/strict', 'eslint-config-airbnb/rules/style', 'eslint-config-airbnb/rules/variables' ].map(require.resolve), From 450e64c9d217ca731561a7d890f1210da82dcef7 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 22 Dec 2015 22:35:11 -0800 Subject: [PATCH 0113/1318] [readme] Add backticks around code items in react readme I noticed a number of places in this document where code was being referenced but it was not marked as such. Adding backticks will instruct the markdown parser to format these bits as code, which should improve the readability of this document. --- react/README.md | 88 ++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/react/README.md b/react/README.md index 7491c46be3..12260155b9 100644 --- a/react/README.md +++ b/react/README.md @@ -23,9 +23,9 @@ - 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` - - Use class extends React.Component unless you have a very good reason to use mixins. + - Use `class extends React.Component` 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). @@ -81,7 +81,7 @@ ## Declaration - - Do not use displayName for naming components. Instead, name the component by reference. + - Do not use `displayName` for naming components. Instead, name the component by reference. ```javascript // bad @@ -261,24 +261,24 @@ ## Ordering - - Ordering for class extends React.Component: - - 1. constructor - 1. optional static methods - 1. getChildContext - 1. componentWillMount - 1. componentDidMount - 1. componentWillReceiveProps - 1. shouldComponentUpdate - 1. componentWillUpdate - 1. componentDidUpdate - 1. componentWillUnmount - 1. *clickHandlers or eventHandlers* like onClickSubmit() or onChangeDescription() - 1. *getter methods for render* like getSelectReason() or getFooterContent() - 1. *Optional render methods* like renderNavigation() or renderProfilePicture() - 1. render - - - How to define propTypes, defaultProps, contextTypes, etc... + - Ordering for `class extends React.Component`: + + 1. `constructor` + 1. optional `static` methods + 1. `getChildContext` + 1. `componentWillMount` + 1. `componentDidMount` + 1. `componentWillReceiveProps` + 1. `shouldComponentUpdate` + 1. `componentWillUpdate` + 1. `componentDidUpdate` + 1. `componentWillUnmount` + 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()` + 1. *getter methods for `render`* like `getSelectReason() or `getFooterContent()` + 1. *Optional render methods* like `renderNavigation()` or `renderProfilePicture()` + 1. `render` + + - How to define `propTypes`, `defaultProps`, `contextTypes`, etc... ```javascript import React, { PropTypes } from 'react'; @@ -309,29 +309,29 @@ export default Link; ``` - - Ordering for React.createClass: - - 1. displayName - 1. propTypes - 1. contextTypes - 1. childContextTypes - 1. mixins - 1. statics - 1. defaultProps - 1. getDefaultProps - 1. getInitialState - 1. getChildContext - 1. componentWillMount - 1. componentDidMount - 1. componentWillReceiveProps - 1. shouldComponentUpdate - 1. componentWillUpdate - 1. componentDidUpdate - 1. componentWillUnmount - 1. *clickHandlers or eventHandlers* like onClickSubmit() or onChangeDescription() - 1. *getter methods for render* like getSelectReason() or getFooterContent() - 1. *Optional render methods* like renderNavigation() or renderProfilePicture() - 1. render + - Ordering for `React.createClass`: + + 1. `displayName` + 1. `propTypes` + 1. `contextTypes` + 1. `childContextTypes` + 1. `mixins` + 1. `statics` + 1. `defaultProps` + 1. `getDefaultProps` + 1. `getInitialState` + 1. `getChildContext` + 1. `componentWillMount` + 1. `componentDidMount` + 1. `componentWillReceiveProps` + 1. `shouldComponentUpdate` + 1. `componentWillUpdate` + 1. `componentDidUpdate` + 1. `componentWillUnmount` + 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()` + 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()` + 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). From a7d3e02a7744068b211d884c3299841767a23b78 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 22 Dec 2015 22:38:02 -0800 Subject: [PATCH 0114/1318] [readme] Add missing heading to react TOC I noticed that this heading wasn't listed in the table of contents. Adding it will help people see at-a-glance what they might find in this document. --- react/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/react/README.md b/react/README.md index 12260155b9..d6f858e10a 100644 --- a/react/README.md +++ b/react/README.md @@ -5,6 +5,7 @@ ## Table of Contents 1. [Basic Rules](#basic-rules) + 1. [Class vs `React.createClass`](#class-vs-reactcreateclass) 1. [Naming](#naming) 1. [Declaration](#declaration) 1. [Alignment](#alignment) From 474087c4269a534d9b57b1bc8e323a4295f0b429 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 22 Dec 2015 22:40:43 -0800 Subject: [PATCH 0115/1318] [readme] Use consistent whitespace in react readme I noticed that some newlines and indentation were a little inconsistent in this file, so I decided to smooth things out a bit. This should help people who decide to modify this document in the future. When determining which is the "right" way to format these things, I decided to use the style used by base readme as a guide. --- react/README.md | 85 ++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/react/README.md b/react/README.md index d6f858e10a..48a50b8378 100644 --- a/react/README.md +++ b/react/README.md @@ -30,21 +30,21 @@ 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
; - } - }); + ```javascript + // bad + const Listing = React.createClass({ + render() { + return
; + } + }); - // good - class Listing extends React.Component { - render() { - return
; + // good + class Listing extends React.Component { + render() { + return
; + } } - } - ``` + ``` ## Naming @@ -52,7 +52,7 @@ - **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). + eslint rules: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md). ```javascript // bad @@ -68,7 +68,8 @@ const reservationItem = ; ``` - **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: + **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 // bad const Footer = require('./Footer/Footer.jsx') @@ -80,8 +81,8 @@ const Footer = require('./Footer') ``` - ## Declaration + - Do not use `displayName` for naming components. Instead, name the component by reference. ```javascript @@ -97,6 +98,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). @@ -125,6 +127,7 @@ ``` ## Quotes + - Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. > 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. @@ -147,7 +150,9 @@ ``` ## Spacing + - Always include a single space in your self-closing tag. + ```javascript // bad @@ -164,7 +169,9 @@ ``` ## Props + - Always use camelCase for prop names. + ```javascript // bad {this.props.text} + render() { + return {this.props.text} + } } - } - Link.propTypes = propTypes; - Link.defaultProps = defaultProps; + Link.propTypes = propTypes; + Link.defaultProps = defaultProps; - export default Link; - ``` + export default Link; + ``` - Ordering for `React.createClass`: From 8989a8a51389562e0440af0546b5b284e0e26bda Mon Sep 17 00:00:00 2001 From: Christopher Banh Date: Wed, 15 Jul 2015 09:17:04 -0700 Subject: [PATCH 0116/1318] Rename jshintrc to .jshintrc According to http://jshint.com/docs/, the "special file" to configure JSHint is named `.jshintrc`, not `jshintrc`. --- linters/{jshintrc => .jshintrc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename linters/{jshintrc => .jshintrc} (100%) diff --git a/linters/jshintrc b/linters/.jshintrc similarity index 100% rename from linters/jshintrc rename to linters/.jshintrc From 5c3137d7364b65c9e3300682dd53a68fd595bda2 Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Sun, 13 Dec 2015 18:36:25 -0800 Subject: [PATCH 0117/1318] Cleaning up the react styleguide. Adding additional info in props. --- packages/eslint-config-airbnb/rules/react.js | 3 + react/README.md | 115 +++++++++++++++++-- 2 files changed, 109 insertions(+), 9 deletions(-) diff --git a/packages/eslint-config-airbnb/rules/react.js b/packages/eslint-config-airbnb/rules/react.js index 758f4e65f4..7f69354521 100644 --- a/packages/eslint-config-airbnb/rules/react.js +++ b/packages/eslint-config-airbnb/rules/react.js @@ -21,6 +21,9 @@ module.exports = { // Validate props indentation in JSX // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md 'react/jsx-indent-props': [2, 2], + // 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, diff --git a/react/README.md b/react/README.md index 48a50b8378..052949876c 100644 --- a/react/README.md +++ b/react/README.md @@ -56,10 +56,10 @@ ```javascript // bad - const reservationCard = require('./ReservationCard'); + import reservationCard from './ReservationCard'; // good - const ReservationCard = require('./ReservationCard'); + import ReservationCard from './ReservationCard'; // bad const ReservationItem = ; @@ -72,13 +72,13 @@ ```javascript // bad - const Footer = require('./Footer/Footer.jsx') + import Footer from './Footer/Footer.jsx'; // bad - const Footer = require('./Footer/index.jsx') + import Footer from './Footer/index.jsx'; // good - const Footer = require('./Footer') + import Footer from './Footer'; ``` ## Declaration @@ -186,6 +186,22 @@ /> ``` + - 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). + + ```javascript + // bad +