Skip to content

unicorn/no-useless-length-check Correctness ​

✅ This rule is turned on by default.
🚧 An auto-fix is still under development.

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 returns true if array is has elements)
  • array.length > 0 && array.some(Boolean) (array.some returns false 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!
}

References ​

Released under the MIT License.