Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 7, 2024
1 parent 60c57d2 commit bfde04f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions test/prefer-structured-clone.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test.snapshot({
'JSON.parse(JSON.stringify(foo))',
'JSON.parse(JSON.stringify(foo),)',
'JSON.parse(JSON.stringify(foo,))',
'JSON.parse(JSON.stringify(foo,),)',
'JSON.parse( ((JSON.stringify)) (foo))',
'(( JSON.parse)) (JSON.stringify(foo))',
'JSON.parse(JSON.stringify( ((foo)) ))',
Expand Down
35 changes: 27 additions & 8 deletions test/snapshots/prefer-structured-clone.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Generated by [AVA](https://avajs.dev).
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`structuredClone(…)\`.␊
1 | structuredClone(foo)␊
1 | structuredClone(foo,)␊
`

## invalid(3): JSON.parse(JSON.stringify(foo,))
Expand All @@ -57,11 +57,30 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`structuredClone(…)\` over \`JSON.parse(JSON.stringify(…))\` to create a deep clone.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`structuredClone(…)\`.␊
1 | structuredClone(foo)␊
`

## invalid(4): JSON.parse(JSON.stringify(foo,),)

> Input
`␊
1 | JSON.parse(JSON.stringify(foo,),)␊
`

> Error 1/1
`␊
> 1 | JSON.parse(JSON.stringify(foo,),)␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer \`structuredClone(…)\` over \`JSON.parse(JSON.stringify(…))\` to create a deep clone.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to \`structuredClone(…)\`.␊
1 | structuredClone(foo,)␊
`

## invalid(4): JSON.parse( ((JSON.stringify)) (foo))
## invalid(5): JSON.parse( ((JSON.stringify)) (foo))

> Input
Expand All @@ -80,7 +99,7 @@ Generated by [AVA](https://avajs.dev).
1 | structuredClone( foo)␊
`

## invalid(5): (( JSON.parse)) (JSON.stringify(foo))
## invalid(6): (( JSON.parse)) (JSON.stringify(foo))

> Input
Expand All @@ -99,7 +118,7 @@ Generated by [AVA](https://avajs.dev).
1 | (( structuredClone)) (foo)␊
`

## invalid(6): JSON.parse(JSON.stringify( ((foo)) ))
## invalid(7): JSON.parse(JSON.stringify( ((foo)) ))

> Input
Expand All @@ -118,7 +137,7 @@ Generated by [AVA](https://avajs.dev).
1 | structuredClone( ((foo)) )␊
`

## invalid(7): function foo() { return JSON .parse( JSON. stringify( bar, ), ); }
## invalid(8): function foo() { return JSON .parse( JSON. stringify( bar, ), ); }

> Input
Expand Down Expand Up @@ -156,9 +175,9 @@ Generated by [AVA](https://avajs.dev).
1 | function foo() {␊
2 | return structuredClone(␊
3 | ␊
4 | bar,
5 | )
6 | ;␊
4 | bar␊
5 | ,
6 | );␊
7 | }␊
`

Expand Down
Binary file modified test/snapshots/prefer-structured-clone.mjs.snap
Binary file not shown.

0 comments on commit bfde04f

Please sign in to comment.