[Bug] SonarQube S2871: Array.sort() without a reliable comparator #241

Closed
opened 2026-06-19 18:44:08 +00:00 by spikerj · 1 comment
Owner

Surfaced by SonarQube (learn.spikersoft.com), rule typescript:S2871 / javascript:S2871, severity CRITICAL (RELIABILITY).

Problem

Calling .sort() (or .sort()-style ordering) without a compare function sorts elements as strings (lexicographic), which gives wrong order for numbers/objects and is locale-unsafe. Provide a comparator (numeric, or String.localeCompare).

Locations

  • projects/spikersoft/src/app/_components/dreamstream-cluster-dashboard/dreamstream-cluster-dashboard.component.ts:1437
  • projects/spikersoft/src/app/_components/dreamstream-cluster-dashboard/dreamstream-cluster-dashboard.cluster.spec.ts:505 (test)
  • libraries/features/dev-tools-sql-runner/src/lib/sql-lesson-grader.service.ts:294
  • libraries/features/dev-tools-sql-runner/src/lib/sql-lesson-grader.service.ts:295
  • libraries/platform/clang-runtime/src/lib/language-concept-registry.service.spec.ts:150 (test)
  • scripts/find-missing-i18n-keys.mjs:43

Fix

Add an explicit comparator at each site, e.g. arr.sort((a, b) => a - b) or arr.sort((a, b) => a.localeCompare(b)).

Rule: https://rules.sonarsource.com/typescript/RSPEC-2871/

Surfaced by SonarQube (`learn.spikersoft.com`), rule `typescript:S2871` / `javascript:S2871`, severity CRITICAL (RELIABILITY). ## Problem Calling `.sort()` (or `.sort()`-style ordering) without a compare function sorts elements as strings (lexicographic), which gives wrong order for numbers/objects and is locale-unsafe. Provide a comparator (numeric, or `String.localeCompare`). ## Locations - `projects/spikersoft/src/app/_components/dreamstream-cluster-dashboard/dreamstream-cluster-dashboard.component.ts:1437` - `projects/spikersoft/src/app/_components/dreamstream-cluster-dashboard/dreamstream-cluster-dashboard.cluster.spec.ts:505` (test) - `libraries/features/dev-tools-sql-runner/src/lib/sql-lesson-grader.service.ts:294` - `libraries/features/dev-tools-sql-runner/src/lib/sql-lesson-grader.service.ts:295` - `libraries/platform/clang-runtime/src/lib/language-concept-registry.service.spec.ts:150` (test) - `scripts/find-missing-i18n-keys.mjs:43` ## Fix Add an explicit comparator at each site, e.g. `arr.sort((a, b) => a - b)` or `arr.sort((a, b) => a.localeCompare(b))`. _Rule: https://rules.sonarsource.com/typescript/RSPEC-2871/_
spikerj added the bugsonarqube labels 2026-06-19 18:44:08 +00:00
Author
Owner

Resolved in spikersoft-angular PR #73 (merged to master). Added explicit localeCompare comparators to all six bare .sort() sites (dreamstream dashboard, sql-lesson-grader ×2, i18n script, two specs). Closing.

Resolved in spikersoft-angular PR #73 (merged to `master`). Added explicit `localeCompare` comparators to all six bare `.sort()` sites (dreamstream dashboard, sql-lesson-grader ×2, i18n script, two specs). Closing.
Sign in to join this conversation.