useArraySome
此内容尚不支持你的语言。
Summary
Section titled “Summary”- 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Prefer .some() over filter(…).length comparison.
> 1 │ array.filter(predicate).length > 0;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Using .filter() followed by a length check iterates the entire array unnecessarily. .some() stops at the first match.
ℹ Use .some() when you only need to know if 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.
ℹ 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Prefer .some() over findIndex(…) !== -1.
> 1 │ array.findIndex(predicate) !== -1;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Use .some() when you only need to know if 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.
ℹ 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Prefer .some() over find-family used as boolean.
> 1 │ if (array.find(predicate)) {}
│ ^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Use .some() when you only need to know if 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.find(predicate) != null;code-block.js:1:1 lint/nursery/useArraySome ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Prefer .some() over find(…) existence comparison.
> 1 │ array.find(predicate) != null;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Use .some() when you only need to know if 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Prefer .some() over findLastIndex(…) !== -1.
> 1 │ array.findLastIndex(predicate) !== -1;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Use .some() when you only need to know if 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.
ℹ 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Prefer .some() over find-family used as boolean.
> 1 │ if (array.findLast(predicate)) {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Use .some() when you only need to know if 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.some(predicate);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.