Skip to content

Latest commit

 

History

History
23 lines (14 loc) · 737 Bytes

no-collection-size-mischeck.md

File metadata and controls

23 lines (14 loc) · 737 Bytes

no-collection-size-mischeck

The size of a collection and the length of an array are always greater than or equal to zero. So testing that a size or length is greater than or equal to zero doesn't make sense, since the result is always true. Similarly testing that it is less than zero will always return false. Perhaps the intent was to check the non-emptiness of the collection or array instead.

Noncompliant Code Example

if (someSet.size >= 0) {...} // Noncompliant

if (someMap.size < 0) {...} // Noncompliant

const result = someArray.length >= 0;  // Noncompliant

Compliant Solution

if (someSet.size > 0) {...}

if (someMap.size == 0) {...}

const result = someArray.length > 0;