{"name":"@putout/plugin-variables","version":"2.7.2","type":"module","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"🐊Putout plugin adds ability to find and remove useless","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-variables#readme","main":"lib/index.js","release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git+https://github.com/coderaiser/putout.git"},"scripts":{"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","putout-plugin-remove","plugin","remove","useless","variables"],"devDependencies":{"@putout/eslint-flat":"^4.0.0","@putout/plugin-declare":"*","@putout/plugin-for-of":"*","@putout/plugin-maybe":"*","@putout/plugin-minify":"*","@putout/plugin-nodejs":"*","@putout/plugin-putout":"*","@putout/plugin-reuse-duplicate-init":"*","@putout/plugin-tape":"*","@putout/test":"^15.0.0","eslint":"^10.0.0","eslint-plugin-putout":"^31.0.0","just-camel-case":"^6.2.0","madrun":"^13.0.0","montag":"^2.0.0","nodemon":"^3.0.1","superc8":"^12.0.0","supertape":"^13.0.0","try-catch":"^4.0.0"},"peerDependencies":{"putout":">=42"},"license":"MIT","engines":{"node":">=22"},"publishConfig":{"access":"public"},"_id":"@putout/plugin-variables@2.7.2","gitHead":"54c69e06b53652fd233481dc84166db6f4a5f576","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_nodeVersion":"26.7.0","_npmVersion":"11.2.0","dist":{"integrity":"sha512-ptFF5uXEdacE2uQuTdjtbEsXg9w8tz0Jeu3UcfFyv83CI3G+ETV4dXxpKFPp/tKfiSibjRS6o4d/SpcEczjrZA==","shasum":"3fbdb3f434448eb39562ee45a5f96503a1076c41","tarball":"http://registry-npm.ywwl.com/@putout/plugin-variables/download/@putout/plugin-variables-2.7.2.tgz","fileCount":26,"unpackedSize":73168,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBX9+oLWLJJv2FT0KcrkIShy3mKtMj2JdDNeT0y17qzLAiBZXxNv3h//qFhcS6HrxzW4LsDnmpJ+PC3vRVFRWsW5TQ=="}],"size":14910,"noattachment":false,"key":"/@putout/plugin-variables/-/@putout/plugin-variables-2.7.2.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-variables_2.7.2_1787643596632_0.7440824959484911"},"_hasShrinkwrap":false,"readme":"# @putout/plugin-variables [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-variables.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-variables \"npm\"\n\n> A **variable** is a named reference to a **value**.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Glossary/Variable)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to transform `variables`.\n\n## Install\n\n```\nnpm i @putout/plugin-variables -D\n```\n\n## Rules\n\n- ✅ [apply-declarations-order](#apply-declarations-order);\n- ✅ [convert-const-to-let](#convert-const-to-let');\n- ✅ [extract-keywords](#extract-keywords');\n- ✅ [reuse-duplicate-init](#reuse-duplicate-init);\n- ✅ [remove-useless-assignment](#remove-useless-assignmenn);\n- ✅ [remove-useless-declaration](#remove-useless-declaration);\n- ✅ [remove-useless-duplicate](#remove-useless-duplicate);\n- ✅ [remove-useless-variables](#remove-useless-variables);\n- ✅ [remove-useless-rename](#remove-useless-rename);\n- ✅ [remove-unused](#remove-unused);\n- ✅ [split-declarations](#split-declarations);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"variables/apply-declarations-order\": \"on\",\n        \"variables/convert-const-to-let\": \"on\",\n        \"variables/extract-keywords\": \"on\",\n        \"variables/reuse-duplicate-init\": \"on\",\n        \"variables/remove-useless-assignment\": \"on\",\n        \"variables/remove-useless-declaration\": [\"on\", {\n            \"maxLength\": 20\n        }],\n        \"variables/remove-useless-duplicate\": \"on\",\n        \"variables/remove-useless-rename\": \"on\",\n        \"variables/remove-useless-remove\": \"on\",\n        \"variables/remove-unused\": \"on\",\n        \"variables/split-declarations\": \"on\"\n    }\n}\n```\n\n## apply-declarations-order\n\nHelps to [reuse duplicate init](#reuse-duplicate-init'). Checkout in 🐊[**Putout Editor**](https://putout.vercel.app/#/gist/b70ff926b36e1e97ec7129aa0e0458a7/ece0a706de2fd24a66b4671284f7f75017f3c268).\n\n### ❌ Example of incorrect code\n\n```js\nconst {env} = require('node:process');\nconst process = require('node:process');\n```\n\n### ✅ Example of correct code\n\n```js\nconst process = require('node:process');\nconst {env} = process;\n```\n\n## assignment\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a2f7fe5e2c294443576f95dce6fde67e/0699ccb4f7335e8e3f80de891913a8e3ad4f35e3).\n\n### ❌ Example of incorrect code\n\n```js\nwhile (!(files = readDirectory(parentDir)).length) {}\n```\n\n### ✅ Example of correct code\n\n```js\nwhile (!readDirectory(parentDir).length) {}\n```\n\n## reuse-duplicate-init\n\n> Functions are one of the fundamental building blocks it contains set of statements that performs a calculations, takes some input and returns an output. To use a function, you must define it somewhere in the scope from which you wish to call it.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to reuse duplicate init.\n\n### ❌ Example of incorrect code\n\n```js\nconst putout = require('putout');\n\nconst {\n    a,\n    b,\n    operator,\n} = require('putout');\n\nconst {replaceWith} = operator;\n```\n\n### ✅ Example of correct code\n\n```js\nconst putout = require('putout');\n\nconst {\n    a,\n    b,\n    operator,\n} = putout;\n\nconst {replaceWith} = operator;\n```\n\n## remove-useless-rename\n\n### ❌ Example of incorrect code\n\n```js\nfunction hi(a) {\n    const b = a;\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfunction hi(b) {}\n```\n\n## remove\n\n### ❌ Example of incorrect code\n\n```js\nconst child_process = require('node:child_process');\n\nconst {exec, spawn} = child_process;\n```\n\n### ✅ Example of correct code\n\n```js\nconst {exec, spawn} = require('node:child_process');\n```\n\n### remove\n\nCheck it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/041767876a6d41c82260b293a06c2b6b/addf2b49cf9235d9b7a1017065cec5dece232660).\n\n### ❌ Example of incorrect code\n\n```js\nconst a = 5;\nconst b = a;\n\nconst c = 5;\n\nd = c;\n```\n\n### ✅ Example of correct code\n\n```js\nconst b = 5;\n\nd = 5;\n```\n\n### remove-useless-declaration\n\nCheck it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/32177535829956ef4c7b51587a8853c3/1fe071ff6542dc66ffad55f4776733903ab07241).\n\n### ❌ Example of incorrect code\n\n```js\nfunction x() {\n    const a = 5;\n    return a;\n}\n\nconst z = b.c.replace('x', 'y');\n\nb.c = z;\n```\n\n### ✅ Example of correct code\n\n```js\nfunction x() {\n    return 5;\n}\n\nb.c = b.c.replace('x', 'y');\n```\n\n### remove-useless-duplicate\n\nCheck it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/32177535829956ef4c7b51587a8853c3/52f19ab0e467ad7cc54fa8c554c3b0804de9d1ca).\n\n### ❌ Example of incorrect code\n\n```js\nconst DestructuringErrors = function DestructuringErrors(a, b) {\n    return [a, b];\n};\n```\n\n### ✅ Example of correct code\n\n```js\nfunction DestructuringErrors(a, b) {\n    return [a, b];\n}\n\nbc = b.c.replace('x', 'y');\n```\n\n## remove-unreferenced\n\n### ❌ Example of incorrect code\n\n```js\nlet a;\nlet b;\n\na = 5;\nb = 6;\n\nconsole.log(a);\n```\n\n### ✅ Example of correct code\n\n```js\nlet a;\n\na = 5;\n\nconsole.log(a);\n```\n\n## split-declarations\n\n> - The [`let`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let) statement declares a block-scoped local variable, optionally initializing it to a value.\n> - [`const`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) statements are also block-scoped. The value of a constant can't be changed through reassignment, and it can't be redeclared. However, if a constant is an **object** or **array** its properties or items can be updated or removed.\n>\n> (c) MDN\n\nAdd ability to find and split variable declarations because (re)moving a line is simpler and less error prone then changing coma (`,`) to colon (`;`).\nFor the same reason, **diff** of changed declarations are more comfortable to read.\n\n### ❌ Example of incorrect code\n\n```js\nlet a, b;\n```\n\n### ✅ Example of correct code\n\n```js\nlet a;\nlet b;\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`remove-debugger`](https://github.com/coderaiser/putout/tree/master/packages/plugin-split-variable-declarations#readme) | ✅\n⏣ **ESLint** | [`no-var`](https://eslint.org/docs/latest/rules/one-var) | ✅\n\n## convert-const-to-let\n\n> The `TypeError` object represents an error when attempting to modify a value that cannot be changed.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)\n\nConvert `const` to `let` to avoid `TypeError`.\nCheck out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/61ffff64a356c47e66af4ea17a9a755d/e7f5fa455c208a7faa9319d94130996d39afcbf7).\n\n### ❌ Example of incorrect code\n\n```js\nlet a = 5;\n\na = 3;\n```\n\n### ✅ Example of correct code\n\n```js\nlet a = 5;\n\na = 3;\n```\n\n## remove-unused\n\n> A variable is a container for a value, like a `number` we might use in a sum, or a `string` that we might use as part of a sentence.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Variables)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to find and remove the variables that are declared, but:\n\n- not passed as **argument** to a **function**;\n- not used as **operand** in **expression**;\n\nThat is **unused variables**. Most likely it is a leftovers due to incomplete transforming of the code. Such variables take up space and gives no value so they must be removed.\n\n☝️*Remember, when you [writing a transform](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme) you can skip all parts related to **removing unused variables** and just reuse current **plugin** it will make your code simpler and less error prone.*\n\n☝️*No, you cannot just look at [`referenced` and `constant` fields](https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md#user-content-bindings) to determine if you can remove variable and [here is why](https://putout.cloudcmd.io/#/gist/4277392f74b56b74911b779c9624af8d/cfec476f857dfb4f4c7a6247bdcc6b521fed8e70) one of the biggest plugins exists*.\n\n### ❌ Example of incorrect code\n\n```js\nconst a = 'hello';\nconst b = 'world';\n\nconsole.log(a);\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = 'hello';\nconsole.log(a);\n```\n\n## Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout**| [`remove-unused-variables`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-unused-variables#readme)| ✅\n⏣ **ESLint** | [`no-unused-vars`](https://eslint.org/docs/rules/no-unused-vars) | ❌\n\n## extract-keywords\n\n> The JavaScript exceptions \"unexpected token\" occur when the parser does not see a token it recognizes at the given position, so it cannot make sense of the structure of the program. This might be a simple typo.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_token)\n\nExtract `keywords` from variables. Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fcaedaa9daf7f3a771274aca0da9ab1b/00850a5d28aec86b1b4083ba2ef9f81bd49aaaac).\n\n```diff\n-export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle',\n+export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle';\nexport const isTemplateTail = (a) => a?.type === 'TemplateTail';\n\n-const a 5;\n+const a = 5;\n\n-export const packContent = (content) {\n+export const packContent = (content) => {\n    console.log(a);\n}\n```\n\n## License\n\nMIT\n","publish_time":1787643596771,"_cnpm_publish_time":1787643596771,"dist-tags":{"latest":"2.7.2"}}