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

Phase out some overly prescriptive code rules: prefer-destructuring for array and object #957

Closed
monfera opened this issue Dec 28, 2020 · 3 comments · Fixed by #965
Closed
Labels
discuss To be discussed enhancement New feature or request

Comments

@monfera
Copy link
Contributor

monfera commented Dec 28, 2020

I think

const [r0] = r;

is less preferable than

const r0 = r[0];

and even if not, it doesn't buy anything. Also, while we should transition to ES2015, I don't see a reason for practically enforcing ES2015-only constructs, and currently, the resulting polyfill, where an ES5 construct exists which is often no worse and sometimes better.

I'm eager to learn if there's some justification. The rule description itself lists no benefits but points to clear drawbacks eg. when indexing arrays. I'm not fond of raising an info or warning for language constructs that seem perfectly legit, so such rules should ideally be activated upon shared conviction.

@monfera monfera added enhancement New feature or request discuss To be discussed labels Dec 28, 2020
@nickofthyme
Copy link
Collaborator

I think overall destructuring (both arrays and objects) is more beneficial from a reading perspective. But admittedly, it does get in the way at times, especially when reassigning values from an array.

// good
const [first, second] = array;

// bad
const first = array[0];
const second = array[1];

@monfera
Copy link
Contributor Author

monfera commented Jan 5, 2021

I agree @nickofthyme and have no plans to discourage the array destructuring, which is often much nicer such as in your example. So my current takeaway is that the linter isn't quite able to judge when one is better than the other, and the developer or code reviewer can. If the linter can't know while we can work out OK usages in what has sometimes grey areas, it ideally isn't enforced one way or the other by the linter

@nickofthyme
Copy link
Collaborator

Yup agreed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss To be discussed enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants