{"record":{"id":"0dcaf8d364a5e744","repo":"oxc-project/oxc","slug":"prefer-some-over-findindex-or-findla","errorCode":null,"errorMessage":"Prefer `.some(…)` over `.findIndex(…)` or `.findLastIndex(…)`.","messagePattern":"Prefer `\\.some\\(…\\)` over `\\.findIndex\\(…\\)` or `\\.findLastIndex\\(…\\)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs","lineNumber":28,"sourceCode":"use 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    ///\n    /// 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`,\n    /// 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)\n    /// 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)\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Using `.some()` is more idiomatic and easier to read.\n    ///\n    /// ### Examples","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs#L10-L46","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Replace `arr.findIndex(fn) !== -1` with `arr.some(fn)`.","Run `oxlint --fix` for automatic conversion where the fixer applies.","If the index itself is needed afterwards, keep `findIndex` and suppress this one line with `// oxlint-disable-next-line unicorn/prefer-array-some`.","Disable the rule repo-wide via `.oxlintrc.json` if index-based flow control is the house style."],"exampleFix":"// before\nif (rows.findIndex(r => r.size > 100) !== -1) { warn(); }\n\n// after\nif (rows.some(r => r.size > 100)) { warn(); }","handlingStrategy":"validation","validationCode":"// oxlint --filter unicorn/prefer-array-some src/\n// CI gate: oxlint --deny-warnings src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve `findIndex` for when the index itself is used; otherwise express existence with `some`.","Avoid copying `indexOf(...) !== -1` idioms onto `findIndex` results."],"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-14T05:17:10.506Z"}