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

Unexpected newline between object and [ of property access #1135

Closed
HoffmannP opened this issue May 16, 2018 · 4 comments

Comments

@HoffmannP
Copy link

commented May 16, 2018

What version of standard?
8.6.0

What operating system, Node.js, and npm version?

$ uname -a
Linux ber 4.8.0-58-generic #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ node --version
v7.10.1
$ npm --version
4.2.0

What did you do?
lint the following code

export class c {
  f (a) {
    let [b, c] = a
    [this.d, this.e] = b
    return [c]
  }
}

What did you expect to happen?
No error

What actually happened?

standard: Use JavaScript Standard Style (http://standardjs.com)
/tmp/test.js:4:5: Unexpected newline between object and [ of property access.
/tmp/test.js:4:12: Unexpected use of comma operator

@feross feross added the question label May 16, 2018

@feross

This comment has been minimized.

Copy link
Member

commented May 16, 2018

You need to use a leading semicolon before the array destructuring:

export class c {
  f (a) {
    let [b, c] = a
    ;[this.d, this.e] = b
    return [c]
  }
}

We should show a warning about this case. This looks like an ESLint bug to me.

(Leaving this issue open as a reminder to report this to the ESLint team.)

@feross feross added the accepted label May 16, 2018

@TheRauven

This comment has been minimized.

Copy link

commented Nov 18, 2018

It's been 6 months, and still nothing has been done to improve the error readability of Destructuring Assignments. I was confused by ESLint not recognizing it, until I finally found this thread

@feross feross changed the title Destructuring assignment to class members Unexpected newline between object and [ of property access Aug 13, 2019

@feross

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

@TheRauven Glad you figured out your issue.

@feross

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

Upon reconsideration, I actually think this error message is actually fine. ESLint sees the code as a property access and since we're omitting semis we know we need to add a leading semi. If anyone disagrees, feel free to file an upstream ESLint issue to attempt to make this clearer.

@feross feross closed this Aug 13, 2019

@feross feross added help wanted and removed accepted labels Aug 13, 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.