From 64427cb99d22f6fadc277e6c6a07c5a80d34268f Mon Sep 17 00:00:00 2001 From: Alejandro Visciglio Date: Thu, 15 Feb 2024 14:42:35 +0100 Subject: [PATCH 1/3] fix: adds I18nT keyword into key collection --- lib/utils/collect-keys.ts | 8 +++----- tests/lib/rules/no-unused-keys.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/utils/collect-keys.ts b/lib/utils/collect-keys.ts index d32a651e..845fad2d 100644 --- a/lib/utils/collect-keys.ts +++ b/lib/utils/collect-keys.ts @@ -210,13 +210,11 @@ export function collectKeysFromAST( } } else { if ( - (node.key.name === 'path' && - (node.parent.parent.name === 'i18n' || - node.parent.parent.name === 'i18n-t')) || - (node.key.name === 'keypath' && node.parent.parent.name === 'i18n-t') + (node.key.name === 'path' && (['i18n', 'i18n-t', 'i18nt'].includes(node.parent.parent.name)) || + (node.key.name === 'keypath' && ['i18n-t', 'i18nt'].includes(node.parent.parent.name))) ) { debug( - "call VElement:matches([name=i18n], [name=i18n-t]) > VStartTag > VAttribute[key.name='path'] handling ..." + "call VElement:matches([name=i18n], [name=i18n-t], [name=i18nt]) > VStartTag > VAttribute[key.name='path'] handling ..." ) const key = getKeyFromI18nComponent(node) diff --git a/tests/lib/rules/no-unused-keys.ts b/tests/lib/rules/no-unused-keys.ts index 93dedb28..ca53f4e4 100644 --- a/tests/lib/rules/no-unused-keys.ts +++ b/tests/lib/rules/no-unused-keys.ts @@ -94,6 +94,22 @@ new RuleTester({ ` }, + { + // component + filename: 'test.vue', + code: ` + + + { + "en": { + "message_key": "hi" + } + } + + ` + }, { // yaml supports filename: 'test.vue', From 32c3a8111486d9437d20f515b90c2ad4d124388e Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 19 Feb 2024 08:23:23 +0900 Subject: [PATCH 2/3] Create khaki-eyes-serve.md --- .changeset/khaki-eyes-serve.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/khaki-eyes-serve.md diff --git a/.changeset/khaki-eyes-serve.md b/.changeset/khaki-eyes-serve.md new file mode 100644 index 00000000..7b059fef --- /dev/null +++ b/.changeset/khaki-eyes-serve.md @@ -0,0 +1,5 @@ +--- +"@intlify/eslint-plugin-vue-i18n": minor +--- + +fix: adds I18nT keyword into key collection From d0170330f5c252f9fed1928d4d0f80e11c9bc667 Mon Sep 17 00:00:00 2001 From: Alejandro Visciglio Date: Mon, 19 Feb 2024 23:52:17 +0100 Subject: [PATCH 3/3] refactor: replace lowercase node name with pascal case raw name --- lib/utils/collect-keys.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/utils/collect-keys.ts b/lib/utils/collect-keys.ts index 845fad2d..c34b619f 100644 --- a/lib/utils/collect-keys.ts +++ b/lib/utils/collect-keys.ts @@ -210,11 +210,16 @@ export function collectKeysFromAST( } } else { if ( - (node.key.name === 'path' && (['i18n', 'i18n-t', 'i18nt'].includes(node.parent.parent.name)) || - (node.key.name === 'keypath' && ['i18n-t', 'i18nt'].includes(node.parent.parent.name))) + (node.key.name === 'path' && + (node.parent.parent.name === 'i18n' || + node.parent.parent.name === 'i18n-t' || + node.parent.parent.rawName === 'I18nT')) || + (node.key.name === 'keypath' && + (node.parent.parent.name === 'i18n-t' || + node.parent.parent.rawName === 'I18nT')) ) { debug( - "call VElement:matches([name=i18n], [name=i18n-t], [name=i18nt]) > VStartTag > VAttribute[key.name='path'] handling ..." + "call VElement:matches([name=i18n], [name=i18n-t], [name=I18nT]) > VStartTag > VAttribute[key.name='path'] handling ..." ) const key = getKeyFromI18nComponent(node)