Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@putout/plugin-remove-useless-spread

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/plugin-remove-useless-spread

🐊Putout plugin adds ability to remove useless spread

  • 11.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
increased by22.11%
Maintainers
1
Weekly downloads
 
Created
Source

@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.

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

Keywords

FAQs

Package last updated on 19 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc