diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs b/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs index d0c1ae474..e5eb4bd36 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs @@ -35,7 +35,9 @@ pub struct PreferArraySome; declare_oxc_lint!( /// ### What it does /// - /// 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) + /// 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, + /// 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) + /// 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) /// /// ### Why is this bad? /// @@ -46,17 +48,25 @@ declare_oxc_lint!( /// Examples of **incorrect** code for this rule: /// ```javascript /// const foo = array.find(fn) ? bar : baz; + /// const foo = array.findLast(elem => hasRole(elem)) !== null; + /// foo.findIndex(bar) < 0; + /// foo.findIndex(element => element.bar === 1) !== -1; + /// foo.findLastIndex(element => element.bar === 1) !== -1; + /// array.filter(fn).length === 0; /// ``` /// /// Examples of **correct** code for this rule: /// ```javascript /// const foo = array.some(fn) ? bar : baz; + /// foo.some(element => element.bar === 1); + /// !array.some(fn); /// ``` PreferArraySome, pedantic, fix ); +/// impl Rule for PreferArraySome { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { match node.kind() {