diff --git a/lib/rules/no-literal-string.js b/lib/rules/no-literal-string.js index 3f1de43..f5892c7 100644 --- a/lib/rules/no-literal-string.js +++ b/lib/rules/no-literal-string.js @@ -347,6 +347,12 @@ module.exports = { if (isUpperCase(node.parent.id.name)) visited.add(node); }, + 'VariableDeclarator > ArrayExpression > Literal'(node) { + // allow statements like const A_B = ["test"] + const declarator = getNearestAncestor(node, 'VariableDeclarator'); + if (isUpperCase(declarator.id.name)) visited.add(node); + }, + 'Property > Literal'(node) { const { parent } = node; // if node is key of property, skip diff --git a/tests/lib/rules/no-literal-string.js b/tests/lib/rules/no-literal-string.js index 144357c..9288526 100644 --- a/tests/lib/rules/no-literal-string.js +++ b/tests/lib/rules/no-literal-string.js @@ -73,6 +73,7 @@ ruleTester.run('no-literal-string', rule, { }, { code: 'const a = "FOO";' }, { code: 'var A_B = "world";' }, + { code: 'var A_B = ["world"];' }, { code: 'var a = {["A_B"]: "hello world"};' }, { code: 'var a = {[A_B]: "hello world"};' }, { code: 'var a = {A_B: "hello world"};' },