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

Help wanted: Spacing between tags #2630

Closed
rumenpetrov opened this issue Apr 23, 2020 · 3 comments · Fixed by #2693
Closed

Help wanted: Spacing between tags #2630

rumenpetrov opened this issue Apr 23, 2020 · 3 comments · Fixed by #2693

Comments

@rumenpetrov
Copy link

rumenpetrov commented Apr 23, 2020

Hi everybody, I am searching for hours and I really can't find a solution to my problem. I will appreciate if somebody can help me with this.
My problem is related to tag formatting and spacing.
I need a rule that will enforce adding newlines between siblings.

Bad:

<div>
  <Button>{data.label}</Button>
  <List />
  <Button>
    <IconPreview /> 
    Button 2
  </Button>
  {showSomething === true ? (
    <Something />
  )}
  <Button>Button 3</Button>
  {showSomething === true ? (
    <Something />
  ) : (
    <ErrorMessage />
  )}
</div>

Good:

<div>
  <Button>{data.label}</Button>

  <List />

  <Button>
    <IconPreview /> 
    Button 2
  </Button>

  {showSomething === true ? (
    <Something />
  )}

  <Button>Button 3</Button>

  {showSomethingElse === true ? (
    <SomethingElse />
  ) : (
    <ErrorMessage />
  )}
</div>

I search in the prettier's rules, eslint's rules, everywhere and I am not finding it. If anybody knows a rule like this or point me to something I will be grateful.

@ljharb
Copy link
Member

ljharb commented Apr 24, 2020

I don't think there's a rule for this anywhere. It might be reasonable. What would it be called, and how would it be configured? Would it apply to any jsx in any context? How would it interact with text nodes (as opposed to elements), as well as inline JS expressions?

@rumenpetrov
Copy link
Author

rumenpetrov commented Apr 24, 2020

@ljharb thank you for the quick response. Overall I see this as something really similar to 'padding-line-between-statements', maybe even as an extension of this rule.
About the context, I see it as any JSX in any context, but I am not really sure that I understand what you mean with this. If you have in mind certain situations that this may cause problems we can restrict some of the contexts for sure.
About the text nodes, I think we don't need new lines before or after them, but this could be a possible configuration option.
About the expressions, I added more cases to my initial example, I hope it makes more sense now.

@ljharb
Copy link
Member

ljharb commented May 9, 2020

I'd be interested to review a PR for this rule.

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.

2 participants