refactor(linter/plugins): reimplement isSpaceBetween() isSpaceBetweenTokens() using tokens#16055
Conversation
5ceb6d8 to
598e16d
Compare
isSpaceBetween using tokensisSpaceBetween() isSpaceBetweenTokens() using tokens
There was a problem hiding this comment.
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.
49c79a3 to
654d719
Compare
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.
654d719 to
bc1f7cc
Compare
overlookmotel
left a comment
There was a problem hiding this comment.
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).
…eenTokens()` using tokens (oxc-project#16055) - Follow up to oxc-project#15498 and oxc-project#15861 - Note: JSX special case (as part of the `isSpaceBetweenTokens()` method) is being removed in ESLint v10 (see [eslint/eslint#20137](https://github.com/eslint/eslint/pull/20137/files#diff-e85eaebdcf6af45c06572019cbd900cff91518c789049c3bd0e8724c18645ab0)) ### Tasks: - [x] Token-based reimplementation of `isSpaceBetween()` - [x] Token-based reimplementation of `isSpaceBetweenTokens()` - [x] Pass existing tests from oxc-project#15498 - [x] New tests for JS syntax - [x] New tests for JSX syntax --------- Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
SourceCode#isSpaceBetween#15498 and feat(linter/plugins): Token-relatedSourceCodeAPIs (TS ESLint implementation) #15861isSpaceBetweenTokens()method) is being removed in ESLint v10 (see eslint/eslint#20137)Tasks:
isSpaceBetween()isSpaceBetweenTokens()SourceCode#isSpaceBetween#15498