Skip to content

Commit 6bf1509

Browse files
committed
feat: support React Strict Dom elements (html.div, etc)
1 parent f2869fd commit 6bf1509

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/rules/forbid-dom-props.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,12 @@ module.exports = {
9696

9797
return {
9898
JSXAttribute(node) {
99-
const tag = node.parent.name.name;
100-
if (!(tag && typeof tag === 'string' && tag[0] !== tag[0].toUpperCase())) {
101-
// This is a Component, not a DOM node, so exit.
99+
const parentName = node.parent.name;
100+
// Extract a component name when using a "namespace", e.g. `<htmo.div />`.
101+
const tag = parentName.name || `${parentName.object.name}.${parentName.property.name}`;
102+
const componentName = parentName.name || parentName.property.name;
103+
const isDomNode = componentName && typeof componentName[0] === 'string' && componentName[0] !== componentName[0].toUpperCase();
104+
if (!isDomNode) {
102105
return;
103106
}
104107

tests/lib/rules/forbid-dom-props.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,5 +324,22 @@ ruleTester.run('forbid-dom-props', rule, {
324324
},
325325
],
326326
},
327+
{
328+
code: `
329+
const First = (props) => (
330+
<html.div id="foo" />
331+
);
332+
`,
333+
options: [{ forbid: ['id'] }],
334+
errors: [
335+
{
336+
messageId: 'propIsForbidden',
337+
data: { prop: 'id' },
338+
line: 3,
339+
column: 16,
340+
type: 'JSXAttribute',
341+
},
342+
],
343+
},
327344
]),
328345
});

0 commit comments

Comments
 (0)