Skip to content

jsx-newline puts line breaks between comments and new JSX elements #3478

Closed
@Sreejit7

Description

@Sreejit7

I have the jsx-newline rule turned on, which when run with the --fix option, puts line breaks between any comments (including eslint-disable comments) and JSX elements, thus undoing the whole point of using comments.

Let's say I have something like this:

<Element as="header" marginBottom="micro">
        {/* eslint-disable-next-line react/jsx-sort-props */}
        <Heading as="h6" align="right">
            Transaction value
        </Heading>
<Element>

The jsx-newline rule puts a line break between the eslint-disable comment and , therefore causing the eslint-disable-{some rule} to stop working.

Can we handle putting line breaks between comments & new JSX elements?

I saw something similar in #2926 (which was closed earlier as completed) but that doesn't work properly as of v7.31.10

Activity

sujan-s

sujan-s commented on Nov 2, 2022

@sujan-s

To demonstrate the above comment—

What we need—
Screenshot 2022-11-02 at 12 04 03 PM

But what actually happens—
Screenshot 2022-11-02 at 12 04 17 PM

Which we obviously don’t want.

Webstorm adds each line as individual comments—which I’d say is a better approach to commenting—and I’d rather have this rule ignoring that.

ljharb

ljharb commented on Nov 2, 2022

@ljharb
Member

If this is new behavior in .10, then it’s a bug (cc @ROSSROSALES), and we should fix it.

Sreejit7

Sreejit7 commented on Nov 2, 2022

@Sreejit7
Author

@ljharb it's not a new behavior in .10, we were using 7.31.8, upgraded to .10

ROSSROSALES

ROSSROSALES commented on Nov 2, 2022

@ROSSROSALES
Contributor

@ljharb Thanks for pinging me, I can try and take a look into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @ljharb@sujan-s@ROSSROSALES@Sreejit7

      Issue actions

        `jsx-newline` puts line breaks between comments and new JSX elements · Issue #3478 · jsx-eslint/eslint-plugin-react