{"name":"@putout/plugin-spread","version":"3.2.0","type":"module","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"🐊Putout plugin adds ability to remove useless spread","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-spread#readme","main":"lib/index.js","release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git+https://github.com/coderaiser/putout.git"},"scripts":{"publishOnly":"madrun publishOnly","test":"madrun test","watch:test":"madrun watch:test","lint":"madrun lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","fix:lint":"madrun fix:lint","coverage":"madrun coverage","report":"madrun report"},"dependencies":{},"keywords":["putout","putout-plugin","plugin","spread","useless"],"devDependencies":{"@putout/test":"^15.0.0","eslint":"^10.0.0","eslint-plugin-putout":"^31.0.0","madrun":"^13.0.0","superc8":"^12.0.0"},"peerDependencies":{"putout":">=42"},"license":"MIT","engines":{"node":">=22"},"publishConfig":{"access":"public"},"gitHead":"fbf7135fb589bc35bc1083caf0339a4389edf248","_id":"@putout/plugin-spread@3.2.0","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_nodeVersion":"26.8.1","_npmVersion":"12.0.2","dist":{"integrity":"sha512-EDRKPGeve59z1UaaW7XAR/xkse1XZ2Fe5RoP8Sx8Qil26+A5N9LOHolf9lmCaOclixui3rbBSCxIii9wv0+P/w==","shasum":"18e2cc201dba9bd0fea82d9144c71bf4a65f67da","tarball":"http://registry-npm.ywwl.com/@putout/plugin-spread/download/@putout/plugin-spread-3.2.0.tgz","fileCount":10,"unpackedSize":12323,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDMK0rP8h0PClrDdChbcNTVt81zb7lp6Wz4gnmOs5pVWAIgQIFKihyimXoPFOJgD4RXNg0smOOgnaWXvWQfzVNFMjM="}],"size":4371,"noattachment":false,"key":"/@putout/plugin-spread/-/@putout/plugin-spread-3.2.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/plugin-spread_3.2.0_1788514320790_0.5793750781770612"},"_hasShrinkwrap":false,"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":1788514320958,"_cnpm_publish_time":1788514320958,"dist-tags":{"latest":"3.2.0"}}