-
-
Notifications
You must be signed in to change notification settings - Fork 724
perf(linter/plugins): optimize getTokens() and other methods
#16188
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
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 optimizes token retrieval methods in the linter plugin by improving performance through several targeted changes: removing unnecessary branching, preventing out-of-bounds array access, renaming variables for clarity, and improving comment consistency.
Key changes:
- Optimizes
getTokens()to avoid unnecessary array operations when filtering with count limits and adds bounds checking to prevent indexing past array length - Refactors binary search in
getLastToken()with a cleaner algorithm and adds explicit bounds checking - Renames
nodeTokensvariable totokenListthroughout the file for better semantic accuracy
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/oxlint/test/tokens.test.ts | Fixes incorrect range values in tests (corrects [0, 11] to [0, 10] to match actual string length) |
| apps/oxlint/src-js/plugins/tokens.ts | Refactors token retrieval methods with performance optimizations: adds bounds checking, removes branching in favor of nullish coalescing, optimizes filtering loops, and renames nodeTokens to tokenList for clarity |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4debb5e to
c071391
Compare
c071391 to
481b9a3
Compare
nodeTokenstotokenList. In the first few methods implemented, they contained tokens of the given node. Not the case for later methods, but the misnomer stayed.