question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove `SourceCode#getComments()`

See original GitHub issue

The version of ESLint you are using.

ESLint 7.29.0 with Espree 8.0.0-beta.1

The problem you want to solve.

This test is failing:

https://github.com/eslint/eslint/blob/f113cdd872257d72bbd66d95e4eaf13623323b24/tests/lib/source-code/source-code.js#L909-L968

because sourceCode.getComments(node) uses start and end properties of nodes and tokens:

https://github.com/eslint/eslint/blob/f113cdd872257d72bbd66d95e4eaf13623323b24/lib/source-code/source-code.js#L351-L357

and after the change in https://github.com/eslint/espree/pull/461, Program.start is no longer 0 but body[0].start:

https://github.com/eslint/espree/blob/e08c9d78745fcee03136b57f46d09e11cad70861/lib/espree.js#L171

Your take on the correct solution to problem.

Remove SourceCode#getComments()?

It was deprecated in ESLint v4.0.0 (https://github.com/eslint/eslint/commit/735d02d570f4a2d3c663f0f4c6a6d4e4223aeb32):

Please note that the following methods have been deprecated and will be removed in a future version of ESLint:

  • getComments() - replaced by getCommentsBefore(), getCommentsAfter(), and getCommentsInside()

In ESLint v7.0.0, RuleTester was updated to throw on any access to start and end properties. Consequently, rules that use sourceCode.getComments() should have already noticed errors (e.g., https://github.com/eslint/eslint/issues/13293) and switched to other methods.

Are you willing to submit a pull request to implement this change?

Yes

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Jun 29, 2021

Throwing an error in RuleTester sounds good.

1reaction
nzakascommented, Jun 25, 2021

I’m not opposed to removing it but since we already locked down and announced the changes coming in v8.0.0, it seems like we should wait until v9.0.0 and maybe just add a deprecation warning in v8.0.0?

Read more comments on GitHub >

github_iconTop Results From Across the Web

remove comments from html source code - php - Stack Overflow
I know how to get the html source code via cUrl, but I want to remove the comments on the html document (I...
Read more >
Remove Comments - LeetCode
Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the i th...
Read more >
python - Remove comments from C-like source code
Given a file path represented as string, take this input string and remove all the comments in the file, print this file or...
Read more >
Fastest Way to Remove a Lot of Comments - YouTube
If you have multiple files to refactor and you also want to remove comments from code from all files quickly, its gonna be...
Read more >
Best practices for writing code comments - Stack Overflow Blog
If you're like most programmers, you sometimes use code that you find online. Including a reference to the source enables future readers to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found