Skip to content

Commit

Permalink
feat: skip literal in SwitchCase statement
Browse files Browse the repository at this point in the history
don't affect litreals in its block

fix #2
  • Loading branch information
edvardchen committed Jul 26, 2019
1 parent 600b5fa commit d270343
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ module.exports = {
if (isValidFunctionCall(parent)) visited.add(node);
},

'SwitchCase > Literal'(node) {
visited.add(node);
},

'Literal:exit'(node) {
// visited and passed linting
if (visited.has(node)) return;
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ruleTester.run('no-literal-string', rule, {
valid: [
{ code: 'import("hello")' },
{ code: "name === 'Android' || name === 'iOS'" },
{ code: "switch(a){ case 'a': break; default: break;}" },
{ code: 'import name from "hello";' },
{ code: 'a.indexOf("ios")' },
{ code: 'a.includes("ios")' },
Expand Down Expand Up @@ -61,6 +62,10 @@ ruleTester.run('no-literal-string', rule, {

invalid: [
{ code: 'a + "b"', errors },
{
code: "switch(a){ case 'a': var a ='b'; break; default: break;}",
errors
},
{ code: 'export const a = "hello_string";', errors },
{ code: 'const a = "foo";', errors },
{ code: 'const a = call("Ffo");', errors },
Expand Down

0 comments on commit d270343

Please sign in to comment.