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] },