1. eslint-plugin-prefer-object-spread
ESLint rule for suggesting that object spread properties be used instead of Object.assign().
eslint-plugin-prefer-object-spread
Package: eslint-plugin-prefer-object-spread
Created by: bryanrsmith
Last modified: Fri, 17 Jun 2022 20:39:04 GMT
Version: 1.2.1
License: MIT
Downloads: 137,095
Repository: https://github.com/bryanrsmith/eslint-plugin-prefer-object-spread

Install

npm install eslint-plugin-prefer-object-spread
yarn add eslint-plugin-prefer-object-spread

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 });

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code