lingui / eslint-plugin

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

Extending rules to support more Lingui usecases #4

Closed timofei-iatsenko closed 2 weeks ago

timofei-iatsenko commented 1 year ago

Currently, the rules are "happy path" only. It means it doesn't cover every edge case. In this issue i will start collecting problems which I noticed (not a complete list though):

yuriy-yarosh commented 10 months ago

@thekip I'd suggest making making recommended settings first e.g. plugin:lingui/recommended.

timofei-iatsenko commented 2 weeks ago

Most of the rules doesn't check that components are actually belongs to Lingui. It just checking it by name such as Trans and t. It means if you have your own Trans component it will be also subject of validation despite it imported from diffrent package. The rules doesn't support renamed symbols. If you have import Trans as $Trans from "@lingui/macro" rules would not be applied to $Trans usages

I dug a bit into eslint plugins architecture, and it seems for us implementing such mechanism will bring more harm than help. I'm pretty satisfied with how that works now, just matching macros by their's name.

Rules do understand only few macros, such as t but don't understand defineMessage and msg. They also don't understand any other usage of the rule than TaggedTemplateExpression. Means calls such as t({message: "Hello!"}) would be ignored or even fail.

I added support for different lingui signatures to all rules.