Socket
Socket
Sign inDemoInstall

eslint-plugin-prefer-object-spread

Package Overview
Dependencies
88
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eslint-plugin-prefer-object-spread

ESLint rule for suggesting that object spread properties be used instead of Object.assign().


Version published
Weekly downloads
30K
decreased by-14.04%
Maintainers
1
Install size
7.75 kB
Created
Weekly downloads
 

Readme

Source

build status test coverage npm

eslint-plugin-prefer-object-spread

ESLint rule for suggesting that object spread properties be used instead of Object.assign().

Installation

Install ESLint and eslint-plugin-prefer-object-spread:

$ npm install --save-dev eslint eslint-plugin-prefer-object-spread

Usage

Add prefer-object-spread to the plugins section of your .eslintrc configuration file, and configure the rule under the rules section.

{
  "plugins": [
    "prefer-object-spread"
  ],
  "rules": {
    "prefer-object-spread/prefer-object-spread": 2
  }
}

This rule suggests that object spread properties be used instead of Object.assign(). The rule is only applied when Object.assign() is used for cloning; not when it is used to extend an existing object. i.e., it applies when the first argument to Object.assign() is an object literal. This is because spread properties only iterate over own properties.

When using this rule the following patterns are considered problems:

var a = Object.assign({}, foo); // error Use a spread property instead of Object.assign().

var b = Object.assign({ c: 1 }, bar); // error Use a spread property instead of Object.assign().

The following patterns are considered okay:

var a = { ...foo };

var b = { c: 1, ...bar };

Object.assign(b, { d: 2 });

Keywords

FAQs

Last updated on 18 Apr 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc