Skip to content

arrayUnnecessaryLengthChecks

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

✅ This rule is included in the ts logical presets.

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
const array: boolean[]
array
: boolean[];
const array: boolean[]
array
.
Array<boolean>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
!== 0 &&
const array: boolean[]
array
.
Array<boolean>.some(predicate: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean

Determines whether the specified callback function returns true for any element of an array.

@parampredicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

some
(
var Boolean: BooleanConstructor
Boolean
);
declare const
const array: boolean[]
array
: boolean[];
const array: boolean[]
array
.
Array<boolean>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
> 0 &&
const array: boolean[]
array
.
Array<boolean>.some(predicate: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean

Determines whether the specified callback function returns true for any element of an array.

@parampredicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

some
(
var Boolean: BooleanConstructor
Boolean
);
declare const
const array: boolean[]
array
: boolean[];
const array: boolean[]
array
.
Array<boolean>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
=== 0 ||
const array: boolean[]
array
.
Array<boolean>.every(predicate: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean (+1 overload)

Determines whether all the members of an array satisfy the specified test.

@parampredicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

every
(
var Boolean: BooleanConstructor
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 ❤️‍🔥 around the world by the Flint team and contributors.