Skip to content

How to write AST selector to match only object key (and not also object value) ? #18320

Answered by lukasMega
lukasMega asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, I found solution finally.
I hope that this information will be beneficial to those who encounter it in the future.

✅ SOLUTION:

  • ObjectExpression> Property[computed=true] > MemberExpression.key

    • it's more specific
  • Property[computed=true] > :expression.key

    • more generic probably, definitely shorter.

✅ SOLUTION (final):

//update:
Thank you @fisker, it's even shorter and working as expected:

  • Property[computed=true] > .key

BTW this is nice place to try AST selector with ESLint, however it's for Typescript: https://typescript-eslint.io/play/...

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fisker
Comment options

Answer selected by lukasMega
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants