lingui / eslint-plugin

Set of ESLint rules for Lingui projects
https://www.npmjs.com/package/eslint-plugin-lingui
MIT License
21 stars 7 forks source link

What rules you are lacking for? #7

Closed timofei-iatsenko closed 1 week ago

timofei-iatsenko commented 1 year ago

Let's collect here rules which might be helpful.

TylerR909 commented 1 year ago

Hey! Really excited to start in on Lingui and glad you're working on ESLint support.

There are a few tokens like <Trans /> that VSCode wants to import from @lingui/react, so an ESLint rule that checks that I'm actually importing it from @lingui/macro would be fantastic.

timofei-iatsenko commented 1 year ago

My proposition:

Rule blocking all global usages of lingui i18n instance. What i mean:

t`Hello` // ❌ Error! 
plural({...}) // ❌ error!

t(i18n)`Hello` // ✅ Ok!
t(i18n)`I have ${plural({one: '# hat', other: "# hats"})}` // ✅ Ok!

Rationally:

It seems lingui was developed when SPA application was the most popular way to use React. In such applications everything executed in the browser and having global singletons is quite fine because you don't need to worry about concurrency.

Currently MPA applications with SSR attracting more and more people and become a default way to make a React applications. Using "globals" in them is harmful. You will get issues right away or withih some period of time.

So to help developers to avoid this, i propose to block these usages at all. BTW It also effectively resolves problem with t on the module level calls which is banned by other rule in this list

PS

I'm thinking for the v5 path, and removing the globals from the lib could be a good candidate for it. This concept is outdated and very confusing.

advdv commented 5 months ago

I would love to see a rule that forces consistent use of explicit message id or no explicit message ids. If developers mix one or the other it should be discouraged.

judeatmerit commented 5 months ago

Hey! Really excited to start in on Lingui and glad you're working on ESLint support.

There are a few tokens like <Trans /> that VSCode wants to import from @lingui/react, so an ESLint rule that checks that I'm actually importing it from @lingui/macro would be fantastic.

@TylerR909 super late to the party, but I just started integrating with Lingui and I'm using no-restricted-imports to help ensure I'm not using the runtime version of Trans. If truly desired, then the dev is to add an explicit disable in the places that need it.

    "no-restricted-imports": [
      "error",
      {
        paths: [
          {
            name: "@lingui/react",
            importNames: ["Trans"],
            message: "Please use Trans from @lingui/macro.",
          },
        ],
      },
    ],
Bertg commented 4 months ago

I recently had following nested translation not detected:

plural(count, { other: t`+# more` })

Was a bit of a PIA to find manually