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

New: eslint-visitor-keys #1

Merged
merged 3 commits into from
Nov 16, 2017
Merged

New: eslint-visitor-keys #1

merged 3 commits into from
Nov 16, 2017

Conversation

mysticatea
Copy link
Member

This PR is the first implementation of eslint-visitor-keys.

Please review for direction.

Also, I'm not sure how I can setup scripts to release this package.
Please help me.

@ilyavolodin
Copy link
Member

Please don't merge this PR in yet. JSF prefers Apache license to MIT. So while we still don't have any code in the repository, it would be easier to change the license.

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

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

This generally looks good to me, I just have a few questions.

Also, I'm not sure how I can setup scripts to release this package.

It might only be necessary to add an eslint-release script (like this one in eslint-scope). It looks like Makefile.js in eslint-scope doesn't have anything related to the release.

README.md Outdated
For example:

```
console.log(evk.getKeys()) // → ["left", "right"]
Copy link
Member

Choose a reason for hiding this comment

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

Should this call have an argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, yes! This is a copy-paste mistake.

const KEYS = require("./visitor-keys.json");

// Types.
const NODE_TYPES = Object.freeze(Object.keys(KEYS));
Copy link
Member

Choose a reason for hiding this comment

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

Does NODE_TYPES need to be frozen? It seems like it's not exported.

(I suppose it's not a problem to freeze it either way.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Because of my liking. It clarifies that it's a constant.


it("should not have duplicate", () => {
assert(unionKeys.Program.filter(key => key === "body").length === 1);
});
Copy link
Member

Choose a reason for hiding this comment

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

Should we add tests for preserving the order of keys?

evk.unionWith({ CallExpression: ["callee"] }).CallExpression;

// ["callee", "arguments"]?
// ["arguments", "callee"]?

- fix the doc of `getKeys`
- clarify the order of keys for `unionWith`
@mysticatea
Copy link
Member Author

I update this PR to follow the review.

I rethought about the order of keys for unionWith(). Users need to control the order to traverse nodes from fore to back (e.g. decoratorskeyvalue).

@JamesHenry
Copy link
Member

Thanks for driving this, @mysticatea! I'll use this PR commit in my babel-eslint PR and see where we're at

@JamesHenry
Copy link
Member

@mysticatea Your freezing of the keys was very useful in flagging up a remaining case of mutation happening within babel-eslint.

The contents of this function are unchanged in my PR, but the file it is now in is different:

https://github.com/babel/babel-eslint/blob/64bd56509e41b31131ff08db882b261deb34d62d/lib/enhanced-referencer.js#L76-L110

// set ArrayPattern/ObjectPattern visitor keys back to their original. otherwise
    // eslint-scope will traverse into them and include the identifiers within as declarations
    extendedVisitorKeys.ObjectPattern = ["properties"];
    extendedVisitorKeys.ArrayPattern = ["elements"];
    // Execute default Referencer logic
    super.visitFunction(node);
    // set them back to normal...
    extendedVisitorKeys.ObjectPattern = t.VISITOR_KEYS.ObjectPattern;
    extendedVisitorKeys.ArrayPattern = t.VISITOR_KEYS.ArrayPattern;

What do you think about this? Should we try and expose an API in this new project for temporarily overriding keys adhoc like this? Or is there a better way?

@mysticatea
Copy link
Member Author

@JamesHenry Does it behave differently about patterns between inside of functions and outside of functions? I think super.visitFunction(node); visits the body of functions.

const {a} = obj // original visitor keys.

function foo() {
    const {a} = obj // overwritten visitor keys.
}

@JamesHenry
Copy link
Member

JamesHenry commented Sep 29, 2017

I don't know, I'm afraid. That PR is my first interaction with babel-eslint, and (eslint-scope's Referencer in general), and as I say this specific bit is not my code...

@JamesHenry
Copy link
Member

I will have much more time next week for open-source, I am a bit swamped right now

@mysticatea
Copy link
Member Author

Thanks. I think that we don't support temporarily overriding for keys in this repo. Traversing is recursive, so it causes unintentional behaviors in general.

@mysticatea
Copy link
Member Author

May I merge this?

@not-an-aardvark
Copy link
Member

👍

@mysticatea mysticatea merged commit a5a026b into master Nov 16, 2017
@mysticatea mysticatea deleted the new branch November 16, 2017 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants