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: remove attachComment option #394

Closed
kaicataldo opened this issue Oct 25, 2018 · 6 comments · Fixed by #405
Closed

Breaking: remove attachComment option #394

kaicataldo opened this issue Oct 25, 2018 · 6 comments · Fixed by #405
Assignees

Comments

@kaicataldo
Copy link
Member

TSC Summary: Now that ESLint does not use the attachComment option and given its buggy nature and maintenance cost, I think we should remove the option from Espree.

TSC Question: This is a breaking change, however I suspect that very few other projects are using this option.

I'm more than happy to do the work if this is accepted.

@kaicataldo kaicataldo self-assigned this Oct 25, 2018
@kaicataldo kaicataldo changed the title Breaking: remove comment attachment option Breaking: remove attachComment option Oct 25, 2018
@btmills
Copy link
Member

btmills commented Nov 8, 2018

We discussed this in today's TSC meeting and approved it with no objections. Since this doesn't affect ESLint, it doesn't need to wait for a major release of ESLint. Thanks for volunteering to do the work, @kaicataldo!

@nfroidure
Copy link

nfroidure commented Jan 12, 2019

FYI I was using it for this project https://github.com/nfroidure/jsarch and faced the issue when bumping. I replaced the default parser by @babel/parser but I would like to know which way you recommend to parse projects for comments now?

@platinumazure
Copy link
Member

@nfroidure espree still parses comments- they're just stored in a comments array rather than attached directly to nodes. You can iterate through all comments pretty easily. Looking for comments "near nodes" is a bit harder, but still possible: If you are using range info on nodes (and tokens and comments), you could get all comments that start before/after the node you're looking at and see all comments that might have been attached to the node in the old comment attachment strategy.

You could also look at ESLint's token store utilities to get an idea of how ESLint manages this information internally.

@benmosher
Copy link

Ah bummer, I was also using it for eslint-plugin-import to detect/report deprecated imported names. but I totally get your motivation. will work around it using top-level comments array 👍

@kaicataldo
Copy link
Member Author

@benmosher You can still use methods on the SourceCode object returned by context.getSourceCode() to find comments based on their location relative to a given node or token (namely getCommentsBefore(nodeOrToken), getCommentsAfter(nodeOrToken), and getCommentsInside(node)). See the docs here for more details and feel free to stop by the Gitter if something isn't clear!

@aminya
Copy link

aminya commented Apr 25, 2021

For those who need this, I have registered the latest Espree with this feature:
https://www.npmjs.com/package/espree-attachcomment

npm install espree-attachcomment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants