Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 23, 2025

The same code was repeated in many places. Move it into a function.

Function is only called when tokensWithComments is not already initialized (cold path), so no function call cost in majority of cases. In Rust, the pattern of moving code which is rarely called into a separate function is usually positive for perf. Not sure whether JS engine works the same way, but it might well be that V8 makes inlining decisions in much the same way.

@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 23, 2025
Copy link
Member Author


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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel marked this pull request as ready for review November 24, 2025 00:00
Copilot AI review requested due to automatic review settings November 24, 2025 00:00
@overlookmotel overlookmotel self-assigned this Nov 24, 2025
Copilot finished reviewing on behalf of overlookmotel November 24, 2025 00:01
@overlookmotel
Copy link
Member Author

cc @lilnasy

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Nov 24, 2025
Copy link
Member Author

overlookmotel commented Nov 24, 2025

Merge activity

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 repeated code by extracting the initialization logic for tokensWithComments into a dedicated helper function. The same code pattern was duplicated across 8 different functions (getTokens, getFirstToken, getFirstTokens, getLastTokens, getTokenBefore, getTokensBefore, getTokenAfter, getTokensAfter), which merged tokens and comments arrays and sorted them. Now all call sites use the new initTokensWithComments() helper function.

  • Introduced new initTokensWithComments() helper function with proper JSDoc documentation
  • Replaced 8 instances of duplicate inline code with calls to the new helper
  • Added defensive debugAssertIsNonNull checks after calling initTokensWithComments() at each call site

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

…Comments` (#16017)

The same code was repeated in many places. Move it into a function.

Function is only called when `tokensWithComments` is not already initialized (cold path), so no function call cost in majority of cases. In Rust, the pattern of moving code which is rarely called into a separate function is usually positive for perf. Not sure whether JS engine works the same way, but it might well be that V8 makes inlining decisions in much the same way.
@graphite-app graphite-app bot force-pushed the 11-23-refactor_linter_plugins_reduce_repeat_code_initializing_tokenswithcomments_ branch from f7c7ff0 to d185615 Compare November 24, 2025 00:06
@graphite-app graphite-app bot merged commit d185615 into main Nov 24, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 11-23-refactor_linter_plugins_reduce_repeat_code_initializing_tokenswithcomments_ branch November 24, 2025 00:12
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 24, 2025
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