Repository: edvardchen/eslint-plugin-i18next (js)

Issue:
Linter doesn't seem to catch hardcoded strings if using backticks
We've noticed if a hardcoded string is used, but with backticks, the linter doesn't catch it as being a hardcoded string.

e.g.

✅ **Caught**
```<Text>{booleanTest ? "Foo" : "Bar"}</Text>```

❌  **Uncaught**
```<Text>{booleanTest ? `Foo ${bar}` : `Baz ${zip}`}</Text>```

Thanks.

Pull request description:
feat: treat template literals without expressions as normal strings
Fixes #85 

Patch:
diff --git a/lib/rules/no-literal-string.js b/lib/rules/no-literal-string.js
index 6d5c3be..7e25709 100644
--- a/lib/rules/no-literal-string.js
+++ b/lib/rules/no-literal-string.js
@@ -252,7 +252,8 @@ module.exports = {
       },
 
       TemplateLiteral(node) {
-        if (!validateTemplate) {
+        // treat template literals without expressions as normal strings
+        if (node.expressions.length && !validateTemplate) {
           return;
         }
         if (isValidScope()) return;


Test patch:
diff --git a/tests/lib/fixtures/valid.jsx b/tests/lib/fixtures/valid.jsx
index 30cb613..1c44be2 100644
--- a/tests/lib/fixtures/valid.jsx
+++ b/tests/lib/fixtures/valid.jsx
@@ -1,7 +1,7 @@
 import('hello');
 
-// don't validate template by default
-var aa = `hello world`;
+// don't validate template literals with expressions by default
+var aa = `hello world, ${name}`;
 
 function bar(a = 'jianhua') { }
 
diff --git a/tests/lib/rules/no-literal-string/words.js b/tests/lib/rules/no-literal-string/words.js
index 3d08302..5f45518 100644
--- a/tests/lib/rules/no-literal-string/words.js
+++ b/tests/lib/rules/no-literal-string/words.js
@@ -11,6 +11,10 @@ const cases = {
       code: 'const a = "fooabc";',
       options: [{ mode: 'all', words: { exclude: ['^foo.*'] } }],
     },
+    {
+      code: 'const a = `afoo ${abc}`;',
+      options: [{ mode: 'all', words: { exclude: ['^foo'] } }],
+    },
   ],
   invalid: [
     {
@@ -18,6 +22,11 @@ const cases = {
       options: [{ mode: 'all', words: { exclude: ['^foo'] } }],
       errors: 1,
     },
+    {
+      code: 'const a = `afoo`;',
+      options: [{ mode: 'all', words: { exclude: ['^foo'] } }],
+      errors: 1,
+    },
   ],
 };