Skip to content

Commit

Permalink
[Fix] no-namespace: fix crash on non-string React.createElement name
Browse files Browse the repository at this point in the history
Fixes #3082
  • Loading branch information
ljharb committed Sep 23, 2021
1 parent eeb0144 commit a4bf7da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## Unreleased

### Fixed
* [`no-namespace`]: fix crash on non-string React.createElement name ([#3082] @ljharb)

[#3082]: https://github.com/yannickcr/eslint-plugin-react/pull/3082

## [7.26.0] - 2021.09.20

### Added
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
CallExpression(node) {
if (isCreateElement(node, context) && node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
const name = node.arguments[0].value;
if (name.indexOf(':') === -1) return undefined;
if (!name || name.indexOf(':') === -1) return undefined;
report(context, messages.noNamespace, 'noNamespace', {
node,
data: {
Expand All @@ -51,7 +51,7 @@ module.exports = {
},
JSXOpeningElement(node) {
const name = elementType(node);
if (name.indexOf(':') === -1) return undefined;
if (!name || name.indexOf(':') === -1) return undefined;
report(context, messages.noNamespace, 'noNamespace', {
node,
data: {
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/no-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ ruleTester.run('no-namespace', rule, {
code: '<Object.TestComponent />'
}, {
code: 'React.createElement("Object.TestComponent")'
}, {
code: 'React.createElement(null)'
}],

invalid: [{
Expand Down

0 comments on commit a4bf7da

Please sign in to comment.