useArraySome
Summary
Section titled “Summary”- Rule available since:
v2.4.5 - Diagnostic Category:
lint/nursery/useArraySome - This rule has an unsafe fix.
- The default severity of this rule is information.
- Sources:
- Inspired from
unicorn/prefer-array-some
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useArraySome": "error" } } }}Description
Section titled “Description”Prefer Array.prototype.some() over verbose existence checks.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.