{"name":"@putout/plugin-assignment","version":"3.0.1","keywords":["putout","putout-plugin","plugin","assignment"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-assignment@3.0.1","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-assignment#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"94790b4e50c7f79686ea0b769d4cfc2d655b43a1","tarball":"http://registry-npm.ywwl.com/@putout/plugin-assignment/download/@putout/plugin-assignment-3.0.1.tgz","fileCount":10,"integrity":"sha512-K4pACuzq7ApsSHa/wZhexPmFiSzlT4JT/N3rwIzWgQDPPReBhlGt15gEUC90RrTP9Zq2w98SMxK3+wbm4K+KGg==","signatures":[{"sig":"MEUCIQCXPVCN42tC4zOo735HdbnNamhmg/pUyP/Y/fDnMprDuQIgXlFNheQHTG+Jzqd93fO1gjGDM4Pioweq3YW6OsTUMPI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":13194,"size":4481,"noattachment":false,"key":"/@putout/plugin-assignment/-/@putout/plugin-assignment-3.0.1.tgz"},"main":"lib/index.js","type":"module","engines":{"node":">=22"},"exports":{".":"./lib/index.js"},"gitHead":"f473e3bc73762dfab240a1975ca94a8b3085cfa1","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"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"12.0.2","description":"🐊Putout plugin adds ability to transform code related to assignment","directories":{},"_nodeVersion":"26.8.1","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^10.0.0","madrun":"^13.0.0","montag":"^2.0.0","nodemon":"^3.0.1","superc8":"^12.0.0","@putout/test":"^15.0.0","@putout/eslint-flat":"^4.0.0","eslint-plugin-putout":"^31.0.0","@putout/plugin-putout":"*","@putout/plugin-declare":"*","@putout/plugin-typescript":"*","@putout/plugin-reuse-duplicate-init":"*","@putout/plugin-declare-before-reference":"*"},"peerDependencies":{"putout":">=42"},"_npmOperationalInternal":{"tmp":"tmp/plugin-assignment_3.0.1_1788515935740_0.3328875569219385","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/plugin-assignment [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-assignment.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-assignment \"npm\"\n\n> The [**assignment operator**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment) (`=`) is used to assign a value to a variable. The assignment operation evaluates to the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables.\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to transform to new **Node.js** API and apply best practices.\n\n## Install\n\n```\nnpm i putout @putout/plugin-assignment -D\n```\n\n## Rules\n\n- ✅ [remove-useless-undefined](#remove-useless-undefined)\n- ✅ [convert-to-arrow-function](#convert-to-arrow-function);\n- ✅ [convert-to-comparison](#convert-to-comparison);\n- ✅ [convert-to-declaration](#convert-to-declaration);\n- ✅ [simplify](#simplify);\n- ✅ [split](#split);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"assignment/convert-to-arrow-function\": \"on\",\n        \"assignment/convert-to-comparison\": \"on\",\n        \"assignment/convert-to-declaration\": \"on\",\n        \n        \"assignment/remove-useless-undefined\": \"on\",\n        \"assignment/simplify\": \"on\",\n        \"assignment/split\": \"on\"\n    }\n}\n```\n\n## convert-to-arrow-function\n\n> An [**arrow function expression**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) is a compact alternative to a **function expression**.\n>\n> (c) MDN\n\nRule adds ability to convert **assignment** to **arrow** function.\n\n### ❌ Example of incorrect code\n\n```js\nconst createRegExp = a = RegExp(a, 'g');\n```\n\n### ✅ Example of correct code\n\n```js\nconst createRegExp = (a) => RegExp(a, 'g');\n```\n\n## convert-to-comparison\n\n> You should almost never have an `if...else` with an assignment like `a = b` as a condition.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)\n\n### ❌ Example of incorrect code\n\n```js\nif (a = b) {}\n```\n\n### ✅ Example of correct code\n\n```js\nif (a === b) {}\n```\n\n## convert-to-declaration\n\n> The `const` declaration declares block-scoped local variables. The value of a constant can't be changed through reassignment using the assignment operator, but if a constant is an object, its properties can be added, updated, or removed.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const)\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/857e6bdc83dc2ee947b2945f6600d417/34d1c3852d85225da7eabdf9b91c138b7533c60b).\n\n## ❌ Example of incorrect code\n\n```js\na = 5;\n```\n\n## ✅ Example of correct code\n\n```js\nconst a = 5;\n```\n\n## simplify\n\n### ❌ Example of incorrect code\n\n```js\nconst {a} = {\n    a: 5,\n};\n\nconst [b] = [5];\nconst c = (() => 7)();\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = 5;\nconst b = 5;\nconst c = 7;\n```\n\n## split\n\nRule adds ability to find and split variable declarations because (re)moving a line is simpler and less error prone then changing coma (`=`) to colon (`;`).\n\nFor the same reason, **diff** of changed declarations are more comfortable to read. Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fee33133e2313c3a741193570e307a58/f8fae66c93acc546194df49fff2a5fc13de8434c).\n\n## ❌ Example of incorrect code\n\n```js\na = b = c = 1;\n```\n\n## ✅ Example of correct code\n\n```js\na = 1;\nb = a;\nc = a;\n```\n\n## remove-useless-undefined\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/de00120e433802e73ae9464b4e63b718/e4cd06b2486afce08e213809de9f0dba7b2e94ea).\n\n### ❌ Example of incorrect code\n\n```js\nconst x = ({a} = {\n    a: undefined,\n    b: '',\n}) => a;\n```\n\n### ✅ Example of correct code\n\n```js\nconst x = ({a} = {\n    b: '',\n}) => a;\n```\n\n## License\n\nMIT\n","publish_time":1788515935871,"_cnpm_publish_time":1788515935871,"dist-tags":{"latest":"3.1.0"}}