chore: adds eslint rules for unused messages and duplicate keys#1930
Conversation
…rnational (intl) messages. Throws an error if an id is used more than once with a different value when running extract message. Makes a plugin for the new eslint rules. Adds a test for the eslint rules. Fixes the violations (unused ids).
|
Sorry for the drive-by comment, but worth noting that formatjs has an official eslint plugin: https://formatjs.github.io/docs/tooling/linter. It probably doesn't cover everything you're trying to do but it's probably a good idea to integrate it regardless (if you think the rules it has are useful). EDIT: Looking closer at the original issue, what you're trying to achieve is probably not covered by the official plugin. Just caught my eye because having to implement and maintain a custom eslint rule doesn't sound like a fun thing to maintain... |
| @@ -0,0 +1,155 @@ | |||
| // @ts-nocheck | |||
There was a problem hiding this comment.
by default js files have // @ts-nocheck so this is redundant.
However, I think it would be good to use // @ts-check so that we can get typescript error checking in a js file.
You can use /** @type {import('eslint').Rule.RuleModule} */ on your functions to type the context and node so you dont get ts errors
ErikSin
left a comment
There was a problem hiding this comment.
Thanks for doing that, excited to have this rule!
closes #1891
Adds a folder for eslint rules.
src/frontend/screens/LocationInfoScreen.tsx) there is no way for eslint to tell what has been used and unused, so then everything in that file passes.src/frontend/screens/Onboarding/DataPrivacyMessages.ts) there is no way with eslint to tell if the message is used, or unused, so that all passes.Adds a "throws" in the extract-messages script so that if there are duplicate keys with different values (the defaultMessage or description part), it will let the developer know! Right now, the first message with the duplicate key is just overwritten by the second.
Creates a plugin for the custom EsLint rules
Fixes the violations of the no unused messages.
I got a lot of help from this post: https://neciudan.dev/master-eslint-rules and this site: https://astexplorer.net/