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

Spaces get condensed by --fix when they are alone in a <span> #1717

Closed
pbondoer opened this issue Mar 9, 2018 · 4 comments · Fixed by #2210
Closed

Spaces get condensed by --fix when they are alone in a <span> #1717

pbondoer opened this issue Mar 9, 2018 · 4 comments · Fixed by #2210

Comments

@pbondoer
Copy link

pbondoer commented Mar 9, 2018

We often need to add spacing between two elements in JSX. For example:

<GenericTextComponent type='test' />
<span>{' '}</span>
<GenericTextComponent type='other' />

Applying --fix turns the code into this:

<GenericTextComponent type='test' />
<span />
<GenericTextComponent type='other' />

which is not the same thing.

I think I've traced down what's happening. The code above gives off this error:

error  Curly braces are unnecessary here  react/jsx-curly-brace-presence

Which, when corrected (by removing the curly braces and quotes), gives off another error:

error  Empty components are self-closing  react/self-closing-comp

which --fix happily turns into the <span /> above.

Versions:

  • eslint@4.18.2
  • eslint-plugin-react@7.7.0
@ljharb
Copy link
Member

ljharb commented Mar 9, 2018

Ouch, that’s a problem. The bug is with curly brace presence (they are necessary around whitespace) and maybe also with self-closing-comp (inline elements with a space inside aren’t necessarily empty).

These need to be fixed soon.

@ljharb
Copy link
Member

ljharb commented Mar 9, 2018

cc @sharmilajesupaul

@sharmilajesupaul
Copy link
Contributor

sharmilajesupaul commented Mar 9, 2018

It looks like react/jsx-curly-brace-presence is erroneously warning on {' '} which is necessary even if children/global option is set to never. Once that's removed, react/self-closing-comp is autofixing the <span> to be self-closing.

The react/jsx-curly-brace-presence rule doesn't have a test for this case but react/self-closing-comp does.

So fixing react/jsx-curly-brace-presence will solve this issue... I think 🤔

@ljharb
Copy link
Member

ljharb commented Mar 13, 2018

We still should fix react-self-closing-comp to not treat inline HTML elements as empty when they contain whitespace (it should autofix them to a single space, perhaps)

@ljharb ljharb reopened this Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants