Skip to content

Commit

Permalink
[Fix] forbid-dom-props: support JSXNamespacedName
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrtnzlml authored and ljharb committed Apr 6, 2021
1 parent 6b6a14a commit 2f376e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/forbid-dom-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/forbid-dom-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ ruleTester.run('forbid-element-props', rule, {
');'
].join('\n'),
options: [{forbid: ['id']}]
}, {
code: [
'const First = (props) => (',
' <fbt:param name="name">{props.name}</fbt:param>',
');'
].join('\n'),
options: [{forbid: ['id']}]
}, {
code: [
'const First = (props) => (',
Expand Down

0 comments on commit 2f376e0

Please sign in to comment.