@putout/plugin-remove-useless-spread v13.0.0
@putout/plugin-remove-useless-spread 
Spread syntax can be used when all elements from an object or array need to be included in a list of some kind.
(c) MDN
πPutout plugin adds ability to remove useless spread syntax.
Install
npm i @putout/plugin-remove-useless-spreadRule
{
"rules": {
"remove-useless-spread/array": "on",
"remove-useless-spread/object": "on",
"remove-useless-spread/nested": "on"
}
}array
The thing is [...b] can be used for:
- copying an array;
- converting different value type like
stringto anarray.
So better to be more concrete and use slice for copying and Array()/Array.from() for converting to decrease cognitive load.
Also sometimes there is no need on any of this operations, and we can drop spread.
β Example of incorrect code
for (const a of [...b]) {}
const places = [...getPlaces()];β Example of correct code
for (const a of b) {}
const places = getPlaces();
// Array constructor creates sparse array
[...Array(5)].map(Number);object
β Example of incorrect code
const a = {
...fn(),
};β Example of correct code
const a = fn();nested
Checkout in πPutout Editor.
β Example of incorrect code
[
...[
...a,
...b,
],
...x,
];β Example of correct code
[
...a,
...b,
...x,
];License
MIT
6 months ago
9 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago