Skip to content

Commit 87797c9

Browse files
wolfgangwaltherota-meshi
authored andcommitted
fix: no-missing-keys rule reports false positive with trailing dot
For a translation key like $t('missing.') the parse function from core utilities returns undefined. Previously this was turned into an empty array which caused all of those paths to be false positives. If the given key can't be parsed as "path" properly, the correct handling is to treat it as a single item path with the provided string as the only item. This also revealed another faulty test, where keypath="'hello'" was passing even though it should not.
1 parent 5a90ce5 commit 87797c9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/utils/key-path.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ export function joinPath(...paths: (string | number)[]): string {
2121
}
2222

2323
export function parsePath(path: string): string[] {
24-
return parse(path) || []
24+
return parse(path) || [path]
2525
}

tests/lib/rules/no-missing-keys.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ tester.run('no-missing-keys', rule as never, {
167167
code: `
168168
<i18n locale="en">{"hello": "hello"}</i18n>
169169
<template>
170-
<i18n-t keypath="'hello'"></i18n-t>
170+
<i18n-t keypath="hello"></i18n-t>
171171
</template>`
172172
},
173173
{
@@ -271,6 +271,13 @@ tester.run('no-missing-keys', rule as never, {
271271
</template>`,
272272
errors: [`'missing' does not exist in localization message resources`]
273273
},
274+
{
275+
// missing ending with a dot
276+
code: `$t('missing.')`,
277+
errors: [
278+
`'["missing."]' does not exist in localization message resources`
279+
]
280+
},
274281
{
275282
// nested basic
276283
code: `$t('missing.path')`,

0 commit comments

Comments
 (0)