Skip to content

Files

Latest commit

09ae161 · Apr 13, 2024

History

History
This branch is 2815 commits behind coderaiser/putout:master.

plugin-convert-object-assign-to-merge-spread

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jun 21, 2023
Jun 21, 2023
Jul 20, 2022
Jan 6, 2022
Jun 21, 2023
Apr 10, 2024
Apr 13, 2024
Jun 21, 2023
Mar 22, 2019
Jun 29, 2022
Apr 8, 2024

@putout/plugin-convert-object-assign-to-merge-spread NPM version

The Object.assign() method copies all enumerable own properties from one or more source objects to a target object and returns the modified target object.

Spread syntax (...) allows an object expression to be expanded in places where zero or more key-value pairs are expected.

(c) MDN

🐊Putout plugin adds ability to convert Object.assign() to merge spread since it shorter but does (mostly) the same.

Install

npm i @putout/plugin-convert-object-assign-to-merge-spread -D

Rule

{
    "rules": {
        "convert-object-assign-to-merge-spread": "on"
    }
}

❌ Example of incorrect code

function merge(a) {
    return Object.assign({}, a, {
        hello: 'world',
    });
}

✅ Example of correct code

function merge(a) {
    return {
        ...a,
        hello: 'world',
    };
}

Comparison

Linter Rule Fix
🐊 Putout convert-object-assign-to-merge-spread
ESLint prefer-object-spread

License

MIT