Skip to content

Commit 2f376e0

Browse files
mrtnzlmlljharb
authored andcommitted
[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: adeira/universe#2005
1 parent 6b6a14a commit 2f376e0

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
88
### Fixed
99
* [`jsx-max-depth`]: Prevent getting stuck in circular references ([#2957][] @AriPerkkio)
1010
* [`jsx-no-target-blank`]: fix handling of `warnOnSpreadAttributes` being false ([#2953][] @Nokel81)
11+
* [`forbid-dom-props`]: support `JSXNamespacedName` [#2961][] @mrtnzlml)
1112

1213
### Changed
1314
* Fix CHANGELOG.md ([#2950][] @JounQin)
1415

16+
[#2961]: https://github.com/yannickcr/eslint-plugin-react/pull/2961
1517
[#2953]: https://github.com/yannickcr/eslint-plugin-react/pull/2953
1618
[#2957]: https://github.com/yannickcr/eslint-plugin-react/pull/2957
1719
[#2950]: https://github.com/yannickcr/eslint-plugin-react/pull/2950

lib/rules/forbid-dom-props.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ module.exports = {
7575
return {
7676
JSXAttribute(node) {
7777
const tag = node.parent.name.name;
78-
if (!(tag && tag[0] !== tag[0].toUpperCase())) {
79-
// This is a Component, not a DOM node, so exit.
78+
if (!(tag && typeof tag === 'string' && tag[0] !== tag[0].toUpperCase())) {
79+
// This is a Component, not a DOM node, so exit.
8080
return;
8181
}
8282

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

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ ruleTester.run('forbid-element-props', rule, {
7171
');'
7272
].join('\n'),
7373
options: [{forbid: ['id']}]
74+
}, {
75+
code: [
76+
'const First = (props) => (',
77+
' <fbt:param name="name">{props.name}</fbt:param>',
78+
');'
79+
].join('\n'),
80+
options: [{forbid: ['id']}]
7481
}, {
7582
code: [
7683
'const First = (props) => (',

0 commit comments

Comments
 (0)