Fully migrate to ICU

This commit is contained in:
Jamie Kyle
2023-03-29 17:03:25 -07:00
committed by GitHub
parent d4e7177ba6
commit 5e647c55d1
274 changed files with 7948 additions and 1944 deletions

View File

@@ -6,6 +6,19 @@ const RuleTester = require('eslint').RuleTester;
const messagesCacheKey = rule.messagesCacheKey;
const __mockMessages__ = {
legacy_real_message: {
message: 'Legacy $message$',
},
'icu:real_message': {
messageformat: 'ICU {message}',
},
'icu:deleted_message': {
messageformat: 'shouldnt use me anymore',
description: '(deleted 01/01/1970)',
},
};
// Need to load so mocha doesn't complain about polluting the global namespace
require('@typescript-eslint/parser');
@@ -23,22 +36,55 @@ const ruleTester = new RuleTester({
ruleTester.run('valid-i18n-keys', rule, {
valid: [
{
code: `i18n("AddCaptionModal__title")`,
options: [{ messagesCacheKey }],
code: `i18n("icu:real_message")`,
options: [{ messagesCacheKey, __mockMessages__ }],
},
{
code: `window.i18n("AddCaptionModal__title")`,
options: [{ messagesCacheKey }],
code: `window.i18n("icu:real_message")`,
options: [{ messagesCacheKey, __mockMessages__ }],
},
{
code: `let jsx = <Intl id="AddCaptionModal__title"/>`,
options: [{ messagesCacheKey }],
code: `let jsx = <Intl id="icu:real_message"/>`,
options: [{ messagesCacheKey, __mockMessages__ }],
},
],
invalid: [
{
code: 'i18n(`AddCaptionModal__${title}`)',
options: [{ messagesCacheKey }],
code: `i18n("legacy_real_message")`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
'i18n() key "legacy_real_message" is not an ICU message in _locales/en/messages.json',
type: 'CallExpression',
},
],
},
{
code: `window.i18n("legacy_real_message")`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
'i18n() key "legacy_real_message" is not an ICU message in _locales/en/messages.json',
type: 'CallExpression',
},
],
},
{
code: `let jsx = <Intl id="legacy_real_message"/>`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
'<Intl> id "legacy_real_message" is not an ICU message in _locales/en/messages.json',
type: 'JSXOpeningElement',
},
],
},
{
code: 'i18n(`icu:real_${message}`)',
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message: "i18n()'s first argument should always be a literal string",
@@ -47,8 +93,8 @@ ruleTester.run('valid-i18n-keys', rule, {
],
},
{
code: 'window.i18n(`AddCaptionModal__${title}`)',
options: [{ messagesCacheKey }],
code: 'window.i18n(`icu:real_${message}`)',
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message: "i18n()'s first argument should always be a literal string",
@@ -57,8 +103,8 @@ ruleTester.run('valid-i18n-keys', rule, {
],
},
{
code: `let jsx = <Intl id={"AddCaptionModal__title"}/>`,
options: [{ messagesCacheKey }],
code: `let jsx = <Intl id={"icu:real_message"}/>`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
@@ -68,8 +114,8 @@ ruleTester.run('valid-i18n-keys', rule, {
],
},
{
code: 'let jsx = <Intl id={`AddCaptionModal__title`}/>',
options: [{ messagesCacheKey }],
code: 'let jsx = <Intl id={`icu:real_message`}/>',
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
@@ -79,8 +125,8 @@ ruleTester.run('valid-i18n-keys', rule, {
],
},
{
code: 'let jsx = <Intl id={`AddCaptionModal__${title}`}/>',
options: [{ messagesCacheKey }],
code: 'let jsx = <Intl id={`icu:real_${message}`}/>',
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
@@ -91,7 +137,7 @@ ruleTester.run('valid-i18n-keys', rule, {
},
{
code: `i18n("THIS_KEY_SHOULD_NEVER_EXIST")`,
options: [{ messagesCacheKey }],
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
@@ -101,8 +147,8 @@ ruleTester.run('valid-i18n-keys', rule, {
],
},
{
code: `i18n(cond ? "AddCaptionModal__title" : "AddCaptionModal__title")`,
options: [{ messagesCacheKey }],
code: `i18n(cond ? "icu:real_message" : "icu:real_message")`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message: "i18n()'s first argument should always be a literal string",
@@ -112,7 +158,7 @@ ruleTester.run('valid-i18n-keys', rule, {
},
{
code: `i18n(42)`,
options: [{ messagesCacheKey }],
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message: "i18n()'s first argument should always be a literal string",
@@ -122,7 +168,7 @@ ruleTester.run('valid-i18n-keys', rule, {
},
{
code: `let jsx = <Intl id="THIS_KEY_SHOULD_NEVER_EXIST"/>`,
options: [{ messagesCacheKey }],
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
@@ -132,8 +178,8 @@ ruleTester.run('valid-i18n-keys', rule, {
],
},
{
code: `let jsx = <Intl id={cond ? "AddCaptionModal__title" : "AddCaptionModal__title"}/>`,
options: [{ messagesCacheKey }],
code: `let jsx = <Intl id={cond ? "icu:real_message" : "icu:real_message"}/>`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
@@ -144,7 +190,7 @@ ruleTester.run('valid-i18n-keys', rule, {
},
{
code: `let jsx = <Intl id={42}/>`,
options: [{ messagesCacheKey }],
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
@@ -153,5 +199,27 @@ ruleTester.run('valid-i18n-keys', rule, {
},
],
},
{
code: `i18n("icu:deleted_message")`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
'i18n() key "icu:deleted_message" is marked as deleted in _locales/en/messages.json',
type: 'CallExpression',
},
],
},
{
code: `let jsx = <Intl id="icu:deleted_message"/>`,
options: [{ messagesCacheKey, __mockMessages__ }],
errors: [
{
message:
'<Intl> id "icu:deleted_message" is marked as deleted in _locales/en/messages.json',
type: 'JSXOpeningElement',
},
],
},
],
});