From 24bedbf244bdf21b33947d77f6c86e59da1be722 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Wed, 6 Apr 2022 11:15:03 +0900 Subject: [PATCH] Fix false positives in no-missing-keys --- lib/utils/locale-messages.ts | 4 +++- .../complex-locales/locales/en.json | 7 +++++++ .../complex-locales/locales/ja.json | 7 +++++++ tests/lib/rules/no-missing-keys.ts | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/no-missing-keys/complex-locales/locales/en.json create mode 100644 tests/fixtures/no-missing-keys/complex-locales/locales/ja.json diff --git a/lib/utils/locale-messages.ts b/lib/utils/locale-messages.ts index b6f8c67c..eb37d425 100644 --- a/lib/utils/locale-messages.ts +++ b/lib/utils/locale-messages.ts @@ -310,6 +310,7 @@ export class LocaleMessages { const paths = [...parsePath(key)] let lasts = localeMessages const targetPaths = [] + let hasMissing = false while (paths.length) { const path = paths.shift()! targetPaths.push(path) @@ -323,11 +324,12 @@ export class LocaleMessages { if (missingPath.length <= targetPaths.length) { missingPath = targetPaths } + hasMissing = true break } lasts = values } - if (!missingPath.length) { + if (!hasMissing) { return null } } diff --git a/tests/fixtures/no-missing-keys/complex-locales/locales/en.json b/tests/fixtures/no-missing-keys/complex-locales/locales/en.json new file mode 100644 index 00000000..b16c2d70 --- /dev/null +++ b/tests/fixtures/no-missing-keys/complex-locales/locales/en.json @@ -0,0 +1,7 @@ +{ + "nesting01": { + "a": { + "a": "message" + } + } +} diff --git a/tests/fixtures/no-missing-keys/complex-locales/locales/ja.json b/tests/fixtures/no-missing-keys/complex-locales/locales/ja.json new file mode 100644 index 00000000..a6c35704 --- /dev/null +++ b/tests/fixtures/no-missing-keys/complex-locales/locales/ja.json @@ -0,0 +1,7 @@ +{ + "nesting01": { + "a": { + "b": "message" + } + } +} diff --git a/tests/lib/rules/no-missing-keys.ts b/tests/lib/rules/no-missing-keys.ts index 6ce4499f..1bcbf8e1 100644 --- a/tests/lib/rules/no-missing-keys.ts +++ b/tests/lib/rules/no-missing-keys.ts @@ -214,6 +214,20 @@ tester.run('no-missing-keys', rule as never, { } } ` + }, + { + filename: 'test.vue', + code: ` + `, + settings: { + 'vue-i18n': { + localeDir: + './tests/fixtures/no-missing-keys/complex-locales/locales/*.json' + } + } } ] ),