{"name":"@putout/plugin-spread","version":"3.0.0","keywords":["putout","putout-plugin","plugin","spread","useless"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-spread@3.0.0","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-spread#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"e739af9cbb3b02132922d9d3dff5947b9d2ecbdb","tarball":"http://registry-npm.ywwl.com/@putout/plugin-spread/download/@putout/plugin-spread-3.0.0.tgz","fileCount":9,"integrity":"sha512-mUqpferkGZQd731RUXQQaQnHLl936qfIvFAASswyDPB4x3Ztzw7KjpQ9ShxbmuJgGjhY8MylADX8Fe6szcuaSA==","signatures":[{"sig":"MEYCIQDcJXwlXit/OBeeFDAZwzbRJYWWBXcyGnetg+Qv8YXx9wIhAIX28UukcC6wD2IsqjVIRE6hunA0AlyWdi1s+o22u/nZ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10902,"size":3988,"noattachment":false,"key":"/@putout/plugin-spread/-/@putout/plugin-spread-3.0.0.tgz"},"main":"lib/index.js","type":"module","engines":{"node":">=22"},"gitHead":"efdde5b548c671ac4c40f147fab8d5e416f0d0c5","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test","publishOnly":"madrun publishOnly"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"11.4.2","description":"🐊Putout plugin adds ability to remove useless spread","directories":{},"_nodeVersion":"22.22.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","eslint":"^10.0.0","madrun":"^13.0.0","@putout/test":"^15.0.0","eslint-plugin-putout":"^31.0.0"},"peerDependencies":{"putout":">=42"},"_npmOperationalInternal":{"tmp":"tmp/plugin-spread_3.0.0_1771279999938_0.3575791992538564","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/plugin-spread [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-spread.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-spread \"npm\"\n\n> **Spread** syntax can be used when all elements from an object or array need to be included in a list of some kind.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to transform **spread** syntax.\n\n## Install\n\n```\nnpm i @putout/plugin-spread\n```\n\n## Rules\n\n- ✅ [remove-useless-logical](#remove-useless-logical)\n- ✅ [convert-apply-to-spread](#convert-apply-to-spread);\n- ✅ [convert-convert-object-assign-to-merge-spread](#convert-object-assign-to-merge-spread);\n- ✅ [simplify-nested](#simplify-nested);\n- ✅ [remove-useless-array](#remove-useless-array);\n- ✅ [remove-useless-object](#remove-useless-object);\n\n## Rule\n\n```json\n{\n    \"rules\": {\n        \"spread/convert-apply-to-spread\": \"on\",\n        \"spread/convert-object-assign-to-merge-spread\": \"on\",\n        \"spread/remove-useless-array\": \"on\",\n        \"spread/remove-useless-object\": \"on\",\n        \"spread/simplify-nested\": \"on\",\n        \"spread/remove-useless-logical\": \"on\"\n    }\n}\n```\n\n## convert-object-assign-to-merge-spread\n\n> The [`Object.assign()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) method copies all enumerable own properties from one or more source objects to a target object and returns the modified target object.\n>\n> [**Spread**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) syntax (`...`) allows an object expression to be expanded in places where zero or more key-value pairs are expected.\n>\n> (c) MDN\n\nConvert `Object.assign()` to merge **spread** since it shorter but does (mostly) the same.\n\n### ❌ Example of incorrect code\n\n```js\nfunction merge(a) {\n    return Object.assign({}, a, {\n        hello: 'world',\n    });\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfunction merge(a) {\n    return {\n        ...a,\n        hello: 'world',\n    };\n}\n```\n\n### Comparison\n\n| Linter        | Rule | Fix |\n|---------------|------|-----|\n| 🐊 **Putout** | [`spread/convert-object-assign-to-merge-spread`](https://github.com/coderaiser/putout/tree/master/packages/plugin-spread#convert-object-assign-to-merge-spread) | ✅   |\n| ⏣ **ESLint**  | [`prefer-object-spread`](https://eslint.org/docs/rules/prefer-object-spread) | ✅   |\n\n## remove-useless-array\n\nThe thing is `[...b]` can be used for:\n\n- copying an array;\n- converting different value type like `string` to an `array`.\n\nSo better to be more concrete and use `slice` for copying and `Array()`/`Array.from()` for converting to decrease cognitive load.\nAlso sometimes there is no need on any of this operations, and we can drop `spread`.\n\n### ❌ Example of incorrect code\n\n```js\nfor (const a of [...b]) {}\n\nconst places = [...getPlaces()];\n```\n\n### ✅ Example of correct code\n\n```js\nfor (const a of b) {}\n\nconst places = getPlaces();\n\n// Array constructor creates sparse array\n[...Array(5)].map(Number);\n```\n\n## remove-useless-object\n\n### ❌ Example of incorrect code\n\n```js\nconst a = {\n    ...fn(),\n};\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = fn();\n```\n\n## nested\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/60e5a99112affb8a629347e5bf04aedf/38b33f3b5b133897b346a018462c431824e64bb8).\n\n### ❌ Example of incorrect code\n\n```js\n[\n    ...[\n        ...a,\n        ...b,\n    ],\n    ...x,\n];\n```\n\n### ✅ Example of correct code\n\n```js\n[\n    ...a,\n    ...b,\n    ...x,\n];\n```\n\n## convert-apply-to-spread\n\n> Spread syntax (`...`) allows an array expression to be expanded in places where zero or more arguments are expected.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)\n\n### ❌ Example of incorrect code\n\n```js\nconsole.apply(null, arguments);\n```\n\n### ✅ Example of correct code\n\n```js\nconsole.log(...arguments);\n```\n\n## remove-useless-logical\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6ceb0366f6576b18d4c08afe266ee637/da9616c2ad6f21472704d44e65609e81de22721c).\n\n### ❌ Example of incorrect code\n\n```js\nconst state = {\n    workbench: {\n        ...base.workbench,\n        ...overrides.workbench || {},\n    },\n};\n```\n\n### ✅ Example of correct code\n\n```js\nconst state = {\n    workbench: {\n        ...base.workbench,\n        ...overrides.workbench,\n    },\n};\n```\n\n## License\n\nMIT\n","publish_time":1771280000086,"_cnpm_publish_time":1771280000086,"dist-tags":{"latest":"3.2.0"}}