Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Rule for PreferArrayFlatMap {

if let Some(first_arg) = flat_call_expr.arguments.first() {
if let Argument::NumericLiteral(number_lit) = first_arg {
if number_lit.raw.as_ref().unwrap() != "1" {
if (number_lit.value - 1.0).abs() > f64::EPSILON {
return;
}
} else {
Expand Down Expand Up @@ -117,7 +117,6 @@ fn test() {
("const bar = [[1],[2],[3]].map(i => [i]).flat(+1)", None),
("const bar = [[1],[2],[3]].map(i => [i]).flat(foo)", None),
("const bar = [[1],[2],[3]].map(i => [i]).flat(foo.bar)", None),
("const bar = [[1],[2],[3]].map(i => [i]).flat(1.00)", None),
];

let fail = vec![
Expand All @@ -134,6 +133,7 @@ fn test() {
("const bar = (([1,2,3].map(i => [i]))).flat()", None),
("let bar = [1,2,3] . map( x => y ) . flat () // 🤪", None),
("const bar = [1,2,3].map(i => [i]).flat(1);", None),
("const bar = [[1],[2],[3]].map(i => [i]).flat(1.00)", None),
];

let fix = vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,10 @@ source: crates/oxc_linter/src/tester.rs
· ─────────────────────────────
╰────
help: Prefer `.flatMap(…)` over `.map(…).flat()`.

⚠ eslint-plugin-unicorn(prefer-array-flat-map): `Array.flatMap` performs `Array.map` and `Array.flat` in one step.
╭─[prefer_array_flat_map.tsx:1:13]
1 │ const bar = [[1],[2],[3]].map(i => [i]).flat(1.00)
· ──────────────────────────────────────
╰────
help: Prefer `.flatMap(…)` over `.map(…).flat()`.
Loading