Skip to content

Commit

Permalink
[Fix] forbid-elements: prevent a crash on createElement()
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 3, 2024
1 parent e880213 commit 83a26dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`no-unknown-property`]: use a better regex to avoid a crash ([#3666][] @ljharb @SCH227)
* [`prop-types`]: handle nested forwardRef + memo ([#3679][] @developer-bandi)
* [`no-unknown-property`]: add `fetchPriority` ([#3697][] @SevereCloud)
* [`forbid-elements`]: prevent a crash on `createElement()` ([#3632][] @ljharb)

### Changed
* [Refactor] `propTypes`: extract type params to var ([#3634][] @HenryBrown0)
Expand Down Expand Up @@ -56,6 +57,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
[#3638]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3638
[#3634]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3634
[#3633]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3633
[#3632]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3632
[#3630]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3630
[#3626]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3626
[#3623]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3623
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ module.exports = {
}

const argument = node.arguments[0];
if (!argument) {
return;
}

const argType = argument.type;

if (argType === 'Identifier' && /^[A-Z_]/.test(argument.name)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ ruleTester.run('forbid-elements', rule, {
code: 'React.createElement(1)',
options: [{ forbid: ['button'] }],
},
{
code: 'React.createElement()',
},
]),

invalid: parsers.all([
Expand Down

0 comments on commit 83a26dd

Please sign in to comment.