Skip to content

Commit

Permalink
Update forbid-component-props to new ESLint rule format
Browse files Browse the repository at this point in the history
I updated this via the codemod from eslint-transforms. [I ran into some
errors getting eslint-transforms to run correctly as described][0], but
I was able to find a workaround by running the jscodeshift command
directly.

[0]: eslint/eslint-transforms#2 (comment)

This is a completely automated change.
  • Loading branch information
lencioni committed Jul 28, 2016
1 parent 986e00e commit 7e67c2d
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions lib/rules/forbid-component-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,52 @@ var DEFAULTS = ['className', 'style'];
// Rule Definition
// ------------------------------------------------------------------------------

module.exports = function(context) {
module.exports = {
meta: {
docs: {},

function isForbidden(prop) {
var configuration = context.options[0] || {};
schema: [{
type: 'object',
properties: {
forbid: {
type: 'array',
items: {
type: 'string'
}
}
},
additionalProperties: true
}]
},

var forbid = configuration.forbid || DEFAULTS;
return forbid.indexOf(prop) >= 0;
}
create: function(context) {

return {
JSXAttribute: function(node) {
var tag = node.parent.name.name;
if (tag[0] !== tag[0].toUpperCase()) {
// This is a DOM node, not a Component, so exit.
return;
}
function isForbidden(prop) {
var configuration = context.options[0] || {};

var prop = node.name.name;
var forbid = configuration.forbid || DEFAULTS;
return forbid.indexOf(prop) >= 0;
}

if (!isForbidden(prop)) {
return;
}
return {
JSXAttribute: function(node) {
var tag = node.parent.name.name;
if (tag[0] !== tag[0].toUpperCase()) {
// This is a DOM node, not a Component, so exit.
return;
}

context.report({
node: node,
message: 'Prop `' + prop + '` is forbidden on Components'
});
}
};
};
var prop = node.name.name;

if (!isForbidden(prop)) {
return;
}

module.exports.schema = [{
type: 'object',
properties: {
forbid: {
type: 'array',
items: {
type: 'string'
context.report({
node: node,
message: 'Prop `' + prop + '` is forbidden on Components'
});
}
}
},
additionalProperties: true
}];
};
}
};

0 comments on commit 7e67c2d

Please sign in to comment.