require-array-sort-compare
Configuration
rslint.config.ts
Rule Details
Require Array#sort and Array#toSorted calls to always provide a compareFunction. When called without a compare function, Array#sort() and Array#toSorted() convert all non-undefined elements to strings and then compare them using their UTF-16 code unit values. This can lead to surprising sort orders, especially for arrays of numbers (e.g., [1, 10, 2] instead of [1, 2, 10]).
By default, string arrays are ignored since the default sort behavior is appropriate for them.
Examples of incorrect code for this rule:
Examples of correct code for this rule: