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

Proposal: Linting for missing spaces between tags #1515

Closed
pfhayes opened this issue Nov 3, 2017 · 4 comments
Closed

Proposal: Linting for missing spaces between tags #1515

pfhayes opened this issue Nov 3, 2017 · 4 comments

Comments

@pfhayes
Copy link
Contributor

pfhayes commented Nov 3, 2017

If your React markup looks like this:

<p>
  Here is a
  <a href="https://google.com>link</a>
  to Google
</p>

The whitespace will be collapsed and it will look like

Here is alinkto Google

Note that the whitespace is collapsed. The recommended solution from React is to write your code as

<p>
  Here is a
  {' '}
  <a href="https://google.com>link</a>
  {' '}
  to Google
</p>

which will render correctly.

It would be great if there was a lint rule that caught this.

  • Does this already exist?
  • Is this something desirable? I am happy to look into a PR
@ljharb
Copy link
Member

ljharb commented Nov 3, 2017

I don't think a rule could catch this, because there's no guarantee that the user wants the space there - and in fact, they might not want it. That's why the best practice is to be explicit.

@pfhayes
Copy link
Contributor Author

pfhayes commented Nov 4, 2017

In my experience, it is very rare that the developer does not want the space. It is almost always indicative of an error that manifests as incorrectly rendered copy

In the case where the developer does not want the space, I would consider it reasonable to require that they be directly adjacent, as in

<p>
  Here is a<a href="https://google.com>link</a>to Google
</p>

Or when the line is long

<p>
  Here is a{/*
  */}<a href="https://google.com>link</a>{/*
  */}to Google
</p>

In general, as written originally the developer's intent is not clear. It appears as though they want some whitespace between the tags, but they may not

One could imagine a rule that forces you to be explicit always - that is, including {' '} when you want a space and a line continuation or comment when you want them adjacent

@ljharb
Copy link
Member

ljharb commented Nov 4, 2017

It might not be safely autofixable at least; but sure, it'd be interesting to see the test cases in a PR.

@pfhayes
Copy link
Contributor Author

pfhayes commented Nov 7, 2017

Thanks - I added some illustrative test cases in #1519

@ljharb ljharb closed this as completed in 06e1667 Dec 1, 2017
This was referenced Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants