diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs b/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs index 641a7fe184359..0191781703191 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_array_some.rs @@ -256,11 +256,21 @@ impl Rule for PreferArraySome { debug_assert!(target_span.is_some()); - if let Some(target_span) = target_span { - fixer.replace(target_span, "some") - } else { - fixer.noop() - } + let Some(target_span) = target_span else { + return fixer.noop(); + }; + + // Replace `filter` with `some` and delete `.length > 0` or `.length !== 0` + let multi_fixer = fixer.for_multifix(); + let mut multi_fix = multi_fixer.new_fix_with_capacity(2); + multi_fix.push(multi_fixer.replace(target_span, "some")); + multi_fix.push( + multi_fixer.delete_range(Span::new( + left_call_expr.span.end, + bin_expr.span.end, + )), + ); + multi_fix.with_message("Replace `.filter(โ€ฆ).length` with `.some(โ€ฆ)`") }, ); } @@ -448,8 +458,8 @@ fn test() { r#"const foo = array.find(element => element === "๐Ÿฆ„") ? bar : baz;"#, r#"const foo = array.some(element => element === "๐Ÿฆ„") ? bar : baz;"#, ), - (r"array.filter(fn).length > 0", r"array.some(fn).length > 0"), - (r"array.filter(fn).length !== 0", r"array.some(fn).length !== 0"), + (r"array.filter(fn).length > 0", r"array.some(fn)"), + (r"array.filter(fn).length !== 0", r"array.some(fn)"), (r"foo.find(fn) == null", r"foo.some(fn) == null"), (r"foo.find(fn) == undefined", r"foo.some(fn) == undefined"), (r"foo.find(fn) === undefined", r"foo.some(fn) === undefined"), diff --git a/crates/oxc_linter/src/snapshots/unicorn_prefer_array_some.snap b/crates/oxc_linter/src/snapshots/unicorn_prefer_array_some.snap index c019faaff61d5..1bfc06ee43769 100644 --- a/crates/oxc_linter/src/snapshots/unicorn_prefer_array_some.snap +++ b/crates/oxc_linter/src/snapshots/unicorn_prefer_array_some.snap @@ -1,5 +1,6 @@ --- source: crates/oxc_linter/src/tester.rs +assertion_line: 444 --- โš  eslint-plugin-unicorn(prefer-array-some): Prefer `.some(โ€ฆ)` over `.find(โ€ฆ)` or `.findLast(โ€ฆ)`. โ•ญโ”€[prefer_array_some.tsx:1:9] @@ -34,14 +35,14 @@ source: crates/oxc_linter/src/tester.rs 1 โ”‚ array.filter(fn).length > 0 ยท โ”€โ”€โ”€โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `filter` with `some`. + help: Replace `.filter(โ€ฆ).length` with `.some(โ€ฆ)` โš  eslint-plugin-unicorn(prefer-array-some): Prefer `.some(โ€ฆ)` over non-zero length check from `.filter(โ€ฆ)`. โ•ญโ”€[prefer_array_some.tsx:1:7] 1 โ”‚ array.filter(fn).length !== 0 ยท โ”€โ”€โ”€โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `filter` with `some`. + help: Replace `.filter(โ€ฆ).length` with `.some(โ€ฆ)` โš  eslint-plugin-unicorn(prefer-array-some): Prefer `.some(โ€ฆ)` over `.find(โ€ฆ)` or `.findLast(โ€ฆ)`. โ•ญโ”€[prefer_array_some.tsx:1:5]