Skip to content

Commit

Permalink
Compute deprecatedRules from deprecated meta property
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
randycoulman committed Oct 15, 2016
1 parent d64eb86 commit 33aa4d5
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -114,7 +121,7 @@ module.exports = {
jsx: true
}
},
rules: allRules
rules: activeRulesConfig
}
}
};

0 comments on commit 33aa4d5

Please sign in to comment.