Skip to content

Commit cda51de

Browse files
authored
Fix false negatives for <i18n-t keypath> in no-missing-key rule (#253)
1 parent be1fda7 commit cda51de

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/rules/no-missing-keys.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ function create(context: RuleContext): RuleListener {
1717
checkDirective(context, node)
1818
},
1919

20-
"VElement:matches([name=i18n], [name=i18n-t]) > VStartTag > VAttribute[key.name='path']"(
21-
node: VAST.VAttribute
22-
) {
23-
checkComponent(context, node)
24-
},
25-
26-
"VElement:matches([name=i18n], [name=i18n-t]) > VStartTag > VAttribute[key.name.name='path']"(
20+
["VElement:matches([name=i18n], [name=i18n-t]) > VStartTag > VAttribute[key.name='path']," +
21+
"VElement[name=i18n-t] > VStartTag > VAttribute[key.name='keypath']"](
2722
node: VAST.VAttribute
2823
) {
2924
checkComponent(context, node)

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ tester.run('no-missing-keys', rule as never, {
161161
<template>
162162
<div id="app"></div>
163163
</template>`
164+
},
165+
{
166+
filename: 'test.vue',
167+
code: `
168+
<i18n locale="en">{"hello": "hello"}</i18n>
169+
<template>
170+
<i18n-t keypath="'hello'"></i18n-t>
171+
</template>`
164172
}
165173
]
166174
),
@@ -278,6 +286,15 @@ tester.run('no-missing-keys', rule as never, {
278286
<p v-t="'missing'"></p>
279287
</template>`,
280288
errors: [`'missing' does not exist in localization message resources`]
289+
},
290+
{
291+
filename: 'test.vue',
292+
code: `
293+
<i18n locale="en">{"hello": "hello"}</i18n>
294+
<template>
295+
<i18n-t keypath="hi"></i18n-t>
296+
</template>`,
297+
errors: [`'hi' does not exist in localization message resources`]
281298
}
282299
]
283300
)

0 commit comments

Comments
 (0)