diff --git a/docs/rules/prefer-array-some.md b/docs/rules/prefer-array-some.md index f7a102d17d..3501176b88 100644 --- a/docs/rules/prefer-array-some.md +++ b/docs/rules/prefer-array-some.md @@ -1,4 +1,4 @@ -# Prefer `.some(…)` over `.filter(…).length` check and `.find(…)` +# Prefer `.some(…)` over `.filter(…).length` check and `.{find,findLast}(…)` @@ -13,11 +13,11 @@ Prefer using [`Array#some`](https://developer.mozilla.org/en-US/docs/Web/JavaScr We only check `.filter().length > 0` and `.filter().length !== 0`. These two non-zero length check styles are allowed in [`unicorn/explicit-length-check`](./explicit-length-check.md#options) rule. It is recommended to use them together. -- Using [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) to ensure at least one element in the array passes a given check. +- Using [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) or [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) to ensure at least one element in the array passes a given check. -- Comparing the result of [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) with `undefined`. +- Comparing the result of [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) or [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) with `undefined`. -This rule is fixable for `.filter(…).length` check and has a suggestion for `.find(…)`. +This rule is fixable for `.filter(…).length` check and has a suggestion for `.{find,findLast}(…)`. ## Fail @@ -51,12 +51,36 @@ const hasUnicorn = array.find(element => isUnicorn(element) !== undefined; const hasUnicorn = array.find(element => isUnicorn(element) != null; ``` +```js +if (array.find(element => isUnicorn(element))) { + // … +} +``` + +```js +const foo = array.findLast(element => isUnicorn(element)) ? bar : baz; +``` + +```js +const hasUnicorn = array.findLast(element => isUnicorn(element) !== undefined; +``` + +```js +const hasUnicorn = array.findLast(element => isUnicorn(element) != null; +``` + ```vue ``` +```vue + +``` + ```vue