-
-
Notifications
You must be signed in to change notification settings - Fork 44
Add ability to ignore certain keys in no-unused-keys
rule
#261
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
Comments
Thank you for posting this issue. However, I don't understand your use case. |
I have some keys that appear to be unused to the rule, but are in fact used:
I tried a few variations of disabling comments and only managed to disable the whole <!-- eslint-disable @intlify/vue-i18n/no-unused-keys this works, but only for the following block -->
<i18n lang="yaml" locale="en">
header breadcrumb: Home
header title: Home
</i18n>
<!-- the following block still throws errors, the comment above needs to be repeated here -->
<i18n lang="yaml" locale="de">
# eslint-disable-next-line @intlify/vue-i18n/no-unused-keys this does not work
header breadcrumb: Home
header title: Home
</i18n> Maybe the issue is with yaml comments not being parsed, I don't know. But right now I would have to create each i18n block twice: once for keys that appear unused and once for keys that should be checked regularly be the rule. Also, since I use this mixin a lot across the codebase, this would lead to a loot of disable comments - where a simple ignore option would work the same. |
Thank you for your explanation. I have more questions.
I don't think it's worth using the |
The Providing a regex (if the whole key was available as string) or function callback in the ignore option would be flexible enough to easily add everything I need. The keys to ignore follow a common pattern. However, better support for disable comments in YAML would help already, too. But I fear that this might be harder to do? |
Thank you for your explanation. I think regex support is probably a must.
Unfortunately, the ESLint configuration file does not allow to specify a function.
It's hard to implement now, as you say, but I may implement it in the future 😅. |
hi @wolfgangwalther and @ota-meshi . I was wondering about the same thing and you started this just a week ago :). Let me start with a simple workaround, which might work for others as well: Introduce another translation file ( |
And here is a different idea to approach this architecture wise: There might be a LOT of dynamic keys in different places around the code and at the same time the I'd propose to put some kind of annotation in the code that the linter can find and expand. E.g.
I do not think Anyways, the ideas is that this might be easier to code (linter) and maintain (users of the linter) as there is a higher chance that devs notice that the |
Works perfectly, thank you very much! :) |
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.)?
New option.
Please provide some example code that this change will affect:
What does the rule currently do for this code?
Report
unused 'ignore_me' key
.What will the rule do after it's changed?
Report all good.
Additional context
Would be good if it was possible to add either plain values or regex to the
ignore
array, to be flexible.Most flexible would be to pass a function to
ignore
that is called to check whether the key should be ignored or not.The text was updated successfully, but these errors were encountered: