Skip to content

Commit 84d59fb

Browse files
authored
Fix false positives in no-missing-keys (#313)
1 parent b43bb16 commit 84d59fb

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/utils/locale-messages.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export class LocaleMessages {
310310
const paths = [...parsePath(key)]
311311
let lasts = localeMessages
312312
const targetPaths = []
313+
let hasMissing = false
313314
while (paths.length) {
314315
const path = paths.shift()!
315316
targetPaths.push(path)
@@ -323,11 +324,12 @@ export class LocaleMessages {
323324
if (missingPath.length <= targetPaths.length) {
324325
missingPath = targetPaths
325326
}
327+
hasMissing = true
326328
break
327329
}
328330
lasts = values
329331
}
330-
if (!missingPath.length) {
332+
if (!hasMissing) {
331333
return null
332334
}
333335
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"nesting01": {
3+
"a": {
4+
"a": "message"
5+
}
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"nesting01": {
3+
"a": {
4+
"b": "message"
5+
}
6+
}
7+
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,20 @@ tester.run('no-missing-keys', rule as never, {
214214
}
215215
}
216216
</script>`
217+
},
218+
{
219+
filename: 'test.vue',
220+
code: `
221+
<template>
222+
{{$t('nesting01.a.a')}}
223+
{{$t('nesting01.a.b')}}
224+
</template>`,
225+
settings: {
226+
'vue-i18n': {
227+
localeDir:
228+
'./tests/fixtures/no-missing-keys/complex-locales/locales/*.json'
229+
}
230+
}
217231
}
218232
]
219233
),

0 commit comments

Comments
 (0)