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

Fix: handle parenthesized chaining expression in prefer-destructuring #13910

Closed
wants to merge 1 commit into from

Conversation

yeonjuan
Copy link
Member

@yeonjuan yeonjuan commented Dec 6, 2020

Prerequisites checklist

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

[ ] 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)

The current version, prefer-destructuring warns following cases.

/* eslint prefer-destructuring: ["error", {
      "array": true,
      "object": true
    }, {
      "enforceForRenamedProperties": false
    }]*/

var bar = (object?.foo).bar; // Error
var bar = (object?.foo()).bar; // Error
var bar = (object?.foo?.()).bar; // Error
bar = (object?.foo).bar; // Error
bar = (object?.foo)[0]; // Error
bar = (object?.foo()).bar; // Error
bar = (object?.foo())[0]; // Error

But as described in this comment, it would occur TypeError when auto fixed.
This PR change "prefer-destructuring" to ignore those cases.

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

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Dec 6, 2020
@eslint-deprecated
Copy link

Hi @yeonjuan!, thanks for the Pull Request

The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag must be one of the following:

    The Tag is one of the following:

    • Fix - for a bug fix.
    • Update - either for a backwards-compatible enhancement or for a rule change that adds reported problems.
    • New - implements a new feature.
    • Breaking - for a backwards-incompatible enhancement or feature.
    • Docs - changes to documentation only.
    • Build - changes to build process only.
    • Upgrade - for a dependency upgrade.
    • Chore - for anything that isn't user-facing (for example, refactoring, adding tests, etc.).

    You can use the labels of the issue you are working on to determine the best tag.

  • There should be a space following the initial tag and colon, for example 'New: Message'.

  • The first letter of the tag should be in uppercase

Read more about contributing to ESLint here

@yeonjuan yeonjuan changed the title fix: handle parenthesized chaining expression in prefer-destructuring Fix: handle parenthesized chaining expression in prefer-destructuring Dec 6, 2020
@mdjermanovic mdjermanovic added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Dec 6, 2020
@mdjermanovic
Copy link
Member

I'm not sure if this is a bug, the fixed examples seem equivalent to their original versions. In particular, the original code would also throw a TypeError if object is nullish?

My concern in #13431 (comment) was that no-unsafe-optional-chaining should report both versions. Since we implemented that no-unsafe-optional-chaining reports var {bar} = object?.foo, the actual behavior of prefer-destructuring looks okay to me.

@yeonjuan
Copy link
Member Author

yeonjuan commented Dec 7, 2020

@mdjermanovic Oh..Right. It was completely my misunderstanding I'll close this PR Thanks

@yeonjuan yeonjuan closed this Dec 7, 2020
@yeonjuan yeonjuan added works as intended The behavior described in this issue is working correctly and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules labels Dec 7, 2020
@yeonjuan yeonjuan deleted the handle-op-chain-stopping branch December 7, 2020 00:59
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jun 6, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 6, 2021
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 works as intended The behavior described in this issue is working correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants