feat: Adds no-t-inside-trans-functions rule#111
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #111 +/- ##
==========================================
+ Coverage 97.86% 97.89% +0.02%
==========================================
Files 11 12 +1
Lines 563 618 +55
Branches 187 207 +20
==========================================
+ Hits 551 605 +54
- Misses 12 13 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@garikkh thanks for the contribution, looks nice! @timofei-iatsenko what do you think? |
There was a problem hiding this comment.
@garikkh Thanks for the contribution! I have a few change requests:
There are quite a few cases not yet covered — t can appear not only as a TaggedTemplateExpression, but also as a CallExpression in various forms.
Similarly, Trans and Plural are only part of the Lingui API — there are other components that should also be handled.
Covering all possible forms and signatures can be tricky, which is why this plugin provides ready-to-use queries for all Lingui cases in src/helpers.ts.
You can take a look at the src/rules/no-trans-inside-trans.ts rule for reference.
Also, the rule name no-t-inside-trans-function might not fully reflect its purpose, since it’s not limited to Trans. It might be worth considering a more fitting name.
Agreed, originally the only scope was t in trans, but then extended for other cases. I'll check the helper queries, and rename the rule. Might take me a few days to get back to this though |
|
@timofei-iatsenko can you point me to a good definition of what is/isn't allowed? I think there are these functions:
which combinations are allowed? you can't have technically If none are allowed within each other, that is OK too - that's how the latest version of this lint rule checks it as well. |
|
bump @timofei-iatsenko |
|
Bump again @timofei-iatsenko - what can I do to get this PR merged :) |
|
Bump again - but also, would like to confirm something: Can react <Plural value={count}
one={
<Trans>
I have <br/>
1 book
</Trans>
}
other={
<Trans>
I have <br/>
{tokens} books
</Trans>
}
/>But the other way around is not good? <Trans>
I have <br/>
<Plural value={count} one="1 book" other="# books" />
</Trans>If so, plugin needs to be fixed. |
|
Hi @timofei-iatsenko, could you please check if any action is needed here to proceed? Thanks! |
Both of them are fine. The second option is discussed here #110 I think it out of scope of this rule. I think So basically we can narrow this rule to "no nested core macro in trans". (for simplicity, meaning trans == plural/select/etc) |
Fixes #90
Adds a new rule to prevent
tcalls inside other functions likeplural,PluralandTrans