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

Bug: jsx-closing-bracket-location autofix removes whitespace character #1501

Open
TSMMark opened this issue Oct 26, 2017 · 4 comments
Open

Comments

@TSMMark
Copy link
Contributor

TSMMark commented Oct 26, 2017

<div>
  foo </div>

Renders a space in HTML: <div>foo </div>

After fix is applied, it becomes:

<div>
  foo 
</div>

Note that there IS a space after foo in the output, however this space will typically be linted off by no-trailing-spaces rule, and even if it's not linted out of your source code, it will be ignored by React's JSX parser, meaning the output HTML will be <div>foo</div> 100% of the time.

tl;dr

<div>foo </div> becomes <div>foo</div>

@ljharb
Copy link
Member

ljharb commented Oct 26, 2017

In that case it seems like the autofix would need to be:

<div>
  {'foo '}
</div>

but i'm not sure it's practical to preserve the space in situations like this; the best practice when a space is important is to put it inside a string inside curlies, for reasons like this.

@TSMMark
Copy link
Contributor Author

TSMMark commented Oct 26, 2017

@ljharb I totally agree that if your whitespace is important you should contain it in curlies. But can we really justify the autofixer breaking code, even if the code is "bad"? If yes, what do you say I apply that same logic to #1497 when handling whitespace? (it's driving me nuts trying to handle it lol)

@ljharb
Copy link
Member

ljharb commented Oct 26, 2017

No, we can't justify that - you're correct.

@Moong0122
Copy link
Contributor

I will take a look this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants