Skip to content

Commit 55469e5

Browse files
authoredFeb 2, 2023
no-useless-spread: Check Array#{toReversed,toSorted,toSpliced,with} (#2030)
1 parent fea5b42 commit 55469e5

File tree

4 files changed

+83
-11
lines changed

4 files changed

+83
-11
lines changed
 

‎rules/no-useless-spread.js

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ const uselessArrayCloneSelector = [
7979
'map',
8080
'slice',
8181
'splice',
82+
'toReversed',
83+
'toSorted',
84+
'toSpliced',
85+
'with',
8286
]),
8387
// `String#split()`
8488
methodCallSelector('split'),

‎test/no-useless-spread.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ test.snapshot({
264264
'[...foo.map(bar)]',
265265
'[...foo.slice(1)]',
266266
'[...foo.splice(1)]',
267+
'[...foo.toReversed()]',
268+
'[...foo.toSorted()]',
269+
'[...foo.toSpliced(0, 1)]',
270+
'[...foo.with(0, bar)]',
267271
'[...foo.split("|")]',
268272
'[...Object.keys(foo)]',
269273
'[...Object.values(foo)]',

‎test/snapshots/no-useless-spread.mjs.md

+75-11
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,70 @@ Generated by [AVA](https://avajs.dev).
16771677
`
16781678

16791679
## Invalid #9
1680+
1 | [...foo.toReversed()]
1681+
1682+
> Output
1683+
1684+
`␊
1685+
1 | foo.toReversed()␊
1686+
`
1687+
1688+
> Error 1/1
1689+
1690+
`␊
1691+
> 1 | [...foo.toReversed()]␊
1692+
| ^^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
1693+
`
1694+
1695+
## Invalid #10
1696+
1 | [...foo.toSorted()]
1697+
1698+
> Output
1699+
1700+
`␊
1701+
1 | foo.toSorted()␊
1702+
`
1703+
1704+
> Error 1/1
1705+
1706+
`␊
1707+
> 1 | [...foo.toSorted()]␊
1708+
| ^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
1709+
`
1710+
1711+
## Invalid #11
1712+
1 | [...foo.toSpliced(0, 1)]
1713+
1714+
> Output
1715+
1716+
`␊
1717+
1 | foo.toSpliced(0, 1)␊
1718+
`
1719+
1720+
> Error 1/1
1721+
1722+
`␊
1723+
> 1 | [...foo.toSpliced(0, 1)]␊
1724+
| ^^^^^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
1725+
`
1726+
1727+
## Invalid #12
1728+
1 | [...foo.with(0, bar)]
1729+
1730+
> Output
1731+
1732+
`␊
1733+
1 | foo.with(0, bar)␊
1734+
`
1735+
1736+
> Error 1/1
1737+
1738+
`␊
1739+
> 1 | [...foo.with(0, bar)]␊
1740+
| ^^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
1741+
`
1742+
1743+
## Invalid #13
16801744
1 | [...foo.split("|")]
16811745

16821746
> Output
@@ -1692,7 +1756,7 @@ Generated by [AVA](https://avajs.dev).
16921756
| ^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
16931757
`
16941758

1695-
## Invalid #10
1759+
## Invalid #14
16961760
1 | [...Object.keys(foo)]
16971761

16981762
> Output
@@ -1708,7 +1772,7 @@ Generated by [AVA](https://avajs.dev).
17081772
| ^^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
17091773
`
17101774

1711-
## Invalid #11
1775+
## Invalid #15
17121776
1 | [...Object.values(foo)]
17131777

17141778
> Output
@@ -1724,7 +1788,7 @@ Generated by [AVA](https://avajs.dev).
17241788
| ^^^^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
17251789
`
17261790

1727-
## Invalid #12
1791+
## Invalid #16
17281792
1 | [...Array.from(foo)]
17291793

17301794
> Output
@@ -1740,7 +1804,7 @@ Generated by [AVA](https://avajs.dev).
17401804
| ^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
17411805
`
17421806

1743-
## Invalid #13
1807+
## Invalid #17
17441808
1 | [...Array.of()]
17451809

17461810
> Output
@@ -1756,7 +1820,7 @@ Generated by [AVA](https://avajs.dev).
17561820
| ^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
17571821
`
17581822

1759-
## Invalid #14
1823+
## Invalid #18
17601824
1 | [...new Array(3)]
17611825

17621826
> Error 1/1
@@ -1766,7 +1830,7 @@ Generated by [AVA](https://avajs.dev).
17661830
| ^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
17671831
`
17681832

1769-
## Invalid #15
1833+
## Invalid #19
17701834
1 | [...await Promise.all(foo)]
17711835

17721836
> Output
@@ -1782,7 +1846,7 @@ Generated by [AVA](https://avajs.dev).
17821846
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
17831847
`
17841848

1785-
## Invalid #16
1849+
## Invalid #20
17861850
1 | [...await Promise.allSettled(foo)]
17871851

17881852
> Output
@@ -1798,7 +1862,7 @@ Generated by [AVA](https://avajs.dev).
17981862
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unnecessarily cloning an array.␊
17991863
`
18001864

1801-
## Invalid #17
1865+
## Invalid #21
18021866
1 | function foo(bar) {
18031867
2 | return[...Object.keys(bar)];
18041868
3 | }
@@ -1820,7 +1884,7 @@ Generated by [AVA](https://avajs.dev).
18201884
3 | }␊
18211885
`
18221886

1823-
## Invalid #18
1887+
## Invalid #22
18241888
1 | function foo(bar) {
18251889
2 | return[
18261890
3 | ...Object.keys(bar)
@@ -1850,7 +1914,7 @@ Generated by [AVA](https://avajs.dev).
18501914
5 | }␊
18511915
`
18521916

1853-
## Invalid #19
1917+
## Invalid #23
18541918
1 | function foo(bar) {
18551919
2 | return[
18561920
3 | ...(
@@ -1888,7 +1952,7 @@ Generated by [AVA](https://avajs.dev).
18881952
7 | }␊
18891953
`
18901954

1891-
## Invalid #20
1955+
## Invalid #24
18921956
1 | function foo(bar) {
18931957
2 | return([
18941958
3 | ...Object.keys(bar)
183 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.