Skip to content

Commit

Permalink
fix: no-missing-keys rule reports false positive with trailing dot (#394
Browse files Browse the repository at this point in the history
)

* 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>
  • Loading branch information
wolfgangwalther and ota-meshi authored Jul 22, 2023
1 parent 5a90ce5 commit 3774e88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-tools-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@intlify/eslint-plugin-vue-i18n": patch
---

fix: no-missing-keys rule reports false positive with trailing dot
2 changes: 1 addition & 1 deletion lib/utils/key-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export function joinPath(...paths: (string | number)[]): string {
}

export function parsePath(path: string): string[] {
return parse(path) || []
return parse(path) || [path]
}
9 changes: 8 additions & 1 deletion tests/lib/rules/no-missing-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ tester.run('no-missing-keys', rule as never, {
code: `
<i18n locale="en">{"hello": "hello"}</i18n>
<template>
<i18n-t keypath="'hello'"></i18n-t>
<i18n-t keypath="hello"></i18n-t>
</template>`
},
{
Expand Down Expand Up @@ -271,6 +271,13 @@ tester.run('no-missing-keys', rule as never, {
</template>`,
errors: [`'missing' does not exist in localization message resources`]
},
{
// missing ending with a dot
code: `$t('missing.')`,
errors: [
`'["missing."]' does not exist in localization message resources`
]
},
{
// nested basic
code: `$t('missing.path')`,
Expand Down

0 comments on commit 3774e88

Please sign in to comment.