Closed timofei-iatsenko closed 1 week 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.
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.
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.
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.",
},
],
},
],
I recently had following nested translation not detected:
plural(count, { other: t`+# more` })
Was a bit of a PIA to find manually
Let's collect here rules which might be helpful.