eslint-plugin-i18next
Advanced tools
Comparing version 4.4.0 to 4.5.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [4.5.0](https://github.com/edvardchen/eslint-plugin-i18next/compare/v4.4.0...v4.5.0) (2020-08-11) | ||
### Features | ||
* add option validateTemplate ([ba0ec60](https://github.com/edvardchen/eslint-plugin-i18next/commit/ba0ec60)) | ||
## [4.4.0](https://github.com/edvardchen/eslint-plugin-i18next/compare/v4.3.0...v4.4.0) (2020-08-03) | ||
@@ -7,0 +14,0 @@ |
@@ -62,2 +62,5 @@ /** | ||
} | ||
}, | ||
validateTemplate: { | ||
type: 'boolean' | ||
} | ||
@@ -401,2 +404,17 @@ }, | ||
TemplateLiteral(node) { | ||
if (!option || !option.validateTemplate) { | ||
return; | ||
} | ||
const { quasis = [] } = node; | ||
quasis.some(({ value: { raw } }) => { | ||
const trimed = raw.trim(); | ||
if (!trimed) return; | ||
if (match(trimed)) return; | ||
context.report({ node, message }); | ||
return true; // break | ||
}); | ||
// const trimed = node.value.trim(); | ||
}, | ||
'Literal:exit'(node) { | ||
@@ -414,4 +432,7 @@ if (markupOnly) { | ||
scriptVisitor[key] = node => { | ||
// make sure node is string literal | ||
if (!isString(node)) return; | ||
// all visitors ends with Literal except TemplateLiteral | ||
if (key !== 'TemplateLiteral') { | ||
// make sure node is string literal | ||
if (!isString(node)) return; | ||
} | ||
@@ -418,0 +439,0 @@ old(node); |
{ | ||
"name": "eslint-plugin-i18next", | ||
"version": "4.4.0", | ||
"version": "4.5.0", | ||
"description": "ESLint plugin for i18n", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -346,1 +346,11 @@ # eslint-plugin-i18next | ||
``` | ||
#### validateTemplate | ||
Indicate whether to validate [template strings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) or not. Default `false` | ||
```js | ||
/*eslint i18next/no-literal-string: ["error", { "validateTemplate": true }]*/ | ||
// incorrect | ||
var foo = `hello world`; | ||
``` |
@@ -124,6 +124,27 @@ /** | ||
{ code: 'const a = "foo";', options: [{ onlyAttribute: ['bar'] }] }, | ||
{ code: '<DIV foo="bar" />', options: [{ onlyAttribute: ['bar'] }] } | ||
{ code: '<DIV foo="bar" />', options: [{ onlyAttribute: ['bar'] }] }, | ||
{ | ||
code: 'var a = `hello world`' | ||
}, | ||
{ | ||
code: 'var a = `12345`', | ||
options: [{ validateTemplate: true }] | ||
}, | ||
{ | ||
code: 'var a = ``', | ||
options: [{ validateTemplate: true }] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: 'var a = `hello ${abc} world`', | ||
options: [{ validateTemplate: true }], | ||
errors | ||
}, | ||
{ | ||
code: 'var a = `hello world`', | ||
options: [{ validateTemplate: true }], | ||
errors | ||
}, | ||
{ code: 'i18nextXt("taa");', errors }, | ||
@@ -130,0 +151,0 @@ { code: 'a + "b"', errors }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49947
944
356