From 2f376e0f379f6e55c7423bd3b268729dde757bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Zl=C3=A1mal?= Date: Tue, 6 Apr 2021 09:07:27 -0500 Subject: [PATCH] [Fix] `forbid-dom-props`: support `JSXNamespacedName` This rather strange pattern is common in [FBT](https://facebook.github.io/fbt/docs/params) and valid according to [JSX](http://facebook.github.io/jsx/) (see `JSXNamespacedName`). Without this change the rule fails on the following error: ``` TypeError: Cannot read property 'toUpperCase' of undefined ``` See: https://github.com/adeira/universe/issues/2005 --- CHANGELOG.md | 2 ++ lib/rules/forbid-dom-props.js | 4 ++-- tests/lib/rules/forbid-dom-props.js | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4bb6c35cf..06a43334a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,12 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Fixed * [`jsx-max-depth`]: Prevent getting stuck in circular references ([#2957][] @AriPerkkio) * [`jsx-no-target-blank`]: fix handling of `warnOnSpreadAttributes` being false ([#2953][] @Nokel81) +* [`forbid-dom-props`]: support `JSXNamespacedName` [#2961][] @mrtnzlml) ### Changed * Fix CHANGELOG.md ([#2950][] @JounQin) +[#2961]: https://github.com/yannickcr/eslint-plugin-react/pull/2961 [#2953]: https://github.com/yannickcr/eslint-plugin-react/pull/2953 [#2957]: https://github.com/yannickcr/eslint-plugin-react/pull/2957 [#2950]: https://github.com/yannickcr/eslint-plugin-react/pull/2950 diff --git a/lib/rules/forbid-dom-props.js b/lib/rules/forbid-dom-props.js index af4b0c2516..fd125b1bfa 100644 --- a/lib/rules/forbid-dom-props.js +++ b/lib/rules/forbid-dom-props.js @@ -75,8 +75,8 @@ module.exports = { return { JSXAttribute(node) { const tag = node.parent.name.name; - if (!(tag && tag[0] !== tag[0].toUpperCase())) { - // This is a Component, not a DOM node, so exit. + if (!(tag && typeof tag === 'string' && tag[0] !== tag[0].toUpperCase())) { + // This is a Component, not a DOM node, so exit. return; } diff --git a/tests/lib/rules/forbid-dom-props.js b/tests/lib/rules/forbid-dom-props.js index c76d788471..3144fbd698 100644 --- a/tests/lib/rules/forbid-dom-props.js +++ b/tests/lib/rules/forbid-dom-props.js @@ -71,6 +71,13 @@ ruleTester.run('forbid-element-props', rule, { ');' ].join('\n'), options: [{forbid: ['id']}] + }, { + code: [ + 'const First = (props) => (', + ' {props.name}', + ');' + ].join('\n'), + options: [{forbid: ['id']}] }, { code: [ 'const First = (props) => (',