diff --git a/lib/rules/jsx-no-literals.js b/lib/rules/jsx-no-literals.js index bebddb067a..95d5412cb5 100644 --- a/lib/rules/jsx-no-literals.js +++ b/lib/rules/jsx-no-literals.js @@ -26,6 +26,9 @@ module.exports = { properties: { noStrings: { type: 'boolean' + }, + allowedStrings: { + type: 'array' } }, additionalProperties: false @@ -34,6 +37,7 @@ module.exports = { create(context) { const isNoStrings = context.options[0] ? context.options[0].noStrings : false; + const allowedStrings = context.options[0] ? context.options[0].allowedStrings : false; const message = isNoStrings ? 'Strings not allowed in JSX files' : @@ -55,6 +59,9 @@ module.exports = { } function getValidation(node) { + if (allowedStrings && allowedStrings.indexOf(node.value) > -1) { + return false; + } const parent = getParentIgnoringBinaryExpressions(node); const standard = !/^[\s]+$/.test(node.value) && typeof node.value === 'string' && diff --git a/tests/lib/rules/jsx-no-literals.js b/tests/lib/rules/jsx-no-literals.js index bd622123f0..150d1c71e1 100644 --- a/tests/lib/rules/jsx-no-literals.js +++ b/tests/lib/rules/jsx-no-literals.js @@ -198,8 +198,36 @@ ruleTester.run('jsx-no-literals', rule, { } `, options: [{noStrings: true}] + }, { + code: ` + class Comp1 extends Component { + render() { + return