Skip to content

fix(linter): sort paths by length instead of alphabetically for depth heuristic#18084

Merged
graphite-app[bot] merged 1 commit intomainfrom
fix-linter-path-sorting
Jan 16, 2026
Merged

fix(linter): sort paths by length instead of alphabetically for depth heuristic#18084
graphite-app[bot] merged 1 commit intomainfrom
fix-linter-path-sorting

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 16, 2026

Summary

Fixes the path sorting bug identified in #15924 where the linter's path sorting was intended to process "deeper" paths first (so leaf modules can be processed and released from memory earlier), but was actually sorting in reverse alphabetical order.

Example of the bug:

  • src/a/b/c/d.js (4 levels deep) vs src/z.js (1 level)
  • Alphabetically: src/a/... < src/z.js (because 'a' < 'z')
  • With reverse sort: src/z.js came BEFORE the deeper path (wrong!)

The fix: Sort by path length descending instead (b.len().cmp(&a.len())), which is a good proxy for depth and achieves O(1) comparison cost per the comment in #15924.

Closes #15924

Test plan

  • cargo check -p oxc_linter passes
  • cargo test -p oxc_linter passes
  • just fmt passes

🤖 Generated with Claude Code

@Boshen Boshen requested a review from camc314 as a code owner January 16, 2026 13:58
Copilot AI review requested due to automatic review settings January 16, 2026 13:58
@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Jan 16, 2026
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 fixes a bug in the linter's path sorting logic where paths were being sorted in reverse alphabetical order instead of by depth. The fix changes the sorting to use path length descending as a heuristic for depth, allowing leaf modules to be processed earlier and released from memory sooner.

Changes:

  • Replace reverse alphabetical path sorting with length-based descending sort
  • Add clarifying comments explaining the O(1) comparison approach

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

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 16, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing fix-linter-path-sorting (4b48087) with main (9135b0b)

Summary

✅ 4 untouched benchmarks
⏩ 41 skipped benchmarks1

Footnotes

  1. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jan 16, 2026
Copy link
Contributor

camc314 commented Jan 16, 2026

Merge activity

… heuristic (#18084)

## Summary

Fixes the path sorting bug identified in #15924 where the linter's path sorting was intended to process "deeper" paths first (so leaf modules can be processed and released from memory earlier), but was actually sorting in reverse alphabetical order.

**Example of the bug:**
- `src/a/b/c/d.js` (4 levels deep) vs `src/z.js` (1 level)
- Alphabetically: `src/a/...` < `src/z.js` (because 'a' < 'z')
- With reverse sort: `src/z.js` came BEFORE the deeper path (wrong!)

**The fix:** Sort by path length descending instead (`b.len().cmp(&a.len())`), which is a good proxy for depth and achieves O(1) comparison cost per the comment in #15924.

Closes #15924

## Test plan

- [x] `cargo check -p oxc_linter` passes
- [x] `cargo test -p oxc_linter` passes
- [x] `just fmt` passes

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the fix-linter-path-sorting branch from 4b48087 to 121a239 Compare January 16, 2026 15:40
@graphite-app graphite-app bot merged commit 121a239 into main Jan 16, 2026
21 checks passed
@graphite-app graphite-app bot deleted the fix-linter-path-sorting branch January 16, 2026 15:45
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: investigate how deep into the module graph the linter resolves

3 participants