sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positive for consistent-destructuring

crystalfp opened this issue · comments

In the code below, the rule suggest to use destructuring but does not suggest a way to fix the problem. In my opinion this is a perfectly valid destructuring and a possible change makes the code unclear. The code is:

const structure = {
    atoms: [{position: [1,2,3]}]
};
const {position} = structure.atoms[0];

The rule complains to the last line. One way to satisfy the rule is to change the last line into:

const {atoms} = structure;
const {position} = atoms[0];

That is much less clear that the first code.

consistent-destructuring

The example is above in the first section.

const code = 'that should be ok';

const structure = {
    atoms: [{position: [1,2,3]}]
};
const {position} = structure.atoms[0];

That's not a false positive, it works as intended.

However we agree that the rule is not always ideal so it was recently removed from the "recommended" config: