diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-10-16 14:13:05 +0100 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-10-22 12:02:24 +0100 |
| commit | dba32772007a3d0f2caacdb3130a8519c1528b19 (patch) | |
| tree | 2123d44d91ddcdbd147aea827fb55ab586898350 | |
| parent | lint all uses of translations (diff) | |
| download | sharkey-dba32772007a3d0f2caacdb3130a8519c1528b19.tar.gz sharkey-dba32772007a3d0f2caacdb3130a8519c1528b19.tar.bz2 sharkey-dba32772007a3d0f2caacdb3130a8519c1528b19.zip | |
fix CallExpression detection
| -rw-r--r-- | eslint/locale.js | 10 | ||||
| -rw-r--r-- | eslint/locale.test.js | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/eslint/locale.js b/eslint/locale.js index b6f6f762be..746bff88a5 100644 --- a/eslint/locale.js +++ b/eslint/locale.js @@ -40,9 +40,13 @@ function walkDown(locale, path) { * to the MemberExpressions */ function findCallExpression(node) { - if (node.type === 'CallExpression') return node - if (node.parent?.type === 'CallExpression') return node.parent; - if (node.parent?.type === 'MemberExpression') return findCallExpression(node.parent); + if (!node.parent) return null; + + // the second half of this guard protects from cases like + // `foo(one.two.three)` where the CallExpression is parent of the + // MemberExpressions, but via `arguments`, not `callee` + if (node.parent.type === 'CallExpression' && node.parent.callee === node) return node.parent; + if (node.parent.type === 'MemberExpression') return findCallExpression(node.parent); return null; } diff --git a/eslint/locale.test.js b/eslint/locale.test.js index cf64961054..2ba1fb3d24 100644 --- a/eslint/locale.test.js +++ b/eslint/locale.test.js @@ -15,6 +15,7 @@ ruleTester.run( {code: 'i18n.tsx.foo.baz(1)', options: [locale] }, {code: 'whatever.i18n.ts.blah.blah', options: [locale] }, {code: 'whatever.i18n.tsx.does.not.matter', options: [locale] }, + {code: 'whatever(i18n.ts.foo.bar)', options: [locale] }, ], invalid: [ {code: 'i18n.ts.not', options: [locale], errors: 1 }, |