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

New rule: Control empty lines around JSX tags #2793

Closed
jsphstls opened this issue Sep 11, 2020 · 8 comments · Fixed by #2935
Closed

New rule: Control empty lines around JSX tags #2793

jsphstls opened this issue Sep 11, 2020 · 8 comments · Fixed by #2935

Comments

@jsphstls
Copy link
Contributor

return (

  <button/>

)

I'd like a rule that would help eliminate empty lines around JSX. The most common case that I encounter is the above example when empty lines occur (mostly after) the JSX and before a closing parenthesis. I don't think these are ever done intentionally and I cannot see how it would improve readability.

A related case that is less common is to add blank lines between JSX:

return (
  <div> 
    <button/>

    <button/>
  </div>
)

This is often done intentionally. I am less concerned about these cases. However, I think they create ambiguity around whether those line breaks are intended to render. I also think that any component that requires spacing within the JSX should be simplified.

I did pursue a way to fix this without this plugin via padding-line-between-statements but since Eslint core no longer takes styling changes I was bounced over here.

@ljharb
Copy link
Member

ljharb commented Sep 11, 2020

This might be a duplicate of #2630, which #2693 might solve?

@jsphstls
Copy link
Contributor Author

Thanks @ljharb , that issue and PR appear to add lines with no configuration options. My goal is the opposite.

The PR looks like good work though. I would not want to impede it by asking for more.

@ljharb
Copy link
Member

ljharb commented Sep 11, 2020

@jsphstls after that PR, can you help me understand what would you still be unable to do?

@jsphstls
Copy link
Contributor Author

@ljharb I would be unable to automatically remove extra lines around and between JSX elements.

Invalid:

return (

  <button/>

)

Valid:

return (
  <button/>
)

@ljharb
Copy link
Member

ljharb commented Sep 15, 2020

I see - so essentially, that PR adds jsx-newline which by default ensures lines, and you’d like a configuration option that removes them?

That seems like a reasonable option to add, either directly to that PR or as a follow up. Would you be interested?

@jsphstls
Copy link
Contributor Author

Sure, I can try it after that merge.

@lukasgjetting
Copy link

@jsphstls Did you make progress on this?

@jsphstls
Copy link
Contributor Author

@lukasgjetting thank for the reminder.

I am working on the MR to make this rule reversible. However, I am seeing some odd behaviour with the presence of &nbsp; that is making this tough to verify with my own local code. It seems to depend on the parser.

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