Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark deprecated rules as deprecated in their metadata #911

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like the react/ prefix won't actually be there for the deprecated rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe it needs to be. It wasn't before - deprecatedRules was defined directly as:

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')
};

The react/ prefix is only needed for activeRulesConfig, because those are used to define the all configuration, whereas rules and deprecatedRules both use the un-prefixed names.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems odd to me but I believe you that the behavior won't be changed by this PR - so while I think all the exported rule name should have the prefix, that clearly is out of scope of this PR. Thanks for clarifying!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the relevant code from ESLint (from https://github.com/eslint/eslint/blob/master/lib/rules.js#L54-L63):

function importPlugin(plugin, pluginName) {
    if (plugin.rules) {
        Object.keys(plugin.rules).forEach(function(ruleId) {
            const qualifiedRuleId = `${pluginName}/${ruleId}`,
                rule = plugin.rules[ruleId];

            define(qualifiedRuleId, rule);
        });
    }
}

You can see that it takes the responsibility of prefixing the plugin name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, that's a good point. thanks

});

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
}
}
};