From f11536c927e0ce4fdc18e3c179835cdde3942b5a Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 16 Oct 2024 15:56:48 +0100 Subject: [PATCH] ignore weirder cases --- eslint/locale.js | 7 ++++++- eslint/locale.test.js | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/eslint/locale.js b/eslint/locale.js index 60ae21e6e5..a686a4b616 100644 --- a/eslint/locale.js +++ b/eslint/locale.js @@ -23,7 +23,7 @@ function collectMembers(node) { */ function walkDown(locale, path) { if (!locale) return null; - if (!path || path.length === 0) return locale; + if (!path || path.length === 0 || !path[0]) return locale; return walkDown(locale[path[0]], path.slice(1)); } @@ -112,6 +112,11 @@ function theRule(context) { return; } + // we hit something weird, assume the programmers know what + // they're doing (this is usually some complicated slicing of + // the translation structure) + if (typeof(translation) !== 'string') return; + // some more checks on how the translation is called if (method == 'ts') { if (translation.match(/\{/)) { diff --git a/eslint/locale.test.js b/eslint/locale.test.js index f08950b8c7..626fe1587c 100644 --- a/eslint/locale.test.js +++ b/eslint/locale.test.js @@ -11,6 +11,8 @@ ruleTester.run( { valid: [ {code: 'i18n.ts.foo.bar', options: [locale] }, + // we don't detect the problem here, but should still accept it + {code: 'i18n.ts.foo["something"]', options: [locale] }, {code: 'i18n.ts.top', options: [locale] }, {code: 'i18n.tsx.foo.baz({x:1})', options: [locale] }, {code: 'whatever.i18n.ts.blah.blah', options: [locale] },