mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
docs(linter): add more examples for unicorn/prefer-array-some (#7411)
This commit is contained in:
parent
f4fda2dba6
commit
6730e3effe
1 changed files with 11 additions and 1 deletions
|
|
@ -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
|
||||
);
|
||||
|
||||
/// <https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v56.0.1/docs/rules/prefer-array-some.md>
|
||||
impl Rule for PreferArraySome {
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
match node.kind() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue