oxc-project/oxc · warning · OxcDiagnostic

Prefer `.some(…)` over `.find(…)` or `.findLast(…)`.

Error message

Prefer `.some(…)` over `.find(…)` or `.findLast(…)`.

What it means

Lint diagnostic from oxlint's `unicorn/prefer-array-some` rule (variant `over_method`). `find()` returns the matching element, so code that only checks the result against `undefined` (`find(fn) !== undefined`) is just asking 'does any element match' — which is `some(fn)`. `some` is clearer about intent, returns a boolean directly, and stops at the first match without constructing/returning elements.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs:19

use oxc_ast::{
    AstKind,
    ast::{Argument, BinaryExpression, Expression, UnaryOperator},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::operator::BinaryOperator;

use crate::{
    AstNode,
    ast_util::{call_expr_method_callee_info, is_method_call, outermost_paren_parent},
    context::LintContext,
    rule::Rule,
    utils::is_boolean_node,
};

fn over_method(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Prefer `.some(…)` over `.find(…)` or `.findLast(…)`.").with_label(span)
}

fn non_zero_filter(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Prefer `.some(…)` over non-zero length check from `.filter(…)`.")
        .with_label(span)
}

fn negative_one_or_zero_filter(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Prefer `.some(…)` over `.findIndex(…)` or `.findLastIndex(…)`.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct PreferArraySome;

declare_oxc_lint!(
    /// ### What it does
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace `arr.find(fn) !== undefined` with `arr.some(fn)`.
  2. Run `oxlint --fix` where the rule offers a fixer for the exact pattern.
  3. If the matched element is actually used later, keep `find` — this rule only targets pure existence checks; suppress inline if a false positive occurs (e.g. custom `undefined`-like sentinels).
  4. Disable the rule in `.oxlintrc.json` if boolean-from-find is pervasive and intentional.

Example fix

// before
if (users.find(u => u.admin) !== undefined) { grant(); }

// after
if (users.some(u => u.admin)) { grant(); }
Defensive patterns

Strategy: validation

Validate before calling

// oxlint --filter unicorn/prefer-array-some src/
// CI gate: oxlint --deny-warnings src/

Prevention

When it happens

Trigger: Boolean-context comparisons on `find`/`findLast` results: `if (users.find(isAdmin) !== undefined) {...}`, `!!list.find(x => x.ok)`, `findLast(fn) != null` style truthiness checks on the found element where the rule can prove only existence is tested. Fires during oxlint analysis of binary expressions and `is_boolean_node` contexts.

Common situations: Existence checks written by developers unfamiliar with `some`, or code auto-converted from `filter(...).length > 0` rewrites. Shows up in bulk when the unicorn ruleset is switched on. Related to the `no-null`/truthiness family of confusion — note `find(fn) != null` also misses `null` elements, which `some` handles correctly.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/2ce12b20612b454f. Report an issue: GitHub.