New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Allow parsers to supply their own Visitor Keys to estraverse/eslint-scope #8392
Proposal: Allow parsers to supply their own Visitor Keys to estraverse/eslint-scope #8392
Comments
Also mentioned in the comment, but this would be beneficial both for the typescript parser and for babel-eslint. |
I think this might need TSC approval anyway, but fwiw I'm 👍 to this. |
@eslint/eslint-team Would love to hear what the rest of the team thinks about and whether or not we should include decorators in #8365. I'm happy to champion this and implement if we decide this is something we want and come up with an implementation we can agree on. |
I'm 👍 for allowing parsers to supply custom keys, but I don't think we should add explicit support for decorators. (Parsers could indicate that decorators should be traversed in |
Great! Pending TSC approval tomorrow, we just need to come up with a concrete proposal of how this should work! |
Can I suggest that we come up with a concrete proposal before the TSC approves this? In issues like #7416, we've run into problems where the TSC approved the general idea of doing something, but then we ran into design issues while implementing. I agree that this is generally a good idea, but I might not necessarily agree with any given proposal to address it. It seems like in general, the details of core proposals are important enough that the TSC should review them in addition to the vague core proposal. |
Yes! Sorry that wasn't clear - I wasn't suggesting we wait. |
Yeah, right now we do https://github.com/babel/babel-eslint/blob/f59d2009652e14acf1231a1268a8324cf046514e/index.js#L59-L61 And then we override methods like visitClass to visit decorators for the no-unused-vars/no-undef rule https://github.com/babel/babel-eslint/blob/f59d2009652e14acf1231a1268a8324cf046514e/index.js#L198-L199 Could just be an export: |
We could make it part of eslint api and create get/set or modify functions for VisitorKeys. Not sure if it would be a good idea to expose the eslint api to the parsers. It would allow for the parser to know which rules are loaded and possibly warn users of incompatibles or even supply extra details or hooks to certain rules. It might get overwhelming if start passing too much stuff through parser services but VisitorKeys seems like a good fit. |
I don't think exposing it as a mutable part of the eslint API is a good idea, because any given parser's modification will be exposed to any other module running eslint in the same process. (Admittedly that's also what happens now if we're monkeypatching estraverse directly, but I think it would be better to not do that.) Using parser services could be the way to go. |
I'm thinking good if we expose |
@mysticatea How would the parser be able to override the handlers of the referencer without monkey-patches? We still need a way for rules to traverse nodes, such as decorators and type parameters. I still thinking passing a VisitorKeys would be useful and extending the scoper is another issue. |
@mysticatea I'm curious how this would allow us to avoid monkey patching too - would each parser be required to implement its own scope analysis then? |
Thoughts on modifying eslint-scope's API to allow for handlers to be overridden/passed in? The parser could then provide the node handler functions which could then be passed through to eslint-scope. estraverse looks a little bit different. Unfortunately, the So, to summarize: seems like parsers should be able to supply an object with two options:
I'm new to this part of the project, so please bear with me! Edit: Ah, @soda0289 beat me to it: eslint/eslint-scope#30 |
My idea is: If a custom parser provides I thought the enhancement of only |
The TSC discussed this in the 2017-04-13 meeting and decided to postpone official approval until a more detailed proposal is available. |
I agree with @mysticatea position. Just |
The eslint-scope issue is another problem. I opened an issue for a possible fix here: eslint/eslint-scope#30. This proposal was not meant to fix all the problems of new syntax. It was just to allow eslint to traverse new node types. Right now you cannot write rules for Decorators or Type Parameters because they are children of known nodes. When we define VisitorKeys we don't set |
I think if we exposed a |
@soda0289 Feel free! Been pretty busy and would love to see this implemented :D |
It looks like we have a WIP PR with a proposal for this. Would be great to evaluate again. Related to this, I think we should revert the monkeypatching for type annotations we added a few weeks ago: #8584 |
We discussed this in the 2017-06-01 TSC meeting but did not come to a resolution. Is there a specific proposal that we can evaluate in light of #8582? |
This proposal is to just allow parser's to pass in VisitorKeys and I think VisitorFallback function makes sense too. |
@soda0289 I think we are just a bit lost as to exactly what is being proposed here, and how does that conflict/work with what @mysticatea is proposing. Just a summary of what the proposed changes are, and how will they help with preventing monkey-patching in estraverse/escope in the future, would really help us figure out what exactly are we approving:-) |
This proposal would allow parsers to pass in VisitorKeys and VisitorFallback function to escope and estraverse. This would be accomplished by adding two properties to the returned object from This would prevent the need to monkey patch the exported VisitorKeys from estravese, which is used by both eslint-scope and estraverse and possible other applications. This would allow eslint plugins to write rules for nodes that are children of known nodes as well as only traverse nodes that are known to be handled correctly. This proposal is not intended to remove the monkey patch of eslint-scope. It is just the first step towards improving support for parsers in eslint. If we want to remove the monkey patch to eslint-scope we have to either provide hooks for node listeners, provided plugins for new node types, or as @mysticatea suggested have parers provide their own scope anaylsis tool. In summary this proposal is just to allow eslint and its tools to traverse new node types and for rules to be written for decorators, type annotations, and type parameters. It will not fix the problems of eslint-scope handling unknown nodes. |
@eslint/eslint-tsc Would be great if we could decide on what we want to do here. This will make things much easier both for the typscript parser and babel-eslint. Ideally, we can live in a world where our parsers don't need to monkeypatch at all (we're seeing the pain points right now as babel-eslint has to now change its own monkeypatching behavior). |
* rewrite traverser * add supports scope and visitorKeys of custorm parsers * add tests * scope → scopeManager in the result of `parser.parseForESLint` * keys → visitorKeys * move some functions to `create()` in no-unmodified-loop-condition * check `this.sourceCode.ast` * fix SourceCode parameter to one object * update for review * update Traverser with eslint-visitor-keys * tweak tests with eslint-visitor-keys * add `eslintVisitorKeys` and `eslintScopeManager` to parserOptions * update docs * fix list style * ensure `sourceCode.scopeManager` is set * Docs: update ScopeManager docs * update for review * fix some links to escope docs * update for review * upgrade eslint-visitor-keys to 1.0.0
There are several node type's that currently do not get traversed when using parsers such as Babel or Typescript . These include Type Parameters, and Decorators. I believe we should define an API in eslint to modify the Visitor Keys for estraverse and eslint-scope. This would then allow parser's to pass in visitor keys using the parser services and eliminate the need for monkey patching or supporting experimental ecma features.
This was suggested by @kaicataldo to overcome the problems that traversing decorators would have caused
#8365 (comment)
The text was updated successfully, but these errors were encountered: