💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
Array#some()
returnsfalse
for an empty array. There is no need to check if the array is not empty.Array#every()
returnstrue
for an empty array. There is no need to check if the array is empty.
We only check .length === 0
, .length !== 0
, and .length > 0
. These zero and non-zero length check styles are allowed in the unicorn/explicit-length-check
rule. It is recommended to use them together.
if (array.length === 0 || array.every(Boolean));
if (array.length !== 0 && array.some(Boolean));
if (array.length > 0 && array.some(Boolean));
const isAllTrulyOrEmpty = array.length === 0 || array.every(Boolean);
if (array.every(Boolean));
if (array.some(Boolean));
const isAllTrulyOrEmpty = array.every(Boolean);
if (array.length === 0 || anotherCheck() || array.every(Boolean));
const isNonEmptyAllTrulyArray = array.length > 0 && array.every(Boolean);
const isEmptyArrayOrAllTruly = array.length === 0 || array.some(Boolean);