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

consistent-destructuring should report error when destructure same object twice #2364

Open
zanminkian opened this issue May 21, 2024 · 1 comment

Comments

@zanminkian
Copy link
Contributor

zanminkian commented May 21, 2024

1️⃣ Explain here what's wrong

Destructuring an object implies that this object will not be used later.

const {foo, bar} = baz;
// from then on, code below will not use `baz` any more

Therefore, consistent-destructuring will report error on the code

const {foo} = baz;

// ... other code

console.log(baz.bar); // will report error this line. it's expected

However, destructuring same object twice will not cause error, which is unexpected.

const {foo} = baz;

// ... other code

const {bar} = baz; // will not report error this line. it's unexpected
console.log(bar);

2️⃣ Specify which rule is buggy here and in the title

consistent-destructuring

3️⃣ Add some examples where the issue appears

const {foo} = baz;

// ... other code

const {bar} = baz;
console.log(bar);

eslint should report error on the code above when enabling consistent-destructuring.

@fregante
Copy link
Collaborator

👎

I think multiple destructuring are fine for the same reason why manual hoisting isn't preferred anymore: just create variables as needed, you don't need to create them all at the beginning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants