@putout/plugin-remove-useless-spread
putout plugin adds ability to remove useless spread
Last updated 4 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-remove-useless-spread 
SYNC missed versions from official npm registry.

@putout/plugin-remove-useless-spread NPM version

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. Merged with @putout/plugin-spread.

Install

npm i @putout/plugin-remove-useless-spread

Rule

{
    "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 string to an array.

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

Current Tags

  • 13.1.1                                ...           latest (4 months ago)

30 Versions

  • 13.1.1                                ...           4 months ago
  • 13.1.0                                ...           5 months ago
  • 13.0.0                                ...           a year ago
  • 12.0.0                                ...           a year ago
  • 11.1.0                                ...           2 years ago
  • 11.0.0                                ...           2 years ago
  • 10.0.1                                ...           2 years ago
  • 10.0.0                                ...           2 years ago
  • 9.0.0                                ...           3 years ago
  • 8.0.1                                ...           3 years ago
  • 8.0.0                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 6.1.0                                ...           3 years ago
  • 6.0.0                                ...           4 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.0                                ...           5 years ago
  • 5.0.1                                ...           5 years ago
  • 5.0.0                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.0                                ...           6 years ago
  • 3.1.1                                ...           6 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.1.1                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |