oxc-project/oxc · warning · OxcDiagnostic

Prefer `.some(…)` over `.findIndex(…)` or `.findLastIndex(…)

Error message

Prefer `.some(…)` over `.findIndex(…)` or `.findLastIndex(…)`.

What it means

Lint diagnostic from oxlint's `unicorn/prefer-array-some` rule (variant `negative_one_or_zero_filter`). `findIndex(fn)` already returns the boolean answer in sign form (`-1` = not found), so comparing it against `-1` or `0` (`findIndex(fn) !== -1`, `findIndex(fn) >= 0`) is an indirect existence check. `some(fn)` states the intent directly.

Source

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

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
    ///
    /// 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?
    ///
    /// Using `.some()` is more idiomatic and easier to read.
    ///
    /// ### Examples

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace `arr.findIndex(fn) !== -1` with `arr.some(fn)`.
  2. Run `oxlint --fix` for automatic conversion where the fixer applies.
  3. If the index itself is needed afterwards, keep `findIndex` and suppress this one line with `// oxlint-disable-next-line unicorn/prefer-array-some`.
  4. Disable the rule repo-wide via `.oxlintrc.json` if index-based flow control is the house style.

Example fix

// before
if (rows.findIndex(r => r.size > 100) !== -1) { warn(); }

// after
if (rows.some(r => r.size > 100)) { warn(); }
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: `if (items.findIndex(isBig) !== -1) {...}`, `items.findLastIndex(fn) >= 0`, `findIndex(fn) > -1` — index comparisons that reduce to 'any match exists'. Detected during oxlint runs when the rule sees `findIndex`/`findLastIndex` results in `-1`/`0` comparisons inside boolean contexts.

Common situations: Habit carried over from `indexOf(fn) !== -1` idioms applied to `findIndex`. Common in validation and 'contains matching' checks. Surfaces in bulk when the unicorn category is enabled in oxlint config.

Related errors


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