Skip to content

refactor: don't use parent property in NodeEventGenerator#18653

Merged
nzakas merged 3 commits intomainfrom
nodeeventgenerator-parent
Jul 5, 2024
Merged

refactor: don't use parent property in NodeEventGenerator#18653
nzakas merged 3 commits intomainfrom
nodeeventgenerator-parent

Conversation

@mdjermanovic
Copy link
Copy Markdown
Member

@mdjermanovic mdjermanovic commented Jul 4, 2024

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:

Refs #16999, eslint/json#4 (comment)

With the current version of ESLint, selectors like Element > String or Element + Element don't work with the @eslint/json language plugin as ESLint passes an empty ancestry to esquery because the calculations in NodeEventGenerator are based on the parent property of nodes, but JSON AST nodes don't have this property.

What changes did you make? (Give an overview)

Refactored NodeEventGenerator to not use the parent property of nodes because language plugins are not required to produce this property in AST.

The code change is that, instead of adding node's parent to the ancestry when entering the node, enterNode now adds the node itself to the ancestry for subsequent calls of enterNode for the node's subtree.

Is there anything you'd like reviewers to focus on?

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

archived due to age This issue has been archived; please open a new issue for any further discussion chore This change is not user-facing core Relates to ESLint's core APIs and features

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants