Skip to content

Commit 3774e88

Browse files
wolfgangwaltherota-meshi
andauthoredJul 22, 2023
fix: no-missing-keys rule reports false positive with trailing dot (#394)
* 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. * Create forty-tools-dream.md --------- Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
1 parent 5a90ce5 commit 3774e88

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed
 

‎.changeset/forty-tools-dream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@intlify/eslint-plugin-vue-i18n": patch
3+
---
4+
5+
fix: no-missing-keys rule reports false positive with trailing dot

‎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)
Please sign in to comment.