eslint-plugin-i18next
Advanced tools
Comparing version 5.1.1 to 5.1.2
@@ -5,2 +5,4 @@ # Changelog | ||
### 5.1.2 (2021-09-12) | ||
### [5.1.1](https://github.com/edvardchen/eslint-plugin-i18next/compare/v5.1.0...v5.1.1) (2021-04-08) | ||
@@ -7,0 +9,0 @@ |
@@ -215,27 +215,2 @@ /** | ||
// | ||
// TYPESCRIPT | ||
// | ||
if (typeChecker) { | ||
const tsNode = esTreeNodeToTSNodeMap.get(node); | ||
const typeObj = typeChecker.getTypeAtLocation(tsNode.parent); | ||
// var a: 'abc' = 'abc' | ||
if (typeObj.isStringLiteral()) { | ||
return; | ||
} | ||
// var a: 'abc' | 'name' = 'abc' | ||
if (typeObj.isUnion()) { | ||
const found = typeObj.types.some(item => { | ||
if (item.isStringLiteral() && item.value === node.value) { | ||
return true; | ||
} | ||
}); | ||
if (found) return; | ||
} | ||
} | ||
// • • • • • | ||
context.report({ node, message }); | ||
@@ -400,2 +375,7 @@ } | ||
NewExpression(node) { | ||
indicatorStack.push(isValidFunctionCall(node)); | ||
}, | ||
'NewExpression:exit': endIndicator, | ||
CallExpression(node) { | ||
@@ -402,0 +382,0 @@ indicatorStack.push(isValidFunctionCall(node)); |
{ | ||
"name": "eslint-plugin-i18next", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"description": "ESLint plugin for i18n", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -30,3 +30,3 @@ /** | ||
}); | ||
ruleTester.run('no-literal-string', rule, { | ||
const usual = { | ||
valid: [ | ||
@@ -69,2 +69,10 @@ { code: 'import("hello")' }, | ||
{ | ||
code: 'new Error("hello")', | ||
options: [ | ||
{ | ||
ignoreCallee: ['Error'], | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'foo.bar("taa");', | ||
@@ -89,44 +97,5 @@ options: [ | ||
{ code: 'class Form extends Component { displayName = "FormContainer" };' }, | ||
// JSX | ||
{ code: '<div className="primary"></div>' }, | ||
{ code: '<div className={a ? "active": "inactive"}></div>' }, | ||
{ code: '<div>{i18next.t("foo")}</div>' }, | ||
{ code: '<svg viewBox="0 0 20 40"></svg>' }, | ||
{ code: '<line x1="0" y1="0" x2="10" y2="20" />' }, | ||
{ code: '<path d="M10 10" />' }, | ||
{ | ||
code: | ||
'<circle width="16px" height="16px" cx="10" cy="10" r="2" fill="red" />', | ||
}, | ||
{ | ||
code: | ||
'<a href="https://google.com" target="_blank" rel="noreferrer noopener"></a>', | ||
}, | ||
{ | ||
code: '<div id="some-id" tabIndex="0" aria-labelledby="label-id"></div>', | ||
}, | ||
{ code: '<div role="button"></div>' }, | ||
{ code: '<img src="./image.png" />' }, | ||
{ code: '<A style="bar" />' }, | ||
{ code: '<button type="button" for="form-id" />' }, | ||
{ code: '<DIV foo="bar" />', options: [{ ignoreAttribute: ['foo'] }] }, | ||
{ code: '<Trans>foo</Trans>' }, | ||
{ code: '<Trans><span>bar</span></Trans>' }, | ||
{ code: '<Trans>foo</Trans>', options: [{ ignoreComponent: ['Icon'] }] }, | ||
{ code: '<Icon>arrow</Icon>', options: [{ ignoreComponent: ['Icon'] }] }, | ||
{ code: 'a + "b"', options: [{ markupOnly: true }] }, | ||
{ code: '<div>{import("abc")}</div>', options: [{ markupOnly: true }] }, | ||
{ | ||
code: '<div>{[].map(item=>"abc")}</div>', | ||
options: [{ markupOnly: true }], | ||
}, | ||
{ code: '<div>{"hello" + "world"}</div>', options: [{ markupOnly: true }] }, | ||
{ code: '<DIV foo="FOO" />', options: [{ markupOnly: true }] }, | ||
{ | ||
code: '<DIV foo="bar" />', | ||
options: [{ markupOnly: true, ignoreAttribute: ['foo'] }], | ||
}, | ||
// when onlyAttribute was configured, the markOnly would be treated as true | ||
{ code: 'const a = "foo";', options: [{ onlyAttribute: ['bar'] }] }, | ||
{ code: '<DIV foo="bar" />', options: [{ onlyAttribute: ['bar'] }] }, | ||
{ | ||
@@ -176,3 +145,47 @@ code: 'var a = `hello world`', | ||
}, | ||
// JSX | ||
], | ||
}; | ||
const jsx = { | ||
valid: [ | ||
{ code: '<div className="primary"></div>' }, | ||
{ code: '<div className={a ? "active": "inactive"}></div>' }, | ||
{ code: '<div>{i18next.t("foo")}</div>' }, | ||
{ code: '<svg viewBox="0 0 20 40"></svg>' }, | ||
{ code: '<line x1="0" y1="0" x2="10" y2="20" />' }, | ||
{ code: '<path d="M10 10" />' }, | ||
{ | ||
code: | ||
'<circle width="16px" height="16px" cx="10" cy="10" r="2" fill="red" />', | ||
}, | ||
{ | ||
code: | ||
'<a href="https://google.com" target="_blank" rel="noreferrer noopener"></a>', | ||
}, | ||
{ | ||
code: '<div id="some-id" tabIndex="0" aria-labelledby="label-id"></div>', | ||
}, | ||
{ code: '<div role="button"></div>' }, | ||
{ code: '<img src="./image.png" />' }, | ||
{ code: '<A style="bar" />' }, | ||
{ code: '<button type="button" for="form-id" />' }, | ||
{ code: '<DIV foo="bar" />', options: [{ ignoreAttribute: ['foo'] }] }, | ||
{ code: '<Trans>foo</Trans>' }, | ||
{ code: '<Trans><span>bar</span></Trans>' }, | ||
{ code: '<Trans>foo</Trans>', options: [{ ignoreComponent: ['Icon'] }] }, | ||
{ code: '<Icon>arrow</Icon>', options: [{ ignoreComponent: ['Icon'] }] }, | ||
{ code: '<div>{import("abc")}</div>', options: [{ markupOnly: true }] }, | ||
{ | ||
code: '<div>{[].map(item=>"abc")}</div>', | ||
options: [{ markupOnly: true }], | ||
}, | ||
{ code: '<div>{"hello" + "world"}</div>', options: [{ markupOnly: true }] }, | ||
{ code: '<DIV foo="FOO" />', options: [{ markupOnly: true }] }, | ||
{ | ||
code: '<DIV foo="bar" />', | ||
options: [{ markupOnly: true, ignoreAttribute: ['foo'] }], | ||
}, | ||
{ code: '<DIV foo="bar" />', options: [{ onlyAttribute: ['bar'] }] }, | ||
], | ||
invalid: [ | ||
{ code: '<div>foo</div>', errors }, | ||
@@ -194,3 +207,5 @@ { code: '<div>foo</div>', options: [{ markupOnly: true }], errors }, | ||
], | ||
}); | ||
}; | ||
ruleTester.run('no-literal-string', rule, usual); | ||
ruleTester.run('no-literal-string', rule, jsx); | ||
@@ -239,2 +254,18 @@ // | ||
tsTester.run('no-literal-string', rule, usual); | ||
tsTester.run( | ||
'no-literal-string', | ||
rule, | ||
Object.entries(jsx).reduce( | ||
(prev, [key, value]) => ({ | ||
...prev, | ||
[key]: value.map(item => ({ | ||
...item, | ||
filename: 'a.jsx', | ||
})), | ||
}), | ||
{} | ||
) | ||
); | ||
tsTester.run('no-literal-string', rule, { | ||
@@ -246,5 +277,3 @@ valid: [ | ||
{ code: "var a: Omit<T, 'af'>" }, | ||
{ code: `var a: 'abc' = 'abc'` }, | ||
{ code: `var a: 'abc' | 'name' | undefined= 'abc'` }, | ||
{ code: "type T = {name: 'b'} ; var a: T = {name: 'b'}" }, | ||
{ code: "function Button({ t= 'name' }: {t: string}){} " }, | ||
{ code: "enum T {howard=1, 'a b'=2} ; var a = T['howard']" }, | ||
@@ -251,0 +280,0 @@ { code: "function Button({ t= 'name' }: {t: 'name'}){} " }, |
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
52783
13
978