Many of JavaScript's ``++Array++`` methods return an altered version of the array while leaving the source array intact. ``++reverse++`` and ``++sort++`` do not fall into this category. Instead, they alter the source array _in addition to_ returning the altered version, which is likely not what was intended.
This rule raises an issue when the return values of these methods are assigned, which could lead maintainers to overlook the fact that the original value is altered.
I've put the rule back to Sonar Way as we removed more code-smelly case ``++a = a.reverse();++`` from the scope (moved to RSPEC-1656).
=== on 16 Jan 2020, 10:23:52 Tibor Blenessy wrote:
Changed to code smell, we can't be sure that the code has a bug, and from issues we find it seems that more often it's not the case
=== on 14 Mar 2021, 11:23:01 JounQin wrote:
Hi, I tried this in SonarJS, it seems `items?.sort()` reports while `items.sort()` does not which is unexpected.
What means this rule is not compatible with `optional chaining`.
=== on 15 Mar 2021, 16:56:59 Tibor Blenessy wrote:
\[~JounQin] I created issue from your report \https://github.com/SonarSource/SonarJS/issues/2513 , however please use our community forum in the future \https://community.sonarsource.com/ , this JIRA project should not be used to report specific implementation issues, as it is agnostic about the language.