From 8078674a27481af2a66627b8461e7de8d64a865d Mon Sep 17 00:00:00 2001 From: William Chong Date: Mon, 6 May 2019 20:14:20 +0800 Subject: [PATCH] :bug: fix plugin crashes on missing nested path --- lib/utils/index.js | 2 +- tests/lib/rules/no-missing-keys.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 0db2b4e2..97d39c10 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -61,7 +61,7 @@ function findMissingsFromLocaleMessages (localeMessages, key) { let last = localeMessage.messages let i = 0 while (i < length) { - const value = last[paths[i]] + const value = last && last[paths[i]] if (value === undefined) { missings.push({ message: `'${key}' does not exist` diff --git a/tests/lib/rules/no-missing-keys.js b/tests/lib/rules/no-missing-keys.js index f8ce2b2b..d8dda9f2 100644 --- a/tests/lib/rules/no-missing-keys.js +++ b/tests/lib/rules/no-missing-keys.js @@ -108,5 +108,15 @@ tester.run('no-missing-keys', rule, { errors: [ `You need to 'localeDir' at 'settings. See the 'eslint-plugin-vue-i18n documentation` ] + }, { + // nested basic + settings, + code: `$t('missing.path')`, + errors: [ + `'missing.path' does not exist`, + `'missing.path' does not exist`, + `'missing.path' does not exist`, + `'missing.path' does not exist` + ] }] })