eslint-plugin-sort-destructure-keys
eslint-plugin-sort-destructure-keys copied to clipboard
Throws error on dynamic destrcturing keys.
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.
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.
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?
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 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.
Closing since it has been a while, but folks can open a new issue with more information if it is still happening.