From d64eb863b9414574efb34a312a869a0a4268807a Mon Sep 17 00:00:00 2001 From: Randy Coulman Date: Fri, 14 Oct 2016 11:53:06 -0700 Subject: [PATCH 1/2] Mark deprecated rules as deprecated in their metadata --- lib/rules/no-comment-textnodes.js | 1 + lib/rules/require-extension.js | 1 + lib/rules/wrap-multilines.js | 1 + tests/index.js | 14 ++++++++++++++ 4 files changed, 17 insertions(+) diff --git a/lib/rules/no-comment-textnodes.js b/lib/rules/no-comment-textnodes.js index 92e7f48259..83ae7450e8 100644 --- a/lib/rules/no-comment-textnodes.js +++ b/lib/rules/no-comment-textnodes.js @@ -15,6 +15,7 @@ var isWarnedForDeprecation = false; module.exports = { meta: { + deprecated: true, docs: { description: 'Comments inside children section of tag should be placed inside braces', category: 'Possible Errors', diff --git a/lib/rules/require-extension.js b/lib/rules/require-extension.js index 1a8a2ed2a7..273d356363 100644 --- a/lib/rules/require-extension.js +++ b/lib/rules/require-extension.js @@ -24,6 +24,7 @@ var PKG_REGEX = /^[^\.]((?!\/).)*$/; module.exports = { meta: { + deprecated: true, docs: { description: 'Restrict file extensions that may be required', category: 'Stylistic Issues', diff --git a/lib/rules/wrap-multilines.js b/lib/rules/wrap-multilines.js index 2b6900eedd..439acbbe82 100644 --- a/lib/rules/wrap-multilines.js +++ b/lib/rules/wrap-multilines.js @@ -15,6 +15,7 @@ var isWarnedForDeprecation = false; module.exports = { meta: { + deprecated: true, docs: { description: 'Prevent missing parentheses around multilines JSX', category: 'Stylistic Issues', diff --git a/tests/index.js b/tests/index.js index a85b4cb6f2..8e058037d2 100644 --- a/tests/index.js +++ b/tests/index.js @@ -23,6 +23,20 @@ describe('all rule files should be exported by the plugin', function() { }); }); +describe('deprecated rules', function() { + it('marks all deprecated rules as deprecated', function() { + ruleFiles.forEach(function(ruleName) { + var inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]); + var isDeprecated = plugin.rules[ruleName].meta.deprecated; + if (inDeprecatedRules) { + assert(isDeprecated, ruleName + ' metadata should mark it as deprecated'); + } else { + assert(!isDeprecated, ruleName + ' metadata should not mark it as deprecated'); + } + }); + }); +}); + describe('configurations', function() { it('should export a \'recommended\' configuration', function() { assert(plugin.configs.recommended); From 33aa4d5d3261ec05a8776a2280de0c845a9e4eab Mon Sep 17 00:00:00 2001 From: Randy Coulman Date: Fri, 14 Oct 2016 17:56:31 -0700 Subject: [PATCH 2/2] Compute deprecatedRules from deprecated meta property * Refactor the creation of the top-level module exports. `rules` becomes `allRules` and includes the deprecated rules. * `deprecatedRules` is now computed using the new `meta.deprecated` property. * The `all` config needs to filter out the deprecated rules. * Extracted some utility functions to remove duplication. --- index.js | 57 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 6bc2671339..b9d6aa45bc 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,6 @@ 'use strict'; -var deprecatedRules = { - 'no-comment-textnodes': require('./lib/rules/no-comment-textnodes'), - 'require-extension': require('./lib/rules/require-extension'), - 'wrap-multilines': require('./lib/rules/wrap-multilines') -}; - -var rules = { +var allRules = { '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'), @@ -58,32 +52,45 @@ var rules = { 'no-danger-with-children': require('./lib/rules/no-danger-with-children'), 'style-prop-object': require('./lib/rules/style-prop-object'), 'no-unused-prop-types': require('./lib/rules/no-unused-prop-types'), - 'no-children-prop': require('./lib/rules/no-children-prop') + 'no-children-prop': require('./lib/rules/no-children-prop'), + 'no-comment-textnodes': require('./lib/rules/no-comment-textnodes'), + 'require-extension': require('./lib/rules/require-extension'), + 'wrap-multilines': require('./lib/rules/wrap-multilines') }; -var ruleNames = Object.keys(rules); -var allRules = {}; -for (var i = 0; i < ruleNames.length; i++) { - allRules['react/' + ruleNames[i]] = 2; -} - -var exportedRules = {}; -for (var key in rules) { - if (!rules.hasOwnProperty(key)) { - continue; +function filterRules(rules, predicate) { + var result = {}; + for (var key in rules) { + if (rules.hasOwnProperty(key) && predicate(rules[key])) { + result[key] = rules[key]; + } } - exportedRules[key] = rules[key]; + return result; } -for (var deprecatedKey in deprecatedRules) { - if (!deprecatedRules.hasOwnProperty(deprecatedKey)) { - continue; + +function configureAsError(rules) { + var result = {}; + for (var key in rules) { + if (!rules.hasOwnProperty(key)) { + continue; + } + result['react/' + key] = 2; } - exportedRules[deprecatedKey] = deprecatedRules[deprecatedKey]; + return result; } +var activeRules = filterRules(allRules, function(rule) { + return !rule.meta.deprecated; +}); +var activeRulesConfig = configureAsError(activeRules); + +var deprecatedRules = filterRules(allRules, function(rule) { + return rule.meta.deprecated; +}); + module.exports = { deprecatedRules: deprecatedRules, - rules: exportedRules, + rules: allRules, configs: { recommended: { parserOptions: { @@ -114,7 +121,7 @@ module.exports = { jsx: true } }, - rules: allRules + rules: activeRulesConfig } } };