Skip to content

refactor(linter/plugins): stronger debug checks for tokens#16810

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-13-refactor_linter_plugins_stronger_debug_checks_for_tokens
Dec 13, 2025
Merged

refactor(linter/plugins): stronger debug checks for tokens#16810
graphite-app[bot] merged 1 commit intomainfrom
12-13-refactor_linter_plugins_stronger_debug_checks_for_tokens

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Dec 13, 2025

Add more debug checks for tokens - that they all have valid ranges, and are in ascending order.

@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 Dec 13, 2025
Copy link
Copy Markdown
Member Author

overlookmotel commented Dec 13, 2025


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.

Copy link
Copy Markdown
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 token validation in the oxlint JavaScript plugin system by introducing a dedicated debugCheckValidRanges function that performs stronger debug-time validation. The refactoring consolidates duplicate checking logic and adds validation immediately after parsing to catch issues earlier in the pipeline.

Key Changes:

  • Introduces debugCheckValidRanges function that validates tokens have valid ranges (end > start) and are in ascending non-overlapping order
  • Adds immediate validation of parsed tokens and comments in initTokens() before they're used elsewhere
  • Simplifies debugCheckTokensAndComments() by removing redundant duplicate-start checking from the sort comparator, since this is now handled by the new validation function

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

Copy link
Copy Markdown

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new debug range validation is a good direction, but the removal of the explicit “same start” invariant plus sorting only by range[0] can make tie cases non-deterministic and potentially less diagnosable. Consider making the ordering check and comparator total (e.g., by [start,end]) and/or explicitly rejecting duplicate starts in debugCheckValidRanges() so the debug assertions remain strict and deterministic.

Additional notes (1)
  • Performance | apps/oxlint/src-js/plugins/tokens.ts:177-185
    initTokens() now does tokensAndComments.sort(...) on a freshly merged array, but the existing debugCheckTokensAndComments() later validates that tokensAndComments (the module-level variable) is correctly ordered.

This is fine, but the current debug check in initTokens() is doing two sorts (here and later) and validates ordering of a merged list that is not otherwise used. If the intent is to catch issues earlier, you can avoid the extra sort by validating tokens and comments individually (already done) and leave merged-order validation to debugCheckTokensAndComments() (which checks the actual stored tokensAndComments).

Summary of changes

Summary

This change strengthens debug-time validation around token ranges produced by tsEslintParse.

  • Imports Range from ./location.ts to enable range validation typing.
  • Adds a debug-only validation pass in initTokens():
    • Validates tokens and comments individually.
    • Merges tokens + comments, sorts by range[0], and validates the combined list.
  • Introduces debugCheckValidRanges() to ensure each item has a valid range (end > start) and that items are in ascending (non-overlapping) order.
  • Simplifies debugCheckTokensAndComments() sorting logic by removing the explicit “same start” check and relying on ordering validation elsewhere.

@charliecreates charliecreates bot removed the request for review from CharlieHelps December 13, 2025 21:18
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 13, 2025
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 13, 2025

Merge activity

Add more debug checks for tokens - that they all have valid ranges, and are in ascending order.
@graphite-app graphite-app bot force-pushed the 12-13-refactor_linter_plugins_stronger_debug_checks_for_tokens branch from d608f7c to c06d243 Compare December 13, 2025 22:55
@graphite-app graphite-app bot merged commit c06d243 into main Dec 13, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 12-13-refactor_linter_plugins_stronger_debug_checks_for_tokens branch December 13, 2025 23:00
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 13, 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