Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds I18nT keyword into key collection #471

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/utils/collect-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use rawName to determine more accurately?

Suggested change
(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'))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I've fixed it accordingly.

) {
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)
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-unused-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ new RuleTester({
</i18n>
`
},
{
// <I18nT> component
filename: 'test.vue',
code: `
<template>
<I18nT keypath="message_key" tag="p" />
</template>
<i18n>
{
"en": {
"message_key": "hi"
}
}
</i18n>
`
},
{
// yaml supports
filename: 'test.vue',
Expand Down