{"name":"@putout/plugin-conditions","version":"6.0.0","type":"commonjs","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"🐊Putout plugin adds support of conditions transformations","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions#readme","main":"lib/index.js","release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git+https://github.com/coderaiser/putout.git"},"scripts":{"wisdom":"madrun wisdom","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-plugin","putout","plugin","conditions"],"devDependencies":{"@putout/plugin-for-of":"*","@putout/test":"^11.0.0","c8":"^10.0.0","eslint":"^9.0.0","eslint-plugin-n":"^17.0.0","eslint-plugin-putout":"^23.0.0","lerna":"^6.0.1","madrun":"^10.0.0","montag":"^1.2.1","nodemon":"^3.0.1"},"peerDependencies":{"putout":">=37"},"license":"MIT","engines":{"node":">=18"},"publishConfig":{"access":"public"},"_id":"@putout/plugin-conditions@6.0.0","gitHead":"51723d760049bf83bcb9f343328a347429ddfad1","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-yxoYFgeewabE1tLmZ8mMoUFMxS4agu0iMz9qRDVbUWoaXDW75CeB1cPpo03JD0tyUk4dCe2rNafpZ4A0+JeoqQ==","shasum":"499a9dde86f36372697b0407cfd66eae79b49ecf","tarball":"http://registry-npm.ywwl.com/@putout/plugin-conditions/download/@putout/plugin-conditions-6.0.0.tgz","fileCount":19,"unpackedSize":26232,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCGoAXxACkx8zf+5jgOFXe1QTSFUfAydtFoI/aeEi0WzQIhALHu0B4nIb5El/azzXLBINGK3/YC4JlCk83o9iyF6MmI"}],"size":7238,"noattachment":false,"key":"/@putout/plugin-conditions/-/@putout/plugin-conditions-6.0.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/plugin-conditions_6.0.0_1735130214352_0.878869266966634"},"_hasShrinkwrap":false,"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-if](#apply-if);\n- ✅ [convert-comparison-to-boolean](#convert-comparison-to-boolean);\n- ✅ [convert-equal-to-strict-equal](#convert-equal-to-strict-equal);\n- ✅ [convert-arrow-to-condition](#convert-arrow-to-condition);\n- ✅ [evaluate](#evaluate);\n- ✅ [merge-if-statements](#merge-if-statements);\n- ✅ [remove-boolean](#remove-boolean);\n- ✅ [remove-constant](#remove-constant);\n- ✅ [remove-same-values-condition](hremove-same-values-condition);\n- ✅ [remove-useless-else](#remove-ureless-else);\n- ✅ [remove-zero](#remove-zero);\n- ✅ [simplify](#simplify);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"conditions/apply-consistent-blocks\": \"on\",\n        \"conditions/apply-comparison-order\": \"on\",\n        \"conditions/apply-if\": \"on\",\n        \"conditions/add-return\": \"on\",\n        \"conditions/convert-comparison-to-boolean\": \"on\",\n        \"conditions/convert-equal-to-strict-equal\": \"on\",\n        \"conditions/convert-arrow-to-condition\": \"on\",\n        \"conditions/evaluate\": \"on\",\n        \"conditions/remove-boolean\": \"on\",\n        \"conditions/remove-constant\": \"on\",\n        \"conditions/remove-zero\": \"on\",\n        \"conditions/remove-useless-else\": \"on\",\n        \"conditions/remove-same-values-condition\": \"on\",\n        \"conditions/merge-if-statements\": \"on\"\n    }\n}\n```\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-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\nLinter | 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-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## 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## 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## 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## 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-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## 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## merge-if-statements\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\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## 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## 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### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`conditions/remove-useless-else`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-debugger#readme) | ✅\n⏣ **ESLint** | [`no-else-return`](https://eslint.org/docs/rules/no-else-return) | ✅\n\n## License\n\nMIT\n","publish_time":1735130214550,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1735130214550,"dist-tags":{"latest":"9.2.4"}}