{"name":"@putout/plugin-conditions","version":"9.2.2","keywords":["putout-plugin","putout","plugin","conditions"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-conditions@9.2.2","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"7e82b7244eeb16a1ed9a1b2939dc8280d5562a2d","tarball":"http://registry-npm.ywwl.com/@putout/plugin-conditions/download/@putout/plugin-conditions-9.2.2.tgz","fileCount":27,"integrity":"sha512-FMn9r6mWNd4lqlRj+vKKc2j0N/7uZmggwwU4Ob0pKJsFqGOzbp5Uuy1MMT0IwGgHVz4WP93kQUySXEnlVhtRWQ==","signatures":[{"sig":"MEQCIAcF4gGliQmHTVijKFfch5hpAdQF64KgRfoUfBn0+Y0oAiB3JXLTYkQlRmVEsEEqBI80mAOIY05c1z+Uz2s9FqelCg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIHgL8rDGJIZWarDGSPilRuQaB4i7J4oee6RTgKq5OdMkAiEAiu76WHsAcvQnKM9GLsTyBvxUsAx0TcRshhDp1F/GzRY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":37343,"size":9810,"noattachment":false,"key":"/@putout/plugin-conditions/-/@putout/plugin-conditions-9.2.2.tgz"},"main":"lib/index.js","type":"module","engines":{"node":">=22"},"gitHead":"6b08b8ac43f24df46a95fe5e3fa5402b4b55aed1","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","wisdom":"madrun wisdom","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 support of conditions transformations","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-for-of":"*"},"peerDependencies":{"putout":">=42"},"_npmOperationalInternal":{"tmp":"tmp/plugin-conditions_9.2.2_1788457843617_0.5174897282375106","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/plugin-conditions [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-conditions.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-conditions \"npm\"\n\n🐊[**Putout**](https://github.com/coderaiser/putout) adds support of conditions transformations.\n\n## Install\n\n```\nnpm i @putout/plugin-conditions -D\n```\n\n## Rules\n\n- ✅ [add-return](#add-return);\n- ✅ [apply-comparison-order](#apply-comparison-order);\n- ✅ [apply-consistent-blocks](#apply-consistent-blocks);\n- ✅ [apply-early-return](#apply-early-return);\n- ✅ [apply-equal](#apply-equal);\n- ✅ [apply-if](#apply-if);\n- ✅ [convert-arrow-to-condition](#convert-arrow-to-condition);\n- ✅ [convert-comparison-to-boolean](#convert-comparison-to-boolean);\n- ✅ [convert-equal-to-strict-equal](#convert-equal-to-strict-equal);\n- ✅ [convert-switch-to-if](#convert-switch-to-if);\n- ✅ [evaluate](#evaluate);\n- ✅ [merge-if-statements](#merge-if-statements);\n- ✅ [merge-if-with-else](#merge-if-with-else);\n- ✅ [remove-boolean](#remove-boolean);\n- ✅ [remove-constant](#remove-constant);\n- ✅ [remove-same-values-condition](#remove-same-values-condition);\n- ✅ [remove-useless-else](#remove-useless-else);\n- ✅ [remove-useless-loop-condition](#remove-useless-loop-condition);\n- ✅ [remove-zero](#remove-zero);\n- ✅ [reverse](#reverse);\n- ✅ [simplify](#simplify);\n- ✅ [wrap-with-block](#wrap-with-block);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"conditions/add-return\": \"on\",\n        \"conditions/apply-comparison-order\": \"on\",\n        \"conditions/apply-consistent-blocks\": \"on\",\n        \n        \"conditions/apply-equal\": \"on\",\n        \"conditions/apply-if\": \"on\",\n        \"conditions/apply-return-return\": \"on\",\n        \n        \"conditions/convert-arrow-to-condition\": \"on\",\n        \"conditions/convert-comparison-to-boolean\": \"on\",\n        \"conditions/convert-equal-to-strict-equal\": \"on\",\n        \"conditions/convert-switch-to-if\": \"on\",\n        \"conditions/evaluate\": \"on\",\n        \n        \"conditions/merge-if-statements\": \"on\",\n        \"conditions/merge-if-with-else\": \"on\",\n        \"conditions/remove-boolean\": \"on\",\n        \"conditions/remove-constant\": \"on\",\n        \n        \"conditions/remove-same-values-condition\": \"on\",\n        \"conditions/remove-useless-else\": \"on\",\n        \"conditions/remove-useless-loop-condition\": \"on\",\n        \"conditions/remove-zero\": \"on\",\n        \"conditions/reverse\": \"on\",\n        \n        \"conditions/simplify\": \"on\",\n        \"conditions/wrap-with-block\": \"on\"\n    }\n}\n```\n\n## add-return\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b1c12a29951659bb54b283310027d6ef/b32270ca22a36728c67edf0dc0f0519876b78f16).\n\n### ❌ Example of incorrect code\n\n```js\nif (a)\n    false;\n```\n\n### ✅ Example of correct code\n\n```js\nif (a)\n    return false;\n```\n\n## apply-comparison-order\n\n> The result of evaluating an equality operator is always of type boolean based on whether the comparison is true.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators)\n\nCheckout it 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/c61c94d2e1990f59b160aaf462f9a903/0855844b114079ec46098be6f3602dfdaa74290c).\n\n### ❌ Example of incorrect code\n\n```js\n3 === a;\n3 < b;\n```\n\n### ✅ Example of correct code\n\n```js\na === 3;\nb > 3;\n```\n\n### Comparison\n\n| Linter        | Rule | Fix |\n|---------------|------|-----|\n| 🐊 **Putout** | [`conditions/apply-comparison-order`](https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions/#apply-comparison-order) | ✅   |\n| ⏣ **ESLint**  | [`yoda`](https://eslint.org/docs/rules/yoda) | ½   |\n\n## apply-consistent-blocks\n\n> A **block statement** is used to group zero or more statements. The block is delimited by a pair of braces (\"curly braces\") and contains a list of zero or more statements and declarations.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block)\n\nCheck out in 🐊**Putout Editor**:\n\n- [Replacer](https://putout.cloudcmd.io/#/gist/9035db21bae7b6c76d1dc875d4c74828/07edbfd755060ae263949caf08b31aa43609375a);\n- [Traverser](https://putout.cloudcmd.io/#/gist/77f84f100d82707925c73c1784f589f2/25923f46973b99f72378104778499ff75b550d2c);\n\n### ❌ Example of incorrect code\n\n```js\nif (a > 3) {\n    m();\n}\n\nif (a > 3)\n    b = 5;\nelse {\n    b = 6;\n}\n\nif (a > 3)\n    b = 5;\nelse {\n    b = 6;\n    fn();\n}\n```\n\n### ✅ Example of correct code\n\n```js\nif (a > 3)\n    m();\n\nif (a > 3)\n    b = 5;\nelse\n    b = 6;\n\nif (a > 3) {\n    b = 5;\n} else {\n    b = 6;\n    fn();\n}\n```\n\n## apply-early-return\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/dd2ba101a3039784bd83a12157fd7fc4/5cdf5340f761c6df3d82964b27aae7d7befcdc56).\n\n### ❌ Example of incorrect code\n\n```js\nfunction notBlockNoNext() {\n    if (a)\n        x();\n    else\n        b();\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfunction notBlockNoNext() {\n    if (a) {\n        x();\n        return;\n    }\n    \n    b();\n}\n```\n\n## apply-equal\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7ec940ad79df7e12a1d9111136b4a168/2ccea607e3232721eb950c18195168f8d9b4ef6a).\n\n### ❌ Example of incorrect code\n\n```js\nreturn a.b = c;\n```\n\n### ✅ Example of correct code\n\n```js\nreturn a.b === c;\n```\n\n## apply-if\n\n### ❌ Example of incorrect code\n\n```js\nif (2 > 3)\n    ;\n\nalert();\n```\n\n### ✅ Example of correct code\n\n```js\nif (2 > 3)\n    alert();\n```\n\n## convert-arrow-to-condition\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4d489393cd08dc771c6324eb0bb2e42f/9e85c4b7b7f2d0f82c660c6db618b31270d3a85e).\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-comparison-to-boolean\n\n> Strict equality compares two values for equality. Neither value is implicitly converted to some other value before being compared. If the values have different types, the values are considered unequal.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness)\n\n## ❌ Example of incorrect code\n\n```js\nconst t = 2 < 3;\n```\n\n## ✅ Example of correct code\n\n```js\nconst t = false;\n```\n\n## convert-equal-to-strict-equal\n\n> The **strict equality** operator (`===`) checks whether its two operands are equal, returning a `Boolean` result. Unlike the **equality** operator (`==`), the **strict equality** operator always considers operands of different types to be different.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality)\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-switch-to-if\n\n> The `switch` statement evaluates an `expression`, matching the expression's value against a series of case clauses, and executes `statements` after the first case clause with a matching value, until a break statement is encountered.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger)\n\nCheckout in 🐊[**Putout Editor**](https://putout.vercel.app/#/gist/725a934d13569bd48b781d0bfaaa3232/b53c994c9f1fc6c12d0e44811b6ff39a818be3dd).\n\n## ❌ Example of incorrect code\n\n```js\nfunction report(path) {\n    switch(path.node.type) {\n    case 'ImportFinding':\n        return 'remove unused import: ' + path.node.path;\n    }\n    \n    return 'remove unused variable';\n}\n```\n\n## ✅ Example of correct code\n\n```js\nfunction report(path) {\n    if (path.node.type === 'ImportFinding')\n        return 'remove unused import: ' + path.node.path;\n    \n    return 'remove unused variable';\n}\n```\n\n## evaluate\n\n> The **if** statement executes a statement if a specified condition is **truthy**. If the condition is **falsy**, another statement can be executed.\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\nconst a = [];\nconst c = a;\n\nif (a)\n    console.log(a);\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = [];\nconst c = a;\n\nconsole.log(a);\n```\n\n## merge-if-statements\n\n> Multiple `if...else` statements can be nested to create an else if clause\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    if (b < c)\n        console.log('hello');\n```\n\n### ✅ Example of correct code\n\n```js\nif (a > b && b < c)\n    console.log('hello');\n```\n\n## merge-if-with-else\n\n> The `if` statement executes a statement `if` a specified condition is truthy.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)\n\nCheckout in [**Putout Editor**](https://putout.cloudcmd.io/#/gist/9d7df8b29406ce24a798f92bce84f40d/10b33f57ba87271283ecb4d7edaae8e8d0300169).\n\n### ❌ Example of incorrect code\n\n```js\nif (!matchFn)\n    fix(from, to, path);\nelse if (matchFn(options))\n    fix(from, to, path);\n```\n\n### ✅ Example of correct code\n\n```js\nif (!matchFn || matchFn(options))\n    fix(from, to, path);\n```\n\n## remove-boolean\n\n### ❌ Example of incorrect code\n\n```js\nif (a === true)\n    alert();\n```\n\n### ✅ Example of correct code\n\n```js\nif (a)\n    alert();\n```\n\n## remove-constant\n\n### ❌ Example of incorrect code\n\n```js\nfunction hi(a) {\n    if (2 < 3) {\n        console.log('hello');\n        console.log('world');\n    }\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfunction hi(b) {\n    console.log('hello');\n    console.log('world');\n}\n```\n\n## remove-same-values-condition\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e537d4ec636d4a9b849063a8326b70ae/661041b3fbb1e3678bf7f828e4c8bf6ca723f89d).\n\n### ❌ Example of incorrect code\n\n```js\nfor (const [i, el] of entries(elements)) {\n    if (el !== path)\n        continue;\n    \n    if (!Number(i) && n) {\n        path.parentPath.node.elements[i] = null;\n        break;\n    }\n    \n    if (el === path) {\n        remove(path);\n        break;\n    }\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfor (const [i, el] of entries(elements)) {\n    if (el !== path)\n        continue;\n    \n    if (!Number(i) && n) {\n        path.parentPath.node.elements[i] = null;\n        break;\n    }\n    \n    remove(path);\n}\n```\n\n## remove-useless-else\n\n> You can skip the `else` block if your `if` block always executes a `return` statement, it makes code a lot easier to read.\n>\n> (c) [no else return](https://www.samanthaming.com/tidbits/23-no-else-return/)\n\nRemove useless `else` before:\n\n- `return`;\n- `continue`;\n- `break`;\n\n### ❌ Example of incorrect code\n\n```js\nif (x)\n    return;\nelse\n    console.log();\n```\n\n### ✅ Example of correct code\n\n```js\nif (x)\n    return;\n\nconsole.log();\n```\n\n### Comparison\n\n| Linter        | Rule | Fix |\n|---------------|------|-----|\n| 🐊 **Putout** | [`conditions/remove-useless-else`](https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions#remove-useless-else) | ✅   |\n| ⏣ **ESLint**  | [`no-else-return`](https://eslint.org/docs/rules/no-else-return) | ✅   |\n\n## remove-useless-loop-condition\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/eefe12da089fda5554d394746ee25a6f/7a3c467cb95a5909f6d7f7d8228b5003da674113).\n\n### ❌ Example of incorrect code\n\n```js\nwhile (currentDirPath = getParentDirectory(currentDirPath)) {\n    if (!currentDirPath)\n        break;\n}\n```\n\n### ✅ Example of correct code\n\n```js\nwhile (currentDirPath = getParentDirectory(currentDirPath)) {}\n```\n\n## remove-zero\n\n### ❌ Example of incorrect code\n\n```js\nif (b === 0) {}\n\nif (b !== 0) {}\n```\n\n### ✅ Example of correct code\n\n```js\nif (!b) {}\n\nif (b) {}\n```\n\n## reverse\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fabfc16a5a5d1002c721fc2dfc31474b/8d1de98533ef439e56e8784f54a34c3928a074fa).\n\n### ❌ Example of incorrect code\n\n```js\nconst check = (references) => !(references > 3);\n\nreturn !(nextNode.type !== 'text' || nextNode.value !== ' ');\n```\n\n### ✅ Example of correct code\n\n```js\nconst check = (references) => references <= 3;\n\nreturn nextNode.type === 'text' && nextNode.value === ' ';\n```\n\n## simplify\n\n### ❌ Example of incorrect code\n\n```js\nif (zone?.tooltipCallback)\n    zone.tooltipCallback(e);\n\nif (a)\n    alert('hello');\nelse\n    alert('hello');\n```\n\n### ✅ Example of correct code\n\n```js\nzone?.tooltipCallback(e);\n\nalert('hello');\n```\n\n## wrap-with-block\n\n> If you use a declaration instead of a statement, it would be a `SyntaxError`. For example, a `let` declaration is not a statement, so you can't use it in its bare form as the body of an if statement.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#difference_between_statements_and_declarations)\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/256b1b6a904b0352c3a2716d365185ca/fac1c6365c01539392c674e2ca7468ee062e73e8).\n\n### ❌ Example of incorrect code\n\n```\nif (a)\n   const b = 5;\n```\n\n### ✅ Example of correct code\n\n```js\nif (a) {\n    const b = 5;\n}\n```\n\n## License\n\nMIT\n","publish_time":1788457843703,"_cnpm_publish_time":1788457843703,"dist-tags":{"latest":"9.2.4"}}