Description
What rule do you want to change?
no-unused-keys
Does this change cause the rule to produce more or fewer warnings?
fewer
How will the change be implemented? (New option, new default behavior, etc.)?
Read the type for the input of the translation-function to determine the possible strings.
Please provide some example code that this change will affect:
<script lang="ts" setup>
let status: 'loading' | 'error' | 'success' = 'loading';
</script>
<template>
<span>{{ t(`global.${status}` }}</span>
</template>
What does the rule currently do for this code?
I guess it does ignore all template-strings, because I get a list of all these translation-keys reported as being unused.
What will the rule do after it's changed?
It recognizes, that the only available values (based on the given types) are global.loading
, global.error
and global.success
, and will remember all those as being used. If not already, this could also be used in the rule @intlify/vue-i18n/no-missing-keys
to determine possibly missing keys.
To be clear, this rule is not for variables typed as string
. There are ways of mapping a union of fixed strings or extending it (see https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html).
Additional context
- If TypeScript is not already used in this rule, it will most certainly reduce performance (
no-unused-keys
is very slow #354). - Might have an intersection with Allow
as
forno-dynamic-keys
rule #602. This rule could also reduce the need for implementing Allowas
forno-dynamic-keys
rule #602 to a bare minimum.