{"record":{"id":"2ce12b20612b454f","repo":"oxc-project/oxc","slug":"prefer-some-over-find-or-findlast","errorCode":null,"errorMessage":"Prefer `.some(…)` over `.find(…)` or `.findLast(…)`.","messagePattern":"Prefer `\\.some\\(…\\)` over `\\.find\\(…\\)` or `\\.findLast\\(…\\)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs","lineNumber":19,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, BinaryExpression, Expression, UnaryOperator},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::BinaryOperator;\n\nuse crate::{\n    AstNode,\n    ast_util::{call_expr_method_callee_info, is_method_call, outermost_paren_parent},\n    context::LintContext,\n    rule::Rule,\n    utils::is_boolean_node,\n};\n\nfn over_method(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `.some(…)` over `.find(…)` or `.findLast(…)`.\").with_label(span)\n}\n\nfn non_zero_filter(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `.some(…)` over non-zero length check from `.filter(…)`.\")\n        .with_label(span)\n}\n\nfn negative_one_or_zero_filter(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `.some(…)` over `.findIndex(…)` or `.findLastIndex(…)`.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferArraySome;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace `arr.find(fn) !== undefined` with `arr.some(fn)`.","Run `oxlint --fix` where the rule offers a fixer for the exact pattern.","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).","Disable the rule in `.oxlintrc.json` if boolean-from-find is pervasive and intentional."],"exampleFix":"// before\nif (users.find(u => u.admin) !== undefined) { grant(); }\n\n// after\nif (users.some(u => u.admin)) { grant(); }","handlingStrategy":"validation","validationCode":"// oxlint --filter unicorn/prefer-array-some src/\n// CI gate: oxlint --deny-warnings src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `some`/`every` for existence/universality checks; `find` only when the element is consumed.","Note `find(fn) != null` is doubly wrong when arrays can contain `null` — some() avoids that trap."],"tags":["oxlint","unicorn","arrays","boolean-logic","refactor"],"backgroundTag":"lint-rule-violation","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}