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 --fix" alters indentation on comments #649

Closed
rmtracey opened this issue Oct 6, 2016 · 6 comments

Comments

@rmtracey
Copy link

commented Oct 6, 2016

I'm trying out standard and I've noticed a bit of an odd behavior. It seems to enforce that all comments have a space before they start:

// like so

However, when I run "standard --fix" on my code, it will indent some comments that it fixes one or two extra times, like this, causing them to become misaligned with the code below them:

Before fixing:

code here
  //comment here
  code here

After fixing:

code here
    // comment here
  code here

This doesn't look right to me. Is this the intended behavior?

@rmtracey

This comment has been minimized.

Copy link
Author

commented Oct 6, 2016

I just realized that my comments were not being indented, it's that they were not being un-indented along with the rest of my code. Is there a way to apply the 2-space indenting rule to comments as well?

@timoxley

This comment has been minimized.

Copy link
Contributor

commented Oct 6, 2016

can you give a concrete example?

@feross

This comment has been minimized.

Copy link
Member

commented Oct 7, 2016

Space after // is an intentional rule:

// this is okay
//this is not okay

As for your other issue, you'll need to provide a code example where it happens before we can look into it.

@rmtracey

This comment has been minimized.

Copy link
Author

commented Oct 7, 2016

Of course, sorry about that. So, for example something like this (which uses 4 spaces for indentation):

const testFun = () => {
    //comment
    const test = 'test'
    return test
}

will be corrected to use 2 spaces, except for the comment:

const testFun = () => {
    // comment
  const test = 'test'
  return test
}

Just to clarify, I have no issue with the space after // rule, it's that the 2-spaces-for-indentation rule is causing some comments to become misaligned with code. I was just misunderstanding what was causing the misalignment at first.

@feross

This comment has been minimized.

Copy link
Member

commented Oct 7, 2016

@11tracer Thanks for the code example. You're right -- confirmed.

@feross feross added bug and removed need more info labels Oct 7, 2016

@feross

This comment has been minimized.

Copy link
Member

commented Oct 8, 2016

Turns out this is a longstanding issue in ESLint (eslint/eslint#3845). There's a rewrite of the indent rule underway (90% done) that will resolve this (eslint/eslint#7274).

So going to close this issue as there's nothing for us to do. We'll get the fix for free in a future ESLint version.

@feross feross closed this Oct 8, 2016

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

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