Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Netail
Copy link
Member

@Netail Netail commented Nov 10, 2025

Summary

Implement Eslint's useArraySortCompare

Closes #8061

Test Plan

Docs

@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2025

🦋 Changeset detected

Latest commit: e3ce923

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Nov 10, 2025
@Netail Netail changed the title feat(biome_js_analyze): Implement useArraySortCompare feat(biome_js_analyze): implement useArraySortCompare Nov 10, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Walkthrough

Adds a new Project-domain lint rule useArraySortCompare (Rust: UseArraySortCompare) that flags calls to Array.prototype.sort and Array.prototype.toSorted without a compare function. Includes the lint implementation, diagnostics, an empty UseArraySortCompareOptions options struct, unit tests for valid and invalid cases, and a documentation changeset. No existing public API signatures were removed or modified.

Suggested reviewers

  • dyc3
  • ematipico
  • arendjr

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the primary change: implementation of the useArraySortCompare lint rule.
Description check ✅ Passed Description clearly relates to the changeset, referencing the ESLint rule being implemented and the closed issue.
Linked Issues check ✅ Passed All coding requirements from issue #8061 are met: the useArraySortCompare rule is implemented in the Project domain with proper type checking and diagnostics.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the useArraySortCompare lint rule; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c0870b and e3ce923.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (2)
  • crates/biome_js_analyze/src/lint/nursery/use_array_sort_compare.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : Add new TypeScript type support by extending the TypeData enum rather than introducing parallel structures.

Applied to files:

  • crates/biome_js_analyze/src/lint/nursery/use_array_sort_compare.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_array_sort_compare.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (2)
  • RuleDomain (927-935)
  • UseArraySortCompareOptions (8376-8376)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Check JS Files
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
🔇 Additional comments (5)
crates/biome_js_analyze/src/lint/nursery/use_array_sort_compare.rs (5)

1-10: Imports look good.

All necessary dependencies are present for a typed lint rule.


11-48: Well-documented rule declaration.

The documentation clearly explains the issue with string-based sorting and provides helpful examples.


56-71: Array and method checking is spot on.

Correctly identifies sort and toSorted calls on array types.


73-86: Argument checking correctly handles the undefined/null case.

The type-based approach at lines 78–83 properly addresses the past review concern by catching undefined and null arguments—whether literal, identifier, or typed variable.


88-105: Clear diagnostic with helpful guidance.

The two notes effectively explain the problem and guide the user towards the fix.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f68bcc and 6c0870b.

⛔ Files ignored due to path filters (9)
  • crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs is excluded by !**/migrate/eslint_any_rule_to_biome.rs and included by **
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs and included by **
  • crates/biome_configuration/src/generated/domain_selector.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • crates/biome_js_analyze/src/lint/nursery.rs is excluded by !**/nursery.rs and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/valid.ts.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (6)
  • .changeset/sad-adults-enjoy.md (1 hunks)
  • crates/biome_js_analyze/src/lint/nursery/use_array_sort_compare.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/valid.ts (1 hunks)
  • crates/biome_rule_options/src/lib.rs (1 hunks)
  • crates/biome_rule_options/src/use_array_sort_compare.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/**/*.rs : Do not copy or clone data between module graph entries (including behind Arc). Each module must avoid holding duplicated data from another module to enable simple invalidation.

Applied to files:

  • crates/biome_rule_options/src/lib.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/**/*.rs : After generation, remove usages of `format_verbatim_node` and implement real formatting with biome_formatter utilities

Applied to files:

  • crates/biome_rule_options/src/lib.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/lib.rs : Add the provided AsFormat, IntoFormat, and iterator plumbing code to lib.rs

Applied to files:

  • crates/biome_rule_options/src/lib.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/{type_info,local_inference,resolver,flattening}.rs : Avoid recursive type structures and cross-module Arcs; represent links between types using TypeReference and TypeData::Reference.

Applied to files:

  • crates/biome_rule_options/src/lib.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : Add new TypeScript type support by extending the TypeData enum rather than introducing parallel structures.

Applied to files:

  • crates/biome_rule_options/src/use_array_sort_compare.rs
  • crates/biome_js_analyze/src/lint/nursery/use_array_sort_compare.rs
🧬 Code graph analysis (2)
crates/biome_rule_options/src/use_array_sort_compare.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
  • UseArraySortCompareOptions (8376-8376)
crates/biome_js_analyze/src/lint/nursery/use_array_sort_compare.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (2)
  • RuleDomain (927-935)
  • UseArraySortCompareOptions (8376-8376)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Check JS Files
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_configuration)

Comment on lines 1 to 7
const anyArray: any[] = [];
anyArray.sort();
anyArray.toSorted();

const stringArray: string[] = [];
stringArray.sort();
stringArray.toSorted();
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add coverage for explicit default comparators.

Please include array.sort(undefined), array.sort(null), and the toSorted equivalents here. The source rule we're porting flags those usages because they still fall back to the lexicographic default, so we need fixtures to lock that behaviour in.

🤖 Prompt for AI Agents
In crates/biome_js_analyze/tests/specs/nursery/useArraySortCompare/invalid.ts
around lines 1-7, the test file is missing cases that call the default
comparator explicitly; add calls that exercise the explicit default comparator
by invoking anyArray.sort(undefined), anyArray.sort(null),
anyArray.toSorted(undefined), anyArray.toSorted(null) and likewise
stringArray.sort(undefined), stringArray.sort(null),
stringArray.toSorted(undefined), stringArray.toSorted(null) so the fixture locks
the lexicographic fallback behavior for both any[] and string[] variants.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 10, 2025

CodSpeed Performance Report

Merging #8065 will not alter performance

Comparing Netail:feat/use-array-sort-compare (d3cf2c7) with main (3ff9d45)1

Summary

✅ 58 untouched
⏩ 85 skipped2

Footnotes

  1. No successful run was found on main (5f68bcc) during the generation of this report, so 3ff9d45 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 85 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.

@Netail Netail force-pushed the feat/use-array-sort-compare branch from d3cf2c7 to f0c16ae Compare November 10, 2025 21:07
@Netail Netail force-pushed the feat/use-array-sort-compare branch from f0c16ae to e3ce923 Compare November 10, 2025 21:10
@Netail Netail merged commit 1a2d1af into biomejs:main Nov 10, 2025
20 checks passed
@github-actions github-actions bot mentioned this pull request Nov 10, 2025
@Netail Netail deleted the feat/use-array-sort-compare branch November 10, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port require-array-sort-compare from typescript-eslint

2 participants