Skip to content

Commit

Permalink
[New] forbid-component-props: Implemented support for "namespaced" …
Browse files Browse the repository at this point in the history
…components.
  • Loading branch information
monnef committed Aug 24, 2020
1 parent 2588c4d commit 9b31ba8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/forbid-component-props.js
Expand Up @@ -78,7 +78,11 @@ module.exports = {

return {
JSXAttribute(node) {
const tag = node.parent.name.name;
let tag = node.parent.name.name;
if (!tag && node.parent.name.object.name !== 'this') {
// Extract a component name when using a "namespace", e.g. `<AntdLayout.Content />`.
tag = `${node.parent.name.object.name}.${node.parent.name.property.name}`;
}
if (tag && tag[0] !== tag[0].toUpperCase()) {
// This is a DOM node, not a Component, so exit.
return;
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/forbid-component-props.js
Expand Up @@ -104,6 +104,11 @@ ruleTester.run('forbid-component-props', rule, {
options: [{
forbid: [{propName: 'className', allowedFor: ['ReactModal']}]
}]
}, {
code: 'const item = (<AntdLayout.Content className="antdFoo" />);',
options: [{
forbid: [{propName: 'className', allowedFor: ['AntdLayout.Content']}]
}]
}],

invalid: [{
Expand Down

0 comments on commit 9b31ba8

Please sign in to comment.