Skip to content
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

Merged
merged 1 commit into from May 20, 2020

Conversation

ilyavolodin
Copy link
Member

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

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

@jsf-clabot
Copy link

jsf-clabot commented May 15, 2020

CLA assistant check
All committers have signed the CLA.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label May 15, 2020
@mysticatea
Copy link
Member

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.

@ilyavolodin
Copy link
Member Author

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.

@mysticatea
Copy link
Member

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?

@ilyavolodin
Copy link
Member Author

@mysticatea I updated the code to stop code path analysis all together if top level node is not Program. I also added unit test to cover this scenario. I also left the old code, just in case, top level node is Program, but followed by unknown nodes. Shouldn't hurt anything anyways.

@mysticatea
Copy link
Member

Thank you.

Looks the linter does nothing at all if the root node is not a Program. I guess it's not intentional.

@ilyavolodin
Copy link
Member Author

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.

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

Copy link
Member

@kaicataldo kaicataldo left a 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 👍

@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features and removed triage An ESLint team member will look at this issue soon labels May 20, 2020
@kaicataldo
Copy link
Member

Marking as accepted since we have the approval of 3/4 of the TSC.

@kaicataldo kaicataldo merged commit 68c8ee3 into eslint:master May 20, 2020
@ilyavolodin ilyavolodin deleted the code-path-analyzer-fix branch May 21, 2020 02:44
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 17, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants