Skip to content

[Bug]: react/jsx-newline does not remove empty lines for surrounding tags #3663

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
2 tasks done
sspenst opened this issue Dec 6, 2023 · 2 comments · May be fixed by #3678
Open
2 tasks done

[Bug]: react/jsx-newline does not remove empty lines for surrounding tags #3663

sspenst opened this issue Dec 6, 2023 · 2 comments · May be fixed by #3678

Comments

@sspenst
Copy link

sspenst commented Dec 6, 2023

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

react/jsx-newline with { "prevent": true } does not remove empty lines for surrounding tags.

Currently react/jsx-newline does not detect any lint errors for the following JSX:

<div>

  <span>
    hi
  </span>

</div>

Expected Behavior

The current detection feels like unintended behavior, as I would expect all newlines within JSX to be removed as follows:

<div>
  <span>
    hi
  </span>
</div>

If there is a different eslint rule that checks for this please let me know!

eslint-plugin-react version

v7.33.2

eslint version

v8.55.0

node version

v18.6.0

@sspenst sspenst added the bug label Dec 6, 2023
@sspenst sspenst changed the title [Bug]: [Bug]: react/jsx-newline does not remove empty lines for surrounding tags Dec 6, 2023
@burtek
Copy link
Contributor

burtek commented Jan 11, 2024

Works as expected? The rule adds/removed newlines between adjacent JSX elements and expressions.

That being said, it might be reasonable to add option to also check newlines at start and end of element's children 🤔

@ljharb

@ljharb
Copy link
Member

ljharb commented Jan 11, 2024

I think it's a reasonable interpretation that <div> and <span> are adjacent lexically, even if they're not adjacent hierarchically, and newlines are a lexical concern.

To avoid a breaking change, we'd need to add a new option for this.

# for free to join this conversation on GitHub. Already have an account? # to comment
3 participants