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

rule object-shorthand "never" should not complain about destructuring assignment #5488

Closed
attekemppila opened this issue Mar 6, 2016 · 8 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@attekemppila
Copy link

What version of ESLint are you using?
v2.3.0

What configuration and parser (Espree, Babel-ESLint, etc.) are you using?
Espree

What did you do? Please include the actual source code causing the issue.

/* eslint-env es6 */
/* eslint object-shorthand: [2, "never"] */

// object initializer

let a = 1, b = 2;

let o = {
    a: a,
    b,                  // object-shorthand error, as expected
    fb: function() {},
    fa() {}             // object-shorthand error, as expected
}


// destructuring assignment

let {a, b} = o;  // object-shorthand error, not expected

let arr = [{a: 1, b: 1}, {a: 2, b: 2}];

for (let {a, b} of arr) {}  // object-shorthand error, not expected

What actually happened? Please include the actual, raw output from ESLint.

  10:5   error  Expected longform property syntax  object-shorthand
  12:5   error  Expected longform method syntax    object-shorthand
  18:6   error  Expected longform property syntax  object-shorthand
  18:9   error  Expected longform property syntax  object-shorthand
  22:11  error  Expected longform property syntax  object-shorthand
  22:14  error  Expected longform property syntax  object-shorthand

✖ 6 problems (6 errors, 0 warnings)

What did you expect to happen?
Rule object-shorthand "never" should not complain about destructuring assignment. Lines 18 and 22 in the example should not produce error.

@alberto alberto added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Mar 6, 2016
@alberto alberto added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed accepted There is consensus among the team that this change meets the criteria for inclusion labels Mar 6, 2016
@alberto
Copy link
Member

alberto commented Mar 6, 2016

Maybe I was too quick to label it as a bug, since I just realized you can also use the long form for destructuring too:

let {a: a, b: b} = o;

for (let {a:a, b:b} of arr) {}

Not sure if this should be an option, though.

ilyavolodin added a commit that referenced this issue Mar 7, 2016
Fix: Ignore destructuring assignment in `object-shorthand` (fixes #5488)
@michaelficarra
Copy link
Member

So... there's no way to get the old behaviour? This probably should have been left in as an option.

@alberto
Copy link
Member

alberto commented Mar 7, 2016

Sorry, it's my bad this got merged before we agreed on a decision. :/

@eslint/eslint-team should this rule deal with shorthand in destructuring assignments or is this rule only concerned about object literals?

@ilyavolodin ilyavolodin reopened this Mar 7, 2016
@ilyavolodin
Copy link
Member

Going to reopen this issue. Sorry, my bad for not double-checking issue before merging code change (I actually did a few times and didn't merge the code, but this time around, I forgot).

@BYK
Copy link
Member

BYK commented Mar 7, 2016

👍 to @michaelficarra

@mysticatea
Copy link
Member

I read the doc, object-shorthand was a rule about object literals (object initializers). So I think making the rule covering destructuring assignments is an enhancement.

Though I don't have any objection, I'd like to separate it to a new issue.

@nzakas
Copy link
Member

nzakas commented Mar 9, 2016

Agree with @mysticatea. This rule was checking destructuring by default and it should not have. I'm unsure about an option vs. a new rule, but agree that should be a separate issue.

@alberto alberto added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Mar 11, 2016
@alberto
Copy link
Member

alberto commented Mar 11, 2016

Closing then, since this was indeed a bug.

@alberto alberto closed this as completed Mar 11, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

7 participants