unicorn/no-useless-length-check Correctness
What it does
It checks for an unnecessary array length check in a logical expression.
The cases are:
array.length === 0 || array.every(Boolean)
(array.every
returnstrue
if array is has elements)array.length > 0 && array.some(Boolean)
(array.some
returnsfalse
if array is empty)
Why is this bad?
An extra unnecessary length check is done.
Example
javascript
if (array.length === 0 || array.every(Boolean)) {
// do something!
}