SonarJS icon indicating copy to clipboard operation
SonarJS copied to clipboard

Rule S2871: Update implementation to raise on non-string-like arrays

Open yassin-kammoun-sonarsource opened this issue 5 years ago • 0 comments

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