{"name":"@putout/plugin-conditions","version":"6.4.0","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@6.4.0","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"e38fc8932542bc72067ba36d57974007c0d34dcd","tarball":"http://registry-npm.ywwl.com/@putout/plugin-conditions/download/@putout/plugin-conditions-6.4.0.tgz","fileCount":21,"integrity":"sha512-0GQ/XREF1fjLyNMl12CwjbmQTMumJEFbNzHSuiKgFCd+6zwL58HqLAPznoIieatAMZMcFYSbbyqUVbiSVKRpDg==","signatures":[{"sig":"MEUCIClfOa13cJmFYHEfQeFVq/Rf1HdpDeT38Vm1VCy9LQWrAiEAxIeM1txijH9YhOkucN51aPA6eI613JvDqs83S6T5v+0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":28426,"size":7815,"noattachment":false,"key":"/@putout/plugin-conditions/-/@putout/plugin-conditions-6.4.0.tgz"},"main":"lib/index.js","type":"commonjs","engines":{"node":">=18"},"gitHead":"5424d44b6620e2ee0bd5beacd07e1f3adbdf1661","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":"10.9.0","description":"🐊Putout plugin adds support of conditions transformations","directories":{},"_nodeVersion":"20.18.1","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","lerna":"^6.0.1","eslint":"^9.0.0","madrun":"^10.0.0","montag":"^1.2.1","nodemon":"^3.0.1","@putout/test":"^11.0.0","eslint-plugin-n":"^17.0.0","eslint-plugin-putout":"^23.0.0","@putout/plugin-for-of":"*"},"peerDependencies":{"putout":">=37"},"_npmOperationalInternal":{"tmp":"tmp/plugin-conditions_6.4.0_1735905420457_0.7876285477682277","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-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- ✅ [merge-if-with-else](#merge-if-with-else);\n- ✅ [reverse](#reverse);\n- ✅ [remove-boolean](#remove-boolean);\n- ✅ [remove-constant](#remove-constant);\n- ✅ [remove-same-values-condition](hremove-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- ✅ [simplify](#simplify);\n- ✅ [wrap-with-block](#wrap-with-block);\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/reverse\": \"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-useless-loop-condition\": \"on\",\n        \"conditions/remove-same-values-condition\": \"on\",\n        \"conditions/merge-if-statements\": \"on\",\n        \"conditions/merge-if-with-else\": \"on\",\n        \"conditions/simplify\": \"on\",\n        \"conditions/wrap-with-block\": \"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## 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## 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> 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-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\nLinter | 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-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## 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```js\nconst a = 5;\n\nif (a) {}\n```\n\n### ✅ Example of correct code\n\n```js\nif (a) {\n    const a = 5;\n}\n```\n\n## License\n\nMIT\n","publish_time":1735905420631,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1735905420631,"dist-tags":{"latest":"9.2.4"}}