Skip to content

arrayUnnecessaryLengthChecks

Reports unnecessary array length checks before .some() or .every() calls.

✅ This rule is included in the ts logical preset.

Array#some() returns false for an empty array, so checking array.length !== 0 or array.length > 0 before calling .some() is redundant.

Array#every() returns true for an empty array, so checking array.length === 0 before calling .every() is redundant.

This rule reports these unnecessary length checks.

declare const array: boolean[];
array.length !== 0 && array.some(Boolean);
declare const array: boolean[];
array.length > 0 && array.some(Boolean);
declare const array: boolean[];
array.length === 0 || array.every(Boolean);

This rule is not configurable.

If you prefer explicit length checks for documentation purposes, or if your team’s coding standards require them, you may disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.