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.
Examples
Section titled “Examples”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);declare const array: boolean[];array.some(Boolean);declare const array: boolean[];array.every(Boolean);declare const array: boolean[];array.length !== 0 && array.every(Boolean);declare const array: boolean[];array.length === 0 || array.some(Boolean);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you prefer explicit length checks for documentation purposes, or if your team’s coding standards require them, you may disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/no-useless-length-check - Oxlint:
unicorn/no-useless-length-check
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.