-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Handle JSX whitespace separately from fbt whitespace #4717
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
Conversation
b1cf275 to
7308e8d
Compare
|
This PR is now in a good place and it would be great to get some reviews, but I'm not sure who is the best person to look at this! @vjeux If you had time it would be great if you could run this PR over some code at Facebook that uses the |
|
I'll try it out tomorrow. |
|
I just ran it on a big chunk of our codebase and it barely changes anything (and what it changes is for the better). Should be good to go :) |
|
Yay! That is great news 😁 |
This is partial progress towards #2279
With this PR we now detect Facebook
fbttags and handle whitespace for them differently from other JSX tags.This lets us tweak how we format whitespace in JSX tags without breaking the Facebook translation pipeline. This means we can now fix up some small JSX formatting edge cases that have always bugged me 😀
The main benefit here is improved consistency across different but equivalent inputs.
For example the current version of Prettier leaves these unchanged (Playground link):
And with this PR they become:
When the text separating tags or expressions is just a single character we display it on a single line where possible.
With the current version of Prettier (Playground link):
With this PR:
And finally I feel this PR improves the output of edges cases like this:
Input:
Output in current version of Prettier (Playground link):
Output with this PR: