unicorn/explicit-length-check Pedantic
What it does
Enforce explicitly comparing the length or size property of a value.
The non-zero option can be configured with one of the following: greater-than (default) Enforces non-zero to be checked with: foo.length > 0 not-equal Enforces non-zero to be checked with: foo.length !== 0
Why is this bad?
Examples
Examples of incorrect code for this rule:
javascript
const isEmpty = foo.length == 0;
const isEmpty = foo.length < 1;
const isEmpty = 0 === foo.length;
const isEmpty = 0 == foo.length;
const isEmpty = 1 > foo.length;
const isEmpty = !foo.length;
const isEmpty = !(foo.length > 0);
const isEmptySet = !foo.size;
Examples of correct code for this rule:
javascript
const isEmpty = foo.length === 0;