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

object-curly-spacing possible bug with destructuring and trailing commas #2647

Closed
lencioni opened this issue May 31, 2015 · 8 comments · Fixed by DavidKindler/meteor#3 · May be fixed by iamstoick/javascript#11
Closed

object-curly-spacing possible bug with destructuring and trailing commas #2647

lencioni opened this issue May 31, 2015 · 8 comments · Fixed by DavidKindler/meteor#3 · May be fixed by iamstoick/javascript#11
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon

Comments

@lencioni
Copy link
Contributor

I have the following code:

const testing = { test: 1 };
let {
  test,
} = testing;

test++;

With the new object-curly-spacing rule set to always in ESLint 0.22.1, I see the following output:

3:6 error A space is required before ',' object-curly-spacing

I wasn't able to find any mention of this in the documentation for the rule, so I'm not sure if it was intentional or not, but it seems a bit strange to me so I thought it might be a bug.

Thanks for all of your great work on this tool!

@ilyavolodin ilyavolodin added the triage An ESLint team member will look at this issue soon label Jun 1, 2015
@ilyavolodin
Copy link
Member

I just verified it, and it does error out. However, I think the error is correct, the message is wrong though. I think it's erroring on a let statement, because with always keyword, you have to have a space after a comma. Now the message is saying that space is missing before the comma, so the message is clearly wrong.

@nzakas
Copy link
Member

nzakas commented Jun 1, 2015

Isn't this rule specifically about the curlies? Why would it care about commas at all?

@xjamundx
Copy link
Contributor

xjamundx commented Jun 1, 2015

I assume that's a typo, but will double check.

@xjamundx
Copy link
Contributor

xjamundx commented Jun 1, 2015

Here's what I get with 0.22.1:

  3:6  error  A space is required before ','       object-curly-spacing

Using this command eslint --env es6 --reset --rule '{object-curly-spacing: [2, "always"]}' test.js

Super weird!

@xjamundx
Copy link
Contributor

xjamundx commented Jun 1, 2015

Here's what up:

  1. We get the lastSpecifier (aka b in the case of var { a, b })
  2. Then we use last = context.getTokenAfter(lastSpecifier); to figure out the character after the lastSpecifier
  3. When then check that to see if it's or}
  4. We pass this to the reporter and it reads that character when it reports the error.

It wouldn't be hard to add explicit support for trailing commas, though I'm not actually sure how that would work here. I suppose we should just pretend the , is part of the specifier for the purposes of the rule.

xjamundx pushed a commit to xjamundx/eslint that referenced this issue Jun 1, 2015
xjamundx pushed a commit to xjamundx/eslint that referenced this issue Jun 1, 2015
@ilyavolodin
Copy link
Member

Hmmm.. I don't think adding explicit support for trailing commas would work. What about something like this:

{ name: something ? something : other }

or

{ name: name || "empty" }

It feels like we should find closing brace and check if the previous character is space.

@xjamundx
Copy link
Contributor

xjamundx commented Jun 1, 2015

I put together a quick PR which does it the way I described, feel free to comment in there with any feedback which I'll gladly apply

@ilyavolodin
Copy link
Member

Nevermind, I just checked the examples I wrote, and they all work fine.

ilyavolodin added a commit that referenced this issue Jun 2, 2015
Fix: trailing commas in object-curly-spacing (fixes #2647)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon
Projects
None yet
4 participants