Skip to content

Commit

Permalink
Modify rule S2871: Add exception for arrays of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmorand-sonarsource committed Jan 30, 2024
1 parent 8f17ae9 commit 617d6d3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rules/S2871/javascript/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ console.log([code1, code2, code3].sort()); // Noncompliant: ["éΔ", "eΔ", "é
console.log([code1, code2, code3].sort((a, b) => a.localeCompare(b))); // ["eΔ", "éΔ", "éΔ"]
----

=== Exceptions

The rule ignores arrays that only contain strings, or are declared as such.

[source,javascript]
----
const names = ['foo', 'bar'];
names.sort(); // Compliant
----

[source,javascript]
----
const names: string[] = [];
names.sort(); // Compliant
----

== Resources
=== Documentation

Expand Down

0 comments on commit 617d6d3

Please sign in to comment.