Skip to content

Commit 6730e3e

Browse files
authored
docs(linter): add more examples for unicorn/prefer-array-some (#7411)
1 parent f4fda2d commit 6730e3e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ pub struct PreferArraySome;
3535
declare_oxc_lint!(
3636
/// ### What it does
3737
///
38-
/// Prefers using [`Array#some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) over [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find), [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) and a non-zero length check on the result of [`Array#filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
38+
/// Prefers using [`Array#some()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) over [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find), [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) with comparing to undefined,
39+
/// or [`Array#findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex), [`Array#findLastIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
40+
/// and a non-zero length check on the result of [`Array#filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
3941
///
4042
/// ### Why is this bad?
4143
///
@@ -46,17 +48,25 @@ declare_oxc_lint!(
4648
/// Examples of **incorrect** code for this rule:
4749
/// ```javascript
4850
/// const foo = array.find(fn) ? bar : baz;
51+
/// const foo = array.findLast(elem => hasRole(elem)) !== null;
52+
/// foo.findIndex(bar) < 0;
53+
/// foo.findIndex(element => element.bar === 1) !== -1;
54+
/// foo.findLastIndex(element => element.bar === 1) !== -1;
55+
/// array.filter(fn).length === 0;
4956
/// ```
5057
///
5158
/// Examples of **correct** code for this rule:
5259
/// ```javascript
5360
/// const foo = array.some(fn) ? bar : baz;
61+
/// foo.some(element => element.bar === 1);
62+
/// !array.some(fn);
5463
/// ```
5564
PreferArraySome,
5665
pedantic,
5766
fix
5867
);
5968

69+
/// <https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v56.0.1/docs/rules/prefer-array-some.md>
6070
impl Rule for PreferArraySome {
6171
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
6272
match node.kind() {

0 commit comments

Comments
 (0)