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
Fix: Stop path analyzer on unknown nodes #13305
Conversation
Thank you. Hmm. I guess, the analyzer still may crash on a node that has the same type name as one of the ESTree nodes. I think better if we expose a flag for custom parsers to disable code path analysis and modify lib/linter/linter.js#L941. |
Sure, that would probably be ideal way to fix this. This is just a very quick fix to unblock linting unknown nodes. Since a new flag from parser would require RFC and a bunch of code changes, could we merge this one in first, and I will create an RFC for supporting generic ASTs (was planning on doing that anyways), which will include this flag as well as few more things. |
My concern is that this patch is incomplete; if the root node is not Program and the tree contains the node that is the same type as any of ESTree nodes, then the analyzer still can crash. I'd like to stop instantiating the analyzer rather than modifying the inside of the analyzer. How about, stop instantiating the analyzer if the root is not a Program? |
fd19e6a
to
0da2123
Compare
@mysticatea I updated the code to stop code path analysis all together if top level node is not |
Thank you. Looks the linter does nothing at all if the root node is not a Program. I guess it's not intentional. |
0da2123
to
dd6e2a9
Compare
Ah, sorry about that. Not sure what I was thinking. Updated with the right code. Should be working fine now. Updated unit test also to verify that it's actually running rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Glad we were able to get to a more complete PR 👍
Marking as accepted since we have the approval of 3/4 of the TSC. |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Updated code path analyzer to bail if no known ESTree nodes are found in AST. I'm trying to get ESLint to work with syntaxes other then ESTree and this is one place where it throws an error, since all the AST nodes are hardcoded in code-path-analyzer and can't be supplied by the parser. Unfortunately, it would be very tricky to create a unit test for this, and since this is a one-line change that shouldn't affect happy path, I figured it would be OK without unit test.
Is there anything you'd like reviewers to focus on?
Nope