From 0f66094cb0ec6c7810a874760471812bd31c1e7d Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Mon, 18 Jul 2016 18:19:52 -0700 Subject: [PATCH 1/5] Add in an "all" config Much like eslint:all http://eslint.org/docs/user-guide/configuring#using-eslintall --- index.js | 108 +++++++++++++++++++++++++++---------------------- tests/index.js | 6 +++ 2 files changed, 65 insertions(+), 49 deletions(-) diff --git a/index.js b/index.js index 5abe6595c3..b4632acd0f 100644 --- a/index.js +++ b/index.js @@ -1,55 +1,57 @@ 'use strict'; +var rules = { + 'jsx-uses-react': require('./lib/rules/jsx-uses-react'), + 'no-multi-comp': require('./lib/rules/no-multi-comp'), + 'prop-types': require('./lib/rules/prop-types'), + 'display-name': require('./lib/rules/display-name'), + 'wrap-multilines': require('./lib/rules/wrap-multilines'), + 'self-closing-comp': require('./lib/rules/self-closing-comp'), + 'no-comment-textnodes': require('./lib/rules/no-comment-textnodes'), + 'no-danger': require('./lib/rules/no-danger'), + 'no-set-state': require('./lib/rules/no-set-state'), + 'no-is-mounted': require('./lib/rules/no-is-mounted'), + 'no-deprecated': require('./lib/rules/no-deprecated'), + 'no-did-mount-set-state': require('./lib/rules/no-did-mount-set-state'), + 'no-did-update-set-state': require('./lib/rules/no-did-update-set-state'), + 'no-render-return-value': require('./lib/rules/no-render-return-value'), + 'react-in-jsx-scope': require('./lib/rules/react-in-jsx-scope'), + 'jsx-uses-vars': require('./lib/rules/jsx-uses-vars'), + 'jsx-handler-names': require('./lib/rules/jsx-handler-names'), + 'jsx-pascal-case': require('./lib/rules/jsx-pascal-case'), + 'jsx-no-bind': require('./lib/rules/jsx-no-bind'), + 'jsx-no-undef': require('./lib/rules/jsx-no-undef'), + 'no-unknown-property': require('./lib/rules/no-unknown-property'), + 'jsx-curly-spacing': require('./lib/rules/jsx-curly-spacing'), + 'jsx-equals-spacing': require('./lib/rules/jsx-equals-spacing'), + 'jsx-sort-props': require('./lib/rules/jsx-sort-props'), + 'sort-prop-types': require('./lib/rules/sort-prop-types'), + 'jsx-boolean-value': require('./lib/rules/jsx-boolean-value'), + 'sort-comp': require('./lib/rules/sort-comp'), + 'require-extension': require('./lib/rules/require-extension'), + 'jsx-no-duplicate-props': require('./lib/rules/jsx-no-duplicate-props'), + 'jsx-max-props-per-line': require('./lib/rules/jsx-max-props-per-line'), + 'jsx-no-literals': require('./lib/rules/jsx-no-literals'), + 'jsx-indent-props': require('./lib/rules/jsx-indent-props'), + 'jsx-indent': require('./lib/rules/jsx-indent'), + 'jsx-closing-bracket-location': require('./lib/rules/jsx-closing-bracket-location'), + 'jsx-space-before-closing': require('./lib/rules/jsx-space-before-closing'), + 'no-direct-mutation-state': require('./lib/rules/no-direct-mutation-state'), + 'forbid-prop-types': require('./lib/rules/forbid-prop-types'), + 'prefer-es6-class': require('./lib/rules/prefer-es6-class'), + 'jsx-key': require('./lib/rules/jsx-key'), + 'no-string-refs': require('./lib/rules/no-string-refs'), + 'prefer-stateless-function': require('./lib/rules/prefer-stateless-function'), + 'require-render-return': require('./lib/rules/require-render-return'), + 'jsx-first-prop-new-line': require('./lib/rules/jsx-first-prop-new-line'), + 'jsx-no-target-blank': require('./lib/rules/jsx-no-target-blank'), + 'jsx-filename-extension': require('./lib/rules/jsx-filename-extension'), + 'require-optimization': require('./lib/rules/require-optimization'), + 'no-find-dom-node': require('./lib/rules/no-find-dom-node') +}; + module.exports = { - rules: { - 'jsx-uses-react': require('./lib/rules/jsx-uses-react'), - 'no-multi-comp': require('./lib/rules/no-multi-comp'), - 'prop-types': require('./lib/rules/prop-types'), - 'display-name': require('./lib/rules/display-name'), - 'wrap-multilines': require('./lib/rules/wrap-multilines'), - 'self-closing-comp': require('./lib/rules/self-closing-comp'), - 'no-comment-textnodes': require('./lib/rules/no-comment-textnodes'), - 'no-danger': require('./lib/rules/no-danger'), - 'no-set-state': require('./lib/rules/no-set-state'), - 'no-is-mounted': require('./lib/rules/no-is-mounted'), - 'no-deprecated': require('./lib/rules/no-deprecated'), - 'no-did-mount-set-state': require('./lib/rules/no-did-mount-set-state'), - 'no-did-update-set-state': require('./lib/rules/no-did-update-set-state'), - 'no-render-return-value': require('./lib/rules/no-render-return-value'), - 'react-in-jsx-scope': require('./lib/rules/react-in-jsx-scope'), - 'jsx-uses-vars': require('./lib/rules/jsx-uses-vars'), - 'jsx-handler-names': require('./lib/rules/jsx-handler-names'), - 'jsx-pascal-case': require('./lib/rules/jsx-pascal-case'), - 'jsx-no-bind': require('./lib/rules/jsx-no-bind'), - 'jsx-no-undef': require('./lib/rules/jsx-no-undef'), - 'no-unknown-property': require('./lib/rules/no-unknown-property'), - 'jsx-curly-spacing': require('./lib/rules/jsx-curly-spacing'), - 'jsx-equals-spacing': require('./lib/rules/jsx-equals-spacing'), - 'jsx-sort-props': require('./lib/rules/jsx-sort-props'), - 'sort-prop-types': require('./lib/rules/sort-prop-types'), - 'jsx-boolean-value': require('./lib/rules/jsx-boolean-value'), - 'sort-comp': require('./lib/rules/sort-comp'), - 'require-extension': require('./lib/rules/require-extension'), - 'jsx-no-duplicate-props': require('./lib/rules/jsx-no-duplicate-props'), - 'jsx-max-props-per-line': require('./lib/rules/jsx-max-props-per-line'), - 'jsx-no-literals': require('./lib/rules/jsx-no-literals'), - 'jsx-indent-props': require('./lib/rules/jsx-indent-props'), - 'jsx-indent': require('./lib/rules/jsx-indent'), - 'jsx-closing-bracket-location': require('./lib/rules/jsx-closing-bracket-location'), - 'jsx-space-before-closing': require('./lib/rules/jsx-space-before-closing'), - 'no-direct-mutation-state': require('./lib/rules/no-direct-mutation-state'), - 'forbid-prop-types': require('./lib/rules/forbid-prop-types'), - 'prefer-es6-class': require('./lib/rules/prefer-es6-class'), - 'jsx-key': require('./lib/rules/jsx-key'), - 'no-string-refs': require('./lib/rules/no-string-refs'), - 'prefer-stateless-function': require('./lib/rules/prefer-stateless-function'), - 'require-render-return': require('./lib/rules/require-render-return'), - 'jsx-first-prop-new-line': require('./lib/rules/jsx-first-prop-new-line'), - 'jsx-no-target-blank': require('./lib/rules/jsx-no-target-blank'), - 'jsx-filename-extension': require('./lib/rules/jsx-filename-extension'), - 'require-optimization': require('./lib/rules/require-optimization'), - 'no-find-dom-node': require('./lib/rules/no-find-dom-node') - }, + rules: rules, configs: { recommended: { parserOptions: { @@ -75,6 +77,14 @@ module.exports = { 'react/prop-types': 2, 'react/react-in-jsx-scope': 2 } + }, + all: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + }, + rules: rules } } }; diff --git a/tests/index.js b/tests/index.js index 100c0ee6d2..4ea16dda13 100644 --- a/tests/index.js +++ b/tests/index.js @@ -27,4 +27,10 @@ describe('configurations', function() { it('should export a \'recommended\' configuration', function() { assert(plugin.configs.recommended); }); + it('should export a \'all\' configuration', function() { + assert(plugin.configs.all); + rules.forEach(function(ruleName) { + assert(plugin.configs.all.rules[ruleName]); + }); + }); }); From 6c9d5f38b1059b6b713a9051b8d4eb2195fa3e91 Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Fri, 15 Jul 2016 15:03:05 -0700 Subject: [PATCH 2/5] Fix default config --- index.js | 8 +++++++- tests/index.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b4632acd0f..818ab09c5a 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,12 @@ var rules = { 'no-find-dom-node': require('./lib/rules/no-find-dom-node') }; +var ruleNames = Object.keys(rules); +var allRules = {}; +for (var i = 0; i < ruleNames.length; i++) { + allRules[ruleNames[i]] = 2; +} + module.exports = { rules: rules, configs: { @@ -84,7 +90,7 @@ module.exports = { jsx: true } }, - rules: rules + rules: allRules } } }; diff --git a/tests/index.js b/tests/index.js index 4ea16dda13..de547fbf28 100644 --- a/tests/index.js +++ b/tests/index.js @@ -30,7 +30,7 @@ describe('configurations', function() { it('should export a \'all\' configuration', function() { assert(plugin.configs.all); rules.forEach(function(ruleName) { - assert(plugin.configs.all.rules[ruleName]); + assert.equal(plugin.configs.all.rules[ruleName], 2); }); }); }); From ca4fb024a2f71ef4ef65728d30796f501b53508f Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Fri, 15 Jul 2016 15:13:05 -0700 Subject: [PATCH 3/5] Fix react prefix --- index.js | 2 +- tests/index.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 818ab09c5a..7f0ae1bb73 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ var rules = { var ruleNames = Object.keys(rules); var allRules = {}; for (var i = 0; i < ruleNames.length; i++) { - allRules[ruleNames[i]] = 2; + allRules['react/' + ruleNames[i]] = 2; } module.exports = { diff --git a/tests/index.js b/tests/index.js index de547fbf28..68f9f86cc5 100644 --- a/tests/index.js +++ b/tests/index.js @@ -26,11 +26,17 @@ describe('all rule files should be exported by the plugin', function() { describe('configurations', function() { it('should export a \'recommended\' configuration', function() { assert(plugin.configs.recommended); + Object.keys(plugin.configs.recommended.rules).forEach(function (configName) { + assert.equal(configName.indexOf('react/'), 0); + var ruleName = configName.substring('react/'.length); + assert(plugin.rules[ruleName]); + }); }); it('should export a \'all\' configuration', function() { assert(plugin.configs.all); - rules.forEach(function(ruleName) { - assert.equal(plugin.configs.all.rules[ruleName], 2); + Object.keys(plugin.configs.all.rules).forEach(function(configName) { + assert.equal(configName.indexOf('react/'), 0); + assert.equal(plugin.configs.all.rules[configName], 2); }); }); }); From 897a6b5845f557b77c7e2a390ba3150e748cba67 Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Fri, 15 Jul 2016 17:03:21 -0700 Subject: [PATCH 4/5] Check that all rules are present in `all` --- tests/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/index.js b/tests/index.js index 68f9f86cc5..13c2e6b5d4 100644 --- a/tests/index.js +++ b/tests/index.js @@ -38,5 +38,8 @@ describe('configurations', function() { assert.equal(configName.indexOf('react/'), 0); assert.equal(plugin.configs.all.rules[configName], 2); }); + rules.forEach(function(ruleName) { + assert(plugin.configs.all.rules['react/' + ruleName]); + }); }); }); From 8d3f08ab3005a5fd361ae4b0a83e3aadb9bcf920 Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Sun, 17 Jul 2016 21:27:16 -0700 Subject: [PATCH 5/5] Update README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index e6dc4d09ec..44bb84ab73 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,18 @@ To enable this configuration use the `extends` property in your `.eslintrc` conf } ``` +This plugin also exports an `all` configuration that includes every available rule. +This pairs well with the `eslint:all` rule. + +```js +{ + "plugins": [ + "react" + ], + "extends": ["eslint:all", "plugin:react/all"] +} +``` + See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files. The rules enabled in this configuration are: