Skip to content

Commit

Permalink
feat: ignore UPPER_CASE arrays
Browse files Browse the repository at this point in the history
closes #12
  • Loading branch information
edvardchen committed Aug 2, 2020
1 parent 0a2ee26 commit 0d7a69a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"};' },
Expand Down

0 comments on commit 0d7a69a

Please sign in to comment.