Skip to content

chore: adds eslint rules for unused messages and duplicate keys#1930

Merged
ErikSin merged 4 commits into
developfrom
chore/lint-message-descriptors
Jun 10, 2026
Merged

chore: adds eslint rules for unused messages and duplicate keys#1930
ErikSin merged 4 commits into
developfrom
chore/lint-message-descriptors

Conversation

@cimigree

@cimigree cimigree commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

closes #1891

  • Adds a folder for eslint rules.

    • Adds a file in there to create rules for international (intl) messages.
    • The files has two rules.
    • Within each individual file, it checks for unused messages and duplicate keys.
      • If the file has a message defined by being looked up at runtime (see 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.
      • If the file exports all of the messages, (see 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 test for that file that will run with the jest tests
  • 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/

cimigree added 2 commits June 8, 2026 15:22
…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).
@cimigree cimigree requested a review from ErikSin June 8, 2026 20:07
@achou11

achou11 commented Jun 9, 2026

Copy link
Copy Markdown
Member

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...

Comment thread eslint-rules/intl.js Outdated
@@ -0,0 +1,155 @@
// @ts-nocheck

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ErikSin ErikSin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for doing that, excited to have this rule!

@ErikSin ErikSin merged commit 8be6a7f into develop Jun 10, 2026
11 of 12 checks passed
@ErikSin ErikSin deleted the chore/lint-message-descriptors branch June 10, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Eslint rule to catch unused message descriptors

3 participants