Skip to content

Commit

Permalink
feat: ignore not-word string
Browse files Browse the repository at this point in the history
  • Loading branch information
edvardchen committed Oct 10, 2019
1 parent 077e682 commit 1752cbe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ module.exports = {
parserServices,
options: [option]
} = context;
const whitelists = ((option && option.ignore) || []).map(
item => new RegExp(item)
);
const whitelists = [
/^[^A-Za-z]+$/, // ignore not-word string
...((option && option.ignore) || [])
].map(item => new RegExp(item));

const calleeWhitelists = generateCalleeWhitelists(option);
const message = 'disallow literal string';
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ ruleTester.run('no-literal-string', rule, {
{ code: 'const a = require(["hello"]);' },
{ code: 'const a = require(["hel" + "lo"]);' },
{ code: 'const a = 1;' },
{ code: 'const a = "?";' },
{ code: `const a = "0123456789!@#$%^&*()_+|~-=\`[]{};':\\",./<>?";` },
{ code: 'i18n("hello");' },
{ code: 'dispatch("hello");' },
{ code: 'store.dispatch("hello");' },
Expand Down

0 comments on commit 1752cbe

Please sign in to comment.