From cf2edd97fe19bbd33af41cf2c67b8f0c66907875 Mon Sep 17 00:00:00 2001 From: David Orr Date: Thu, 13 Jul 2017 15:24:22 -0400 Subject: [PATCH] Fix false positives in no-literals This rule should only check strings. Fixes #1301 --- lib/rules/jsx-no-literals.js | 1 + tests/lib/rules/jsx-no-literals.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/rules/jsx-no-literals.js b/lib/rules/jsx-no-literals.js index 8b17054314..10d2f84822 100644 --- a/lib/rules/jsx-no-literals.js +++ b/lib/rules/jsx-no-literals.js @@ -44,6 +44,7 @@ module.exports = { function getValidation(node) { const standard = !/^[\s]+$/.test(node.value) && + typeof node.value === 'string' && node.parent && node.parent.type.indexOf('JSX') !== -1 && node.parent.type !== 'JSXAttribute'; diff --git a/tests/lib/rules/jsx-no-literals.js b/tests/lib/rules/jsx-no-literals.js index d506d8779e..f7e881b62d 100644 --- a/tests/lib/rules/jsx-no-literals.js +++ b/tests/lib/rules/jsx-no-literals.js @@ -126,6 +126,18 @@ ruleTester.run('jsx-no-literals', rule, { `, parser: 'babel-eslint', options: [{noStrings: true}] + }, { + code: '', + parser: 'babel-eslint', + options: [{noStrings: true}] + }, { + code: '', + parser: 'babel-eslint', + options: [{noStrings: true}] + }, { + code: '', + parser: 'babel-eslint', + options: [{noStrings: true}] }, { code: ` @@ -140,7 +152,17 @@ ruleTester.run('jsx-no-literals', rule, { `, options: [{noStrings: true}] + }, { + code: '', + options: [{noStrings: true}] + }, { + code: '', + options: [{noStrings: true}] + }, { + code: '', + options: [{noStrings: true}] } + ], invalid: [