Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tbashiyy committed Nov 4, 2024
1 parent 310dc5c commit b6f735b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ fn test() {
r"array.flatMap(() => x)",
r"array.flatMap((x, y) => x)",
r"array.flatMap(x => y)",
r"(array?.flatMap)?.(x => y)",
r"new array.reduce((a, b) => a.concat(b), [])",
r"array.reduce",
r"reduce((a, b) => a.concat(b), [])",
Expand Down Expand Up @@ -388,6 +389,7 @@ fn test() {

let fail = vec![
r"array.flatMap(x => x)",
r"(array?.flatMap)?.(x => x)",
r"function foo(){return[].flatMap(x => x)}",
r"foo.flatMap(x => x) instanceof Array",
r"array.reduce((a, b) => a.concat(b), [])",
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/snapshots/prefer_array_flat.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 353
snapshot_kind: text
---
eslint-plugin-unicorn(prefer-array-flat): Prefer Array#flat() over legacy techniques to flatten arrays.
╭─[prefer_array_flat.tsx:1:1]
Expand All @@ -8,6 +10,13 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Call `.flat()` on the array instead.

eslint-plugin-unicorn(prefer-array-flat): Prefer Array#flat() over legacy techniques to flatten arrays.
╭─[prefer_array_flat.tsx:1:1]
1 │ (array?.flatMap)?.(x => x)
· ──────────────────────────
╰────
help: Call `.flat()` on the array instead.

eslint-plugin-unicorn(prefer-array-flat): Prefer Array#flat() over legacy techniques to flatten arrays.
╭─[prefer_array_flat.tsx:1:22]
1function foo(){return[].flatMap(x => x)}
Expand Down

0 comments on commit b6f735b

Please sign in to comment.