Duplicate local declaration

Note

The Duplicate local declaration code issue is JavaScript specific.

CodeRush shows the Duplicate local declaration code issue if a local variable is declared two or more times.

Fix

Remove all variable declarations except the first one.

Purpose

Highlights duplicate local declarations, which are redundant. With the exception of the first declaraiton, they can all be removed.

Example

function GetClicksCount() {
  var clicks = GetClicks();
  ProcessClicks(clicks);
  var clicks = GetProcessedClicks();
  if (AllClicksProcessed === 0) {
    var clicks = GetUnProcessedClicks();
    ReportUnprocessedClicks(clicks);
  }
  return clicks;
}

Fix:

function GetClicksCount() {
  var clicks = GetClicks();
  ProcessClicks(clicks);
  clicks = GetProcessedClicks();
  if (AllClicksProcessed === 0) {
    clicks = GetUnProcessedClicks();
    ReportUnprocessedClicks(clicks);
  }
  return clicks;
}