eslint-plugin-sort-destructure-keys icon indicating copy to clipboard operation
eslint-plugin-sort-destructure-keys copied to clipboard

Throws error on dynamic destrcturing keys.

Open ckruppe opened this issue 2 years ago • 4 comments
trafficstars

The rule throws an error on dynamic key destructuring like so.

const {prop1, prop2, [propkey1]: prop3, [propkey2]: prop4} = object;

Whole eslint chokes on this line if sort-destructure-keys is active.

ckruppe avatar Apr 25 '23 17:04 ckruppe

The problem is this line: https://github.com/mthadley/eslint-plugin-sort-destructure-keys/blob/master/lib/rules/sort-destructure-keys.js#L57

Because node.key is undefined in this case.

If i rewrite this line like this. node?.key?.type then eslint does not die and everything works like expected. That you cant sort the last two keys is expected i think.

ckruppe avatar Apr 25 '23 17:04 ckruppe

Looks like we have test coverage for computed properties. I tried copying your example code into the tests, but didn't observe any errors.

@ckruppe Any other info you can provide, like which version of eslint you are running? Are you using a parser other than espree or @babel/eslint-parser?

mthadley avatar Apr 29 '23 20:04 mthadley

Sorry for the really late answer but did see the notification only now. Yes we use @typescript-eslint/parser. Unfortunately i don't have much more information, only what i have provided so far. If there is something i can do to get more information or a place you want me to look or try i am happy to help.

ckruppe avatar Jul 21 '23 18:07 ckruppe

@ckruppe No problem on the delayed response.

I took a look at reproducing errors with the code snippet you shared and @typescript-eslint/parser, but didn't have any luck. You can see the branch here, which has all tests passing using that parser.

Let me know if there's any additional context you can provide, as otherwise I can't reproduce the issue.

mthadley avatar Jul 22 '23 01:07 mthadley

Closing since it has been a while, but folks can open a new issue with more information if it is still happening.

mthadley avatar Apr 24 '24 03:04 mthadley