This is an issue when checking array length before calling Array#some() or Array#every() methods in cases where the
length check is redundant.
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.
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.
Remove the redundant length check when using Array#every() with OR logic. The every() method already returns
true for empty arrays.
if (array.length === 0 || array.every(Boolean)) { // Noncompliant
// Handle case
}
if (array.every(Boolean)) {
// Handle case
}