SonarJS
SonarJS copied to clipboard
Rule S2871: Update implementation to raise on non-string-like arrays
We currently raise issues for numeric arrays only, but we can improve the rule and extend its scope to raise on non-string-like arrays.
We define a string-like data type as being either:
Primitive type string
:
let strings: string[] = ...
strings.sort(); // OK
Types (Type, Class, Interface) overriding the toString
method:
interface I {
toString(): string;
}
let interfaces: I[] = ...
interfaces.sort(); // OK
Intersections involving at least one of the above:
let intersections: (string & something)[] = ...
intersections.sort(); // OK