Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 653 Bytes

no-unused-collection.md

File metadata and controls

26 lines (19 loc) · 653 Bytes

no-unused-collection

When a collection is populated but its contents are never used, then it is surely some kind of mistake. Either refactoring has rendered the collection moot, or an access is missing.

This rule raises an issue when no methods are called on a collection other than those that add or remove values.

Noncompliant Code Example

function getLength(a, b, c) {
  const strings = []; // Noncompliant
  strings.push(a);
  strings.push(b);
  strings.push(c);

  return a.length + b.length + c.length;
}

Compliant Solution

function getLength(a, b, c) {
  return a.length + b.length + c.length;
}