From 99e15e131aa483fecc1e64d3bcdf719ddd141361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Thu, 12 Sep 2024 12:39:26 +0200 Subject: [PATCH] [Fix] `jsx-no-literals`: Avoid crashing on valueless boolean props b8217ed5f4104bd18b54f77ea108ec081ebbbd49 removed the node.value check leading to this crashing on any valueless boolean prop such as This just readds the check. --- CHANGELOG.md | 2 ++ lib/rules/jsx-no-literals.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3faa4c5ae..5cd01e2de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rules/jsx-no-literals.js b/lib/rules/jsx-no-literals.js index ab2553d189..1d4a30835f 100644 --- a/lib/rules/jsx-no-literals.js +++ b/lib/rules/jsx-no-literals.js @@ -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;