Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Remove comment attachment #736

Merged
merged 2 commits into from
Jan 11, 2019

Conversation

kaicataldo
Copy link
Member

fixes #707

ESLint no longer uses attached comments provided by the parser. This behavior has already been removed from the default parser. I also refactored some of this code to hopefully make it clearer/remove some commented out code.

"use strict";

// comment fixes
module.exports = function(ast, comments, tokens) {
Copy link
Member Author

@kaicataldo kaicataldo Jan 10, 2019

Choose a reason for hiding this comment

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

This is actually currently incorrectly named. Rather than doing comment attachment, it's actually calculating the location information for the top-level Program node. Renamed this to convertProgramNode and encapsulated all the logic of transforming the Program node to what ESLint expects in that function.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, much less confusing :)

Copy link
Member

@loganfsmyth loganfsmyth left a comment

Choose a reason for hiding this comment

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

Looks good to me! Both my comments are about existing code :)

test/specs/babel-eslint.js Outdated Show resolved Hide resolved
delete node.innerComments;
}

if (node.trailingComments) {
convertComments(node.trailingComments);
delete node.trailingComments;
Copy link
Member

Choose a reason for hiding this comment

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

Just for my own understanding, does ESLint just not used these properties?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right! We dropped the need for comment attachment to happen at the parser level in v4 (see docs here). We decided to move away from thinking about comments in the context of AST nodes (which had to be reimplemented by every parser and was buggy at best) and instead to just think of them in the context of tokens. ESLint now just takes the tokens and comments arrays provided by the parser and gives rules access to comments through the use of utility methods like sourceCode#getTokenBefore(nodeOrToken, { includeComments: true }).

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 talking to Kai about being able to turn off even adding the comments in @babel/parser but if the only use case is for babel-eslint we probably don't need to make that option then? Unless there's a case for it being much faster (would need to test)

Copy link
Member Author

@kaicataldo kaicataldo Jan 11, 2019

Choose a reason for hiding this comment

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

I could explore that - I haven't looked at how comment attachment works in @babel/parser in a long time now, but if it's not too crazy of a thing to add I'm happy to do it! That said, I don't think it needs to be tied to this release, since it won't result in any user-facing changes.

@kaicataldo kaicataldo merged commit b8126ce into babel:master Jan 11, 2019
@kaicataldo kaicataldo deleted the remove-comment-attachment branch January 11, 2019 17:23
nicolo-ribaudo pushed a commit to babel/babel that referenced this pull request Nov 14, 2019
* Remove comment attachment

* Simplify error messaging in tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove comment attachment
4 participants