-
-
Notifications
You must be signed in to change notification settings - Fork 728
refactor(linter/plugins): reimplement isSpaceBetween() isSpaceBetweenTokens() using tokens
#16055
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
Conversation
5ceb6d8 to
598e16d
Compare
isSpaceBetween using tokensisSpaceBetween() isSpaceBetweenTokens() using tokens
There was a problem hiding this 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.
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.
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).
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