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

Standard(ESLint?) cannot decide on how many spaces are needed for a JSX Component #1196

Closed
akatechis opened this issue Sep 7, 2018 · 7 comments

Comments

@akatechis
Copy link

commented Sep 7, 2018

What version of standard? 11.0.1

What operating system, Node.js, and npm version?
Windows 10, Node 10.0.0, NPM 6.1.0

What did you expect to happen?
I expect indentation to be 6 spaces for the line with the href prop.

What actually happened?
Standard (or ESLint?) cannot decide whether the indentation should be 6 or 8 spaces for the following example:

export default function MyComponent () {
  return (
    <div>
      <a onClick={(event) => {
        event.preventDefault()
      }}
        href=''>Send again</a>.
    </div>
  )
}

Initially, it correctly tells me it expects 6 spaces for the href line. I change it to 6, and it marks the same line, saying it expects 8.

@akatechis

This comment has been minimized.

Copy link
Author

commented Sep 7, 2018

Looks like changing the onClick handler to be a single expression function body without curly braces fixes the issue:

export default function MyComponent () {
  return (
    <div>
      <a onClick={(event) => event.preventDefault()}
        href=''>Send again</a>.
    </div>
  )
}
@LinusU

This comment has been minimized.

Copy link
Member

commented Sep 7, 2018

Have you tried it with Standard v12?

@akatechis

This comment has been minimized.

Copy link
Author

commented Sep 7, 2018

Issue still exists in 12.0.1

@stale

This comment has been minimized.

Copy link

commented Dec 6, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Dec 6, 2018

@akatechis

This comment has been minimized.

Copy link
Author

commented Dec 6, 2018

This issue has not been fixed, since reported.

@stale stale bot removed the stale label Dec 6, 2018

@stale

This comment has been minimized.

Copy link

commented Mar 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Mar 6, 2019

@stale stale bot closed this Mar 13, 2019

@lock lock bot locked as resolved and limited conversation to collaborators Jun 12, 2019

@feross

This comment has been minimized.

Copy link
Member

commented Aug 12, 2019

@akatechis I think that ESLint is behaving correctly in your code sample. The onClick attribute appears at an indentation of 6, so it expects all attributes to appear with the same indentation level. Here's what I would write:

export default function MyComponent () {
  return (
    <div>
      <a
        onClick={(event) => {
          event.preventDefault()
        }}
        href=''
      >
        Send again
      </a>.
    </div>
  )
}

Or better:

export default function MyComponent () {
  return (
    <div>
      <a
        onClick={event => event.preventDefault()}
        href=''
      >
        Send again
      </a>.
    </div>
  )
}

@standard standard unlocked this conversation Aug 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.