Make valid-i18n-keys rule strict and fix most exceptions

This commit is contained in:
Jamie Kyle
2023-03-29 10:15:54 -07:00
committed by GitHub
parent 18a6da310f
commit 11cfcb4e32
36 changed files with 796 additions and 687 deletions

View File

@@ -27,27 +27,68 @@ ruleTester.run('valid-i18n-keys', rule, {
options: [{ messagesCacheKey }],
},
{
code: 'i18n(`AddCaptionModal__${title}`)',
code: `window.i18n("AddCaptionModal__title")`,
options: [{ messagesCacheKey }],
},
{
code: `let jsx = <Intl id="AddCaptionModal__title"/>`,
options: [{ messagesCacheKey }],
},
],
invalid: [
{
code: 'i18n(`AddCaptionModal__${title}`)',
options: [{ messagesCacheKey }],
errors: [
{
message: "i18n()'s first argument should always be a literal string",
type: 'CallExpression',
},
],
},
{
code: 'window.i18n(`AddCaptionModal__${title}`)',
options: [{ messagesCacheKey }],
errors: [
{
message: "i18n()'s first argument should always be a literal string",
type: 'CallExpression',
},
],
},
{
code: `let jsx = <Intl id={"AddCaptionModal__title"}/>`,
options: [{ messagesCacheKey }],
errors: [
{
message:
"<Intl> must always be provided an 'id' attribute with a literal string",
type: 'JSXOpeningElement',
},
],
},
{
code: 'let jsx = <Intl id={`AddCaptionModal__title`}/>',
options: [{ messagesCacheKey }],
errors: [
{
message:
"<Intl> must always be provided an 'id' attribute with a literal string",
type: 'JSXOpeningElement',
},
],
},
{
code: 'let jsx = <Intl id={`AddCaptionModal__${title}`}/>',
options: [{ messagesCacheKey }],
errors: [
{
message:
"<Intl> must always be provided an 'id' attribute with a literal string",
type: 'JSXOpeningElement',
},
],
},
],
invalid: [
{
code: `i18n("THIS_KEY_SHOULD_NEVER_EXIST")`,
options: [{ messagesCacheKey }],