Skip to content

Commit

Permalink
[Fix] jsx-no-literals: Avoid crashing on valueless boolean props
Browse files Browse the repository at this point in the history
b8217ed removed the node.value check
leading to this crashing on any valueless boolean prop such as
<Component isWhatever />

This just readds the check.
  • Loading branch information
reosarevok authored and ljharb committed Sep 12, 2024
1 parent a09083b commit 99e15e1
Show file tree
Hide file tree
Showing 2 changed files with 4 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,7 +8,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

### Fixed
* [`no-is-mounted`]: fix logic in method name check ([#3821][] @Mathias-S)
* [`jsx-no-literals`]: Avoid crashing on valueless boolean props ([#3823][] @reosarevok)

[#3823]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3823
[#3821]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3821

## [7.36.0] - 2024.09.12
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/jsx-no-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ module.exports = {
},

JSXAttribute(node) {
const isLiteralString = node.value.type === 'Literal'
const isLiteralString = node.value && node.value.type === 'Literal'
&& typeof node.value.value === 'string';
const isStringLiteral = node.value.type === 'StringLiteral';
const isStringLiteral = node.value && node.value.type === 'StringLiteral';

if (isLiteralString || isStringLiteral) {
const resolvedConfig = getOverrideConfig(node) || config;
Expand Down

0 comments on commit 99e15e1

Please sign in to comment.