Skip to content

Conversation

@lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Nov 24, 2025

Tasks:

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Nov 24, 2025
@lilnasy lilnasy force-pushed the isSpaceBetween branch 4 times, most recently from 5ceb6d8 to 598e16d Compare November 26, 2025 22:01
@lilnasy lilnasy marked this pull request as ready for review November 26, 2025 22:25
Copilot AI review requested due to automatic review settings November 26, 2025 22:25
@lilnasy lilnasy changed the title refactor(linter/plugins): reimplement isSpaceBetween using tokens refactor(linter/plugins): reimplement isSpaceBetween() isSpaceBetweenTokens() using tokens Nov 26, 2025
Copilot finished reviewing on behalf of lilnasy November 26, 2025 22:29
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

This PR refactors the isSpaceBetween and isSpaceBetweenTokens functions to use a token-based implementation instead of checking whitespace in the source code directly. This fixes issues where the previous implementation incorrectly returned true for cases like x+" "+y where the whitespace is inside a string token, not between tokens.

Key changes:

  • Reimplemented both functions to iterate through tokens and check for gaps between them using binary search
  • Fixed incorrect behavior where whitespace inside tokens (like string literals or JSXText) was counted as space between nodes
  • Removed outdated comments explaining known bugs that are now fixed

Reviewed changes

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

Show a summary per file
File Description
apps/oxlint/src-js/plugins/tokens.ts Reimplemented isSpaceBetween() and isSpaceBetweenTokens() using token-based iteration with binary search; removed unused initSourceText import; added JSX_WHITESPACE_REGEXP constant
apps/oxlint/test/isSpaceBetween.test.ts Added comprehensive test cases for isSpaceBetween() covering various whitespace scenarios and JSX edge cases
apps/oxlint/test/fixtures/isSpaceBetween/output.snap.md Updated snapshots to reflect corrected behavior (false instead of true for string literals and JSX text with internal spaces)
apps/oxlint/test/fixtures/isSpaceBetween/files/index.js Removed comment about known incorrect behavior that has been fixed
apps/oxlint/test/fixtures/isSpaceBetween/files/index.jsx Removed comments about known incorrect behavior that has been fixed

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

If `tokensWithComments !== null`, no need to check if `tokens === null`.
Our convention for comments is:
1. Comment which is a single sentence = no full stop on end.
2. Comment which is multiple sentences = full stop on end of each sentence.
3. Comments preceding a top-level var, class, or type definition = full stop on end.
Maybe that's too complicated, but IMO having *some* convention is more important than what that convention is exactly.
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.

Excellent! Thanks very much for adding so many tests.

I've pushed a few commits - all nits. I've only split it into so many tiny commits so you can see what I'm trying to do clearly (if you're interested).

@overlookmotel overlookmotel self-assigned this Nov 27, 2025
@overlookmotel overlookmotel removed the request for review from camc314 November 27, 2025 12:59
@overlookmotel overlookmotel merged commit f3e9913 into oxc-project:main Nov 27, 2025
17 checks passed
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 A-linter-plugins Area - Linter JS plugins C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants