eslint-plugin icon indicating copy to clipboard operation
eslint-plugin copied to clipboard

What rules you are lacking for?

Open timofei-iatsenko opened this issue 2 years ago • 5 comments

Let's collect here rules which might be helpful.

timofei-iatsenko avatar Aug 18 '23 09:08 timofei-iatsenko

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 avatar Aug 18 '23 22:08 TylerR909

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.

timofei-iatsenko avatar Sep 15 '23 08:09 timofei-iatsenko

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.

advdv avatar Apr 30 '24 07:04 advdv

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.",
          },
        ],
      },
    ],

judeatmerit avatar May 01 '24 23:05 judeatmerit

I recently had following nested translation not detected:

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

Was a bit of a PIA to find manually

Bertg avatar May 30 '24 14:05 Bertg