-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lint against strings without wrapping <Text> #3398
Conversation
'bsky-internal/avoid-unwrapped-text': [ | ||
'error', | ||
{ | ||
impliedTextComponents: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal is to get this list close to zero, maybe except H1..H6. For components that always return Text (e.g. links), I propose adding Text suffix and making the rule enforce that they actually return Text. Will need follow-up work.
The Pull Request introduced fingerprint changes against the base commit: 8e393b1 Fingerprint diff[
{
"type": "file",
"filePath": "package.json",
"reasons": [
"expoConfigPlugins"
],
"hash": "e63e4bc19f16de7405b22d617734da9061b47b13"
}
] Generated by PR labeler 🤖 |
@@ -234,6 +234,7 @@ | |||
"babel-preset-expo": "^10.0.0", | |||
"detox": "^20.14.8", | |||
"eslint": "^8.19.0", | |||
"eslint-plugin-bsky-internal": "link:./eslint", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to run yarn.
|
5b8747a
to
2fc78e0
Compare
2fc78e0
to
66f966c
Compare
8089e14
to
fb9a516
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went through a bunch of test cases on this, works great. Really like the prop name idea as well.
This adds a lint rule enforcing that JSX text has an immediate
<Text>
parent. There are a few nuances:<Trans>
when looking upwards for<Text>
. So<Text><Trans>text</Trans></Text>
is OK.<Trans>
, the parent has to be immediate. I.e.<Foo><Text>text</Text></Foo>
is OK but<Text><Foo>text</Foo></Text>
is not.Text
as a valid parent. E.g.<FooText>text</FooText>
is OK. This is useful for the design system.FooText
must returnText
. This would close the remaining loophole.text
(or ending withText
) as an implied guarantee it's wrapped. So<Foo bla={<Trans>hello</Trans>} />
is not OK but<Foo blaText={<Trans>hello</Trans>} />
is OK.<Foo>{'text'}</Foo>
will pass despite being not OK. Only JSX text is validated. This leaves much less space for false positives, and is probably fine because we have to wrap stuff in<Trans>
anyway.This gets us pretty far.
Examples
Raw text in
<View>
Raw text in a custom component
Raw text in a prop