Skip to content

Commit 1d50e01

Browse files
authored
Fix false positives when key contains object in YAML in no-unused-keys and no-duplicate-keys-in-locale rules. (#115)
1 parent bb66b7b commit 1d50e01

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

lib/rules/no-duplicate-keys-in-locale.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ function create(context: RuleContext): RuleListener {
257257
return true
258258
}
259259

260-
if (node.type === 'YAMLPair') {
261-
yamlKeyNodes.add(node.key)
262-
return true
263-
}
264260
if (yamlKeyNodes.has(node)) {
265261
// within key node
266262
return true
@@ -271,6 +267,10 @@ function create(context: RuleContext): RuleListener {
271267
yamlKeyNodes.add(node)
272268
return true
273269
}
270+
if (node.type === 'YAMLPair') {
271+
yamlKeyNodes.add(node.key)
272+
return true
273+
}
274274
return false
275275
},
276276
resolveKey(node) {

lib/rules/no-unused-keys.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ function create(context: RuleContext): RuleListener {
321321
return true
322322
}
323323

324-
if (node.type === 'YAMLPair') {
325-
yamlKeyNodes.add(node.key)
326-
return true
327-
}
328324
if (yamlKeyNodes.has(node)) {
329325
// within key node
330326
return true
@@ -335,6 +331,10 @@ function create(context: RuleContext): RuleListener {
335331
yamlKeyNodes.add(node)
336332
return true
337333
}
334+
if (node.type === 'YAMLPair') {
335+
yamlKeyNodes.add(node.key)
336+
return true
337+
}
338338
return false
339339
},
340340
/**

tests/lib/rules/no-duplicate-keys-in-locale.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ new RuleTester({
6161
</i18n>
6262
<template></template>
6363
<script></script>`
64+
},
65+
{
66+
filename: 'test.vue',
67+
code: `
68+
<i18n lang="yaml">
69+
en:
70+
? [{foo: {bar: baz}}]
71+
: 123
72+
foo: {bar: baz}
73+
</i18n>
74+
<template></template>
75+
<script></script>`
6476
}
6577
],
6678
invalid: [

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,17 @@ ${' '.repeat(6)}
910910
]
911911
}
912912
]
913+
},
914+
{
915+
filename: 'test.vue',
916+
code: `
917+
<i18n locale="en" lang="yaml">
918+
? [{foo: bar}]
919+
: {foo: bar}
920+
</i18n>
921+
<template></template>
922+
<script></script>`,
923+
errors: [`unused '["[{foo: bar}]"].foo' key`]
913924
}
914925
]
915926
})

0 commit comments

Comments
 (0)