Skip to content
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

Add line break before forced space to stay within the print width #4527

Closed
mariusschulz opened this issue May 23, 2018 · 2 comments
Closed
Labels
lang:jsx Issues affecting JSX (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:duplicate Issues that are a duplicate of a previous issue

Comments

@mariusschulz
Copy link

Prettier 1.12.1
Playground link

Input:

const someVariable = (
  <div>
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx{" "}y
  </div>
);

Output:

const someVariable = (
  <div>
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx{" "}
    y
  </div>
);

Expected behavior:

const someVariable = (
  <div>
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    {" "}y
  </div>
);

With --print-width=80, the forced space ({" "}) should be placed on the next line so that the line does not exceed the print width.

@duailibe
Copy link
Member

Context: #1582 #1831 #1964

We decided to do always append to the preceding node (instead of prepending to the following node) because there might be some cases of

<div>
  xxxxxxxxxxxx
  {" "}<div>
    <Something />
  </div>
</div>

I guess we can improve this heuristic, see what's before and what's after and then chose what's best.

@duailibe duailibe added the lang:jsx Issues affecting JSX (not general JS issues) label May 23, 2018
@lydell
Copy link
Member

lydell commented May 23, 2018

I actually think this is a duplicate of #2553

@lydell lydell closed this as completed May 23, 2018
@lydell lydell marked this as a duplicate of #2553 May 23, 2018
@lydell lydell added the type:duplicate Issues that are a duplicate of a previous issue label May 23, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Aug 21, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:jsx Issues affecting JSX (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:duplicate Issues that are a duplicate of a previous issue
Projects
None yet
Development

No branches or pull requests

3 participants