This is an issue when checking array length before calling Array#some() or Array#every() methods in cases where the length check is redundant.

Why is this an issue?

JavaScript’s Array#some() and Array#every() methods already handle empty arrays correctly without requiring explicit length checks.

The Array#some() method returns false when called on an empty array because no elements can satisfy the condition. Similarly, Array#every() returns true for empty arrays following the principle of vacuous truth - if there are no elements, then technically all elements satisfy the condition.

When developers add unnecessary length checks before these method calls, it creates redundant code that:

The redundant patterns typically look like array.length === 0 || array.every(…​) or array.length !== 0 && array.some(…​). In both cases, the length check doesn’t change the final result because the array methods already handle empty arrays appropriately.

What is the potential impact?

This issue primarily affects code readability and maintainability. While it doesn’t cause functional bugs, it can lead to confusion among team members and makes the codebase unnecessarily verbose. Removing these redundant checks results in cleaner, more idiomatic JavaScript code that better expresses the developer’s intent.

How to fix?

Remove the redundant length check when using Array#every() with OR logic. The every() method already returns true for empty arrays.

Non-compliant code example

if (array.length === 0 || array.every(Boolean)) { // Noncompliant
  // Handle case
}

Compliant code example

if (array.every(Boolean)) {
  // Handle case
}

Documentation