diff --git a/lib/rules/jsx-no-literals.js b/lib/rules/jsx-no-literals.js index 9ae90d8daf..c74ab82487 100644 --- a/lib/rules/jsx-no-literals.js +++ b/lib/rules/jsx-no-literals.js @@ -120,7 +120,7 @@ module.exports = { }, JSXAttribute(node) { - const isNodeValueString = node.value && node.value && node.value.type === 'Literal' && typeof node.value.value === 'string'; + const isNodeValueString = node && node.value && node.value.type === 'Literal' && typeof node.value.value === 'string' && !config.allowedStrings.has(node.value.value); if (config.noStrings && !config.ignoreProps && isNodeValueString) { const customMessage = 'Invalid prop value'; diff --git a/tests/lib/rules/jsx-no-literals.js b/tests/lib/rules/jsx-no-literals.js index c8851b2e24..c06eec5994 100644 --- a/tests/lib/rules/jsx-no-literals.js +++ b/tests/lib/rules/jsx-no-literals.js @@ -42,8 +42,63 @@ function invalidProp(str) { const ruleTester = new RuleTester({parserOptions}); ruleTester.run('jsx-no-literals', rule, { - valid: [ + valid: [].concat( { + code: ` + class Comp1 extends Component { + render() { + return ( +