Skip to content

Conversation

@lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Oct 17, 2025

Part of #14564. Implement the remaining SourceCode APIs related to comments (getCommentsBefore, getCommentsAfter, getCommentsInside, commentsExistBetween).

@lilnasy lilnasy requested a review from camc314 as a code owner October 17, 2025 08:12
@lilnasy lilnasy requested review from Copilot and removed request for camc314 October 17, 2025 08:12
@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 17, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI C-enhancement Category - New feature or request labels Oct 17, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Introduce and test comment-related SourceCode APIs for JS plugins, replacing the previous single getAllComments fixture with a more comprehensive comments fixture.

  • Implement SourceCode.getCommentsBefore, getCommentsAfter, getCommentsInside, and commentsExistBetween
  • Add new test fixture “comments” with snapshot; remove old “getAllComments” fixture
  • Update e2e test to use the new fixture

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apps/oxlint/src-js/plugins/source_code.ts Implements the new comment-related APIs used by plugins.
apps/oxlint/test/e2e.test.ts Points the e2e test to the new “comments” fixture (currently marked it.only).
apps/oxlint/test/fixtures/comments/plugin.ts New test plugin exercising the new comment-related APIs.
apps/oxlint/test/fixtures/comments/output.snap.md Snapshot for the new comments fixture.
apps/oxlint/test/fixtures/comments/.oxlintrc.json Config enabling the new test plugin for the fixture.
apps/oxlint/test/fixtures/getAllComments/* Removes the old fixture, plugin, and snapshot tied to getAllComments.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@lilnasy lilnasy marked this pull request as draft October 17, 2025 08:20
@lilnasy lilnasy force-pushed the feat/linter/plugins/comments branch 2 times, most recently from 3b6e594 to 5b96e1f Compare October 17, 2025 13:14
Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Apologies that this review is premature - I know you're still working on it. But I was interested and had a look, so I thought I'd give my thoughts.

Background: In linter JS plugins, the JS-side code is going to be the slowest code in the whole path, so I'm keen to get it as tight and performant as it possibly can be. In most projects, readability and suchlike is also important, and it's normal to be a little loose, but here I think we should prioritise perf over all else.

(e.g. you'll see in the rest of the JS plugins code we never use if (!foo), we'll use the cheaper if (foo === false) or if (foo !== null) instead, depending on the type of foo)

That's the reason for my rather fanatical nit-picking!

Note: I think it's fine to leave binary search to a later PR, but I still feel it's helpful to tighten the algorithms as much as possible at this earlier stage.

@lilnasy lilnasy force-pushed the feat/linter/plugins/comments branch 3 times, most recently from 9d4fa3f to 60f0b14 Compare October 17, 2025 20:09
@lilnasy lilnasy marked this pull request as ready for review October 17, 2025 20:09
@overlookmotel
Copy link
Member

overlookmotel commented Oct 18, 2025

Great! Reviewing now (rebasing on latest main first).

@overlookmotel overlookmotel force-pushed the feat/linter/plugins/comments branch from 60f0b14 to 5fc0f23 Compare October 18, 2025 09:38
@overlookmotel
Copy link
Member

@lilnasy I'm really sorry, I've made a massive screw-up. While rebasing on main, it seems my local git client had cached the previous version (before you added the whitespace-checking logic). Now I've force-pushed and destroyed all that work.

Could you please force push the most recent version from your local copy, to restore the most recent version?

I'm really sorry. Totally stupid of me!

@overlookmotel overlookmotel force-pushed the feat/linter/plugins/comments branch from 5fc0f23 to 2a563b5 Compare October 18, 2025 10:11
@overlookmotel
Copy link
Member

overlookmotel commented Oct 18, 2025

OK, I think I've recovered the commits I over-wrote, and force pushed them back onto the PR branch. But can you please check I didn't lose anything in the process? Really sorry I've made a mess of this.

@overlookmotel
Copy link
Member

I'm still going through it. Have pushed a few commits - all just nits, except the last one.

Destructuring treats array as an iterator. Direct property access may be faster.
If there's no comments after `betweenRangeStart`, `betweenRangeEnd` is never accessed. So move it to where it's used.
@overlookmotel overlookmotel force-pushed the feat/linter/plugins/comments branch from 471dfc3 to 1aadc6d Compare October 18, 2025 11:31
Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Nice one! I had completely misunderstood what these methods are meant to do, because I hadn't looked at ESLint's implementation. Thank you for figuring out the correct logic.

I've pushed a bunch of commits, but they're all just style nits, perf micro-micro-optimizations, and increasing the test coverage. The logic is unaltered, and all seems correct.

I've not checked the output against ESLint, but I have been through the snapshot and checked it's correct according to my new understanding of what these methods are meant to do.

The only one of my commits which actually changed behavior is this one: 1aadc6d

Going to merge now, but please come back if you disagree with any of my changes.

@overlookmotel overlookmotel merged commit 9700a56 into oxc-project:main Oct 18, 2025
19 checks passed
@lilnasy lilnasy deleted the feat/linter/plugins/comments branch October 18, 2025 13:19
graphite-app bot pushed a commit that referenced this pull request Oct 18, 2025
…le (#14753)

Follow-on after #14715. Pure refactor. Move code for `SourceCode`'s comment-related methods into a separate file. Code is completely unchanged - it's just moved.
graphite-app bot pushed a commit that referenced this pull request Oct 18, 2025
Follow-on after #14715. I for one had completely misunderstood what the comments APIs are meant to do. Expand the docs for these methods to clarify their behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants