Skip to content

useArraySome (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useArraySome": "error"
}
}
}
}

Prefer Array.prototype.some() over verbose existence checks.

array.filter(predicate).length > 0;
code-block.js:1:1 lint/nursery/useArraySome  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This expression uses .filter() and then checks whether the result is empty.

> 1 │ array.filter(predicate).length > 0;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ .some() matches that intent better and can stop as soon as it finds a match.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Use .some() instead.

1 │ - array.filter(predicate).length·>·0;
1 │ + array.some(predicate);
2 2 │

array.findIndex(predicate) !== -1;
code-block.js:1:1 lint/nursery/useArraySome  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This expression uses .findIndex() to test whether any array element matches.

> 1 │ array.findIndex(predicate) !== -1;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ .some() makes that intent clearer because it returns a boolean directly.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Use .some() instead.

1 │ - array.findIndex(predicate)·!==·-1;
1 │ + array.some(predicate);
2 2 │

if (array.find(predicate)) {}
code-block.js:1:5 lint/nursery/useArraySome ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This expression uses a .find()-style call as a boolean test.

> 1 │ if (array.find(predicate)) {}
│ ^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ .some() makes that intent clearer because it returns a boolean directly.

ℹ Use .some() instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

array.find(predicate) != null;
code-block.js:1:1 lint/nursery/useArraySome ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This expression uses .find() only to check whether an array element exists.

> 1 │ array.find(predicate) != null;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ .some() makes that intent clearer because it returns a boolean directly.

ℹ Use .some() if you only need to know whether any element matches.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

array.findLastIndex(predicate) !== -1;
code-block.js:1:1 lint/nursery/useArraySome  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This expression uses .findLastIndex() to test whether any array element matches.

> 1 │ array.findLastIndex(predicate) !== -1;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ .some() makes that intent clearer because it returns a boolean directly.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Use .some() instead.

1 │ - array.findLastIndex(predicate)·!==·-1;
1 │ + array.some(predicate);
2 2 │

if (array.findLast(predicate)) {}
code-block.js:1:5 lint/nursery/useArraySome ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This expression uses a .find()-style call as a boolean test.

> 1 │ if (array.findLast(predicate)) {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ .some() makes that intent clearer because it returns a boolean directly.

ℹ Use .some() instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

array.some(predicate);