JavaScript false positive on variable self-assignment

javascript

(nkawxs) #1

sonarqube 7.5
this javascript rule says “Variables should not be self-assigned”

Noncompliant Code Example

function setName(name) {
name = name;
}

Compliant Solution

function setName(name) {
this.name = name;
}

but it is wrong.
lets have a look on the belows examples

  1. arrayA = arrayA.sort();

  2. maskedValue = maskedValue.reverse()

  3. list = list.sort(function(a, b) {

     return parseFloat(b) - parseFloat(a);
    

    });