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

Update: check renaming identifier in object destructuring (fixes 12827) #12881

Merged
merged 11 commits into from Feb 17, 2020

Conversation

yeonjuan
Copy link
Member

@yeonjuan yeonjuan commented Feb 6, 2020

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

What is the purpose of this pull request? (put an "X" next to an item)

[x] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

const { renamed: renaming} = foo;

Changed this rule to warn the length of the renaming identifier rather than a renamed identifier.

Is there anything you'd like reviewers to focus on?

Fixes #12827

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Feb 6, 2020
@yeonjuan yeonjuan added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Feb 6, 2020
lib/rules/id-length.js Outdated Show resolved Hide resolved
tests/lib/rules/id-length.js Show resolved Hide resolved
tests/lib/rules/id-length.js Outdated Show resolved Hide resolved
tests/lib/rules/id-length.js Outdated Show resolved Hide resolved
docs/rules/id-length.md Outdated Show resolved Hide resolved
tests/lib/rules/id-length.js Show resolved Hide resolved
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yeonjuan sorry for the confusion, I didn't mean to suggest to fix these 3 issues now.

Since you already fixed that, I think that 2 of those 3 changes are certainly correct at this moment.

var {x} = foo; might need a discussion as it could be undesirable for some users.

I left comments on tests cases for these 3 changes.

tests/lib/rules/id-length.js Show resolved Hide resolved
tests/lib/rules/id-length.js Outdated Show resolved Hide resolved
tests/lib/rules/id-length.js Outdated Show resolved Hide resolved
@mdjermanovic
Copy link
Member

Checked examples from the docs:

  • var { a: [x]} = {}; examples will be valid after this PR (without the other PR), maybe we should remove them from invalid sections, in this PR.
  • var { prop: a } = {}; in section Examples of incorrect code for this rule with the { "min": 4 } option: is now invalid.
  • In the same section, var foo = function (event) { /* do stuff */ }; is also invalid. that was probably a mistake in the docs.
  • In the same section, obj.element = document.body; and ({ prop: obj.name } = {}); are both invalid on obj. That was probably broken in the code. Not sure what should we do with this, maybe leave for another PR.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

tests/lib/rules/id-length.js Show resolved Hide resolved
@@ -89,8 +91,7 @@ class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a regression in this PR? I see that this is going to be worked on in a separate PR. Do we have an issue outlining our plan for this (just in case someone else needs to pick this work up)?

Copy link
Member Author

@yeonjuan yeonjuan Feb 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaicataldo

Is this a regression in this PR?

Yes. The case will not be warned after this PR merged because the actual version warns about a rather than x.

/*eslint id-length: ["error", { "min": 4 }]*/
/*eslint-env es6*/

var { a: [x]} = {}; // Error: Identifier name `a` ...

And there is a PR working on to fix it (#12839).

Do we have an issue outlining our plan for this (just in case someone else needs to pick this work up)?

I will add an outlining plan for this on #12832. Thanks 👍

@kaicataldo
Copy link
Member

Thanks for working on this!

@kaicataldo kaicataldo merged commit 77df505 into master Feb 17, 2020
@kaicataldo kaicataldo deleted the issue12827 branch February 17, 2020 17:06
@kaicataldo
Copy link
Member

Thanks for contributing!

montmanu pushed a commit to montmanu/eslint that referenced this pull request Mar 4, 2020
…7) (eslint#12881)

* Update: check renaming identifier in object destructuring (fixes 12827)

* Fix wrong error type

* ignore properties options on object pattern, ignore computed prop

* modify docs, add test cases

* add test cases

* remove wrong test cases

* change to ignore destructuring on properties never

* update documentation

* fix typo

* fix documentation

* include error loc, data info
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 17, 2020
@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 Aug 17, 2020
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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

id-length should warn about the renamed identifier length in the destructuring assignment.
3 participants