Support querying for nodes using the eslint node selector syntax from an individual node
See original GitHub issueThe version of ESLint you are using.
6.4.0
The problem you want to solve.
Want to be able to query for nodes using the eslint node selector syntax from a particular node, instead of the main visitor body callback, to make it easier to locate nodes that maybe relevant for writing descriptive error messages or fixes. Eslint already has an amazing selector syntax, so it would be great to be able to utilize it here too.
Currently, once you’re in the visitor, all the traversal has to be done manually.
Your take on the correct solution to problem.
Like how .querySelector()
exists not only for the document
but for every element in the DOM, I think that adding a similar method for each node would be nice. Another approach could be to add it to the context
object, something like context.queryNodes(rootNode, selector)
.
Are you willing to submit a pull request to implement this change?
Sure but could be easier for someone with a more intimate knowledge of ESLint internals
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
I really like this idea! I think it would be better to include it in the context object that’s passed to each rule (maybe on
SourceCode
)? Since this is a change to core, we’ll probably want to write up an RFC.Simplifying traversal of children nodes sounds really useful and would improve the DX of rules immensely.
Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.