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

Breaking: align babel-eslint-parser & espree #11137

Merged
merged 4 commits into from Feb 20, 2020

Conversation

kaicataldo
Copy link
Member

@kaicataldo kaicataldo commented Feb 13, 2020

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change? 👍
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

As I was switching our test suite to use Jest, I noticed that we're not checking for extraneous properties on nodes. I'm still looking into which properties might be useful to keep (even if they're not defined by ESTree), but this way we can be explicit about what extra properties we decide to keep.

This is a breaking change because it's removing some properties from nodes in the @babel/eslint-parser AST.

delete node.extra;
}

if (node.loc && Object.hasOwnProperty.call(node.loc, "identifierName")) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Seems unlikely ESLint would need this, but please let me know if I'm wrong. I also don't see this referenced anywhere in eslint-plugin-flowtype.

const node = path.node;
const { node } = path;

if (Object.hasOwnProperty.call(node, "extra")) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Seems unlikely ESLint would need this, but please let me know if I'm wrong. I also don't see this referenced anywhere in eslint-plugin-flowtype.

Copy link
Contributor

@JLHwung JLHwung Feb 19, 2020

Choose a reason for hiding this comment

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

AFAIK node.extra is only used internally in babel-parser. It is a collection of per-node parser features, parenthesized, trailingComma, etc. So we can safely remove node.extra.

I think we can even remove the hasOwnProperty guard then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, thanks!

ast.body = ast.program.body;
delete ast.program;
delete ast.errors;
Copy link
Member Author

Choose a reason for hiding this comment

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

Extra property that ESLint doesn't use (though we are planning to implement a top-level recoverableErrors property - you can find more info here).

@kaicataldo kaicataldo force-pushed the use-jest-babel-eslint branch 2 times, most recently from 990e31f to 0ca7c3b Compare February 13, 2020 03:58
@kaicataldo kaicataldo changed the title Chore: align babel-eslint-parser & espree Breaking: align babel-eslint-parser & espree Feb 13, 2020
@@ -31,7 +31,6 @@
"@babel/core": "^7.2.0",
"@babel/eslint-shared-fixtures": "*",
"eslint": "^6.0.1",
"espree": "^6.0.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Thoughts on this? Seems like we should ensure we're using the version of Espree that's included with the version of ESLint we're testing against.

Copy link
Member

Choose a reason for hiding this comment

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

i think it should be a combo peer dep and dep, that way npm ls will fail (and npm install in npm 7+) when the peer dep isn't met.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Now that we use require.resolve to get ESLint's dep, this shouldn't be needed anymore.

@@ -107,12 +107,7 @@ function convertProgramNode(ast) {
if (ast.comments.length) {
const lastComment = ast.comments[ast.comments.length - 1];

if (!ast.tokens.length) {
// if no tokens, the program starts at the end of the last comment
Copy link
Member Author

Choose a reason for hiding this comment

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

This behavior doesn't match Espree's (it probably did at one point and has since changed).

@@ -306,13 +306,11 @@ describe("Babel and Espree", () => {
expect(babylonAST.tokens[3].value).toEqual("#");
});

// eslint-disable-next-line jest/no-disabled-tests
it.skip("empty program with line comment", () => {
it("empty program with line comment", () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is now aligned! 🎉

@kaicataldo kaicataldo added PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: eslint area: estree labels Feb 13, 2020
nicolo-ribaudo
nicolo-ribaudo previously approved these changes Feb 13, 2020
@nicolo-ribaudo nicolo-ribaudo dismissed their stale review February 13, 2020 23:22

I didn't meant to approve, I haven't reviewed yet 😅

const ALLOWED_PROPERTIES = [
"importKind",
"exportKind",
"variance",
Copy link
Member Author

Choose a reason for hiding this comment

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

This is used in eslint-plugin-flowtype.

"importKind",
"exportKind",
"variance",
"typeArguments",
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not used in eslint-plugin-flowtype. Should we remove this?

Copy link
Member

Choose a reason for hiding this comment

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

I think that we should keep it: if espree doesn't support flow, we don't need to align in this case.

configFile: require.resolve(
"@babel/eslint-shared-fixtures/config/babel.config.js",
),
};
const ALLOWED_PROPERTIES = [
"importKind",
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm assuming we want to leave importKind and exportKind since they might be useful for Flow-related ESLint rules. exportKind is already used in eslint-plugin-flowtype, so it seems like we should include both properties.

Copy link
Member

Choose a reason for hiding this comment

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

eslint-plugin-import definitely uses these.

Copy link
Member

Choose a reason for hiding this comment

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

We might want to add tests for third-party ESLint plugins in the e2e Circle CI workflow.

@nicolo-ribaudo
Copy link
Member

@kaicataldo The failing tests are related to the changes in this PR.

@kaicataldo
Copy link
Member Author

kaicataldo commented Feb 20, 2020

Yikes, had a bad rebase or something and lost a bunch of the changes 🤦‍♂. Fixing up now.

Edit: I see what I did now. I had an outdated branch on another machine and rebased and force pushed. Oof.

Edit 2: TIL about –force-with-lease (thanks @nicolo-ribaudo!)

@kaicataldo
Copy link
Member Author

reflog for the win!

const node = path.node;

// private var to track original node type
node._babelType = node.type;
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering why we had this in the first place, but a quick search on GitHub (search) shows that it's only used in snapshot tests output: it can be safely removed.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

It still looks good!

@nicolo-ribaudo nicolo-ribaudo merged commit 3960f4d into babel:master Feb 20, 2020
@kaicataldo kaicataldo deleted the use-jest-babel-eslint branch February 20, 2020 21:07
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: eslint area: estree outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants