{"name":"@putout/plugin-promises","version":"16.0.0","type":"commonjs","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"🐊Putout plugin improves Promise-related code","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-promises#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":{"fullstore":"^3.0.0"},"keywords":["putout","putout-plugin","plugin","esm","commonjs"],"devDependencies":{"@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","nodemon":"^3.0.1"},"peerDependencies":{"putout":">=37"},"license":"MIT","engines":{"node":">=18"},"publishConfig":{"access":"public"},"_id":"@putout/plugin-promises@16.0.0","gitHead":"829d0ab6725768dbfb83b72e4a0e2fc52f76ae8b","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-lGkmSs1WJHRLXZ+pjN/KOdwQh2BSNbvdPa0LJYyXauGApamy36Q9FtyN9PBqKCQI/ZcI3n7iGh54/sMWBn9mog==","shasum":"8479d14a2cc80726c12991ef46b3f4e79429e16a","tarball":"http://registry-npm.ywwl.com/@putout/plugin-promises/download/@putout/plugin-promises-16.0.0.tgz","fileCount":15,"unpackedSize":23542,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCwfsnvffMl97iyFgIvC0K2QQ3q0YWSk98D5xgAg6SPKgIhAMed4EckqD8przj+IAUL3Cqv9Vvlhi4R3YqqWRRxInBG"}],"size":6471,"noattachment":false,"key":"/@putout/plugin-promises/-/@putout/plugin-promises-16.0.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/plugin-promises_16.0.0_1734384057124_0.8772646341908759"},"_hasShrinkwrap":false,"readme":"# @putout/plugin-promises [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-promises.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-promises \"npm\"\n\n> A `Promise` is in one of these states:\n>\n> - ✅ `pending`: initial state, neither fulfilled nor rejected;\n> - ✅ `fulfilled`: meaning that the operation was completed successfully;\n> - ✅ `rejected`: meaning that the operation failed;\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin improves `Promise`-related code.\n\n## Install\n\n```\nnpm i @putout/plugin-promises -D\n```\n\n## Rules\n\n- ✅ [add-missing-async](#add-missing-async);\n- ✅ [add-missing-await](#add-missing-await);\n- ✅ [apply-await-import](#apply-await-import);\n- ✅ [apply-top-level-await](#apply-top-level-await);\n- ✅ [apply-with-resolvers](#apply-with-resolvers);\n- ✅ [convert-new-promise-to-async](#convert-new-promise-to-async);\n- ✅ [convert-reject-to-throw](#convert-reject-to-throw);\n- ✅ [remove-useless-async](#remove-useless-async);\n- ✅ [remove-useless-await](#remove-useless-await);\n- ✅ [remove-useless-resolve](#remove-useless-resolve);\n- ✅ [remove-useless-variables](#remove-useless-variables);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"promises/add-missing-await\": \"on\",\n        \"promises/add-missing-async\": \"on\",\n        \"promises/apply-await-import\": \"on\",\n        \"promises/apply-top-level-await\": \"on\",\n        \"promises/apply-with-resolvers\": \"off\",\n        \"promises/remove-useless-resolve\": \"on\",\n        \"promises/remove-useless-async\": \"on\",\n        \"promises/remove-useless-await\": \"on\",\n        \"promises/remove-useless-variables\": \"on\",\n        \"promises/convert-reject-to-throw\": \"on\",\n        \"promises/convert-new-promise-to-async\": \"on\"\n    }\n}\n```\n\n☝️ If you want to override any of it, update `.putout.json` in the directory near your files.\n\n[🦉 Configuration](https://github.com/coderaiser/putout#-configuration) section of 🐊**Putout** documentation tell you more about all configuration options supported.\n\n## apply-await-import\n\nadd forgotten **await** to [**dynamic `import()`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports).\n\n### ❌ Example of incorrect code\n\n```js\nconst {readFile} = import('node:fs/promises');\n```\n\n### ✅ Example of correct code\n\n```js\nconst {readFile} = await import('node:fs/promises');\n```\n\n## apply-with-resolvers\n\n> The `Promise.withResolvers()` static method returns an object containing a new `Promise` object and two functions to `resolve` or `reject` it, corresponding to the two parameters passed to the executor of the `Promise()` constructor.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)\n\nCheckout in\n\n- 🐊📱[**Mobile Putout Editor**](https://putout.vercel.app/#/gist/e93dc4b71d05661e5d96141f31880945/de8940e2b8ecaebfcfe782cf25b221cb48830a03);\n- 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e93dc4b71d05661e5d96141f31880945/de8940e2b8ecaebfcfe782cf25b221cb48830a03);\n\n### ❌ Example of incorrect code\n\n```js\nconst promise = new Promise((res, rej) => {});\n```\n\n### ✅ Example of correct code\n\n```js\nconst {\n    promise,\n    resolve,\n    reject,\n} = Promise.withResolvers();\n```\n\n## remove-useless-resolve\n\n### ❌ Example of incorrect code\n\n```js\nasync function hello() {\n    return Promise.resolve('hello');\n}\n```\n\n### ✅ Example of correct code\n\n```js\nasync function hello() {\n    return 'hello';\n}\n```\n\n## remove-useless-async\n\n### ❌ Example of incorrect code\n\n```js\nasync function hello() {\n    return 'hello';\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfunction hello() {\n    return 'hello';\n}\n```\n\n## remove-useless-await\n\n> If a handler function returns another pending promise object, the resolution of the **promise** returned by `then` will be subsequent to the resolution of the promise returned by the handler. Also, the resolved value of the **promise** returned by `then` will be the same as the resolved value of the **promise** returned by the handler.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then#return_value)\n\n### ❌ Example of incorrect code\n\n```js\nawait await Promise.resolve();\nconst hello = await 'world';\n```\n\n### ✅ Example of correct code\n\n```js\nawait Promise.resolve();\nconst hello = 'world';\n```\n\n## convert-reject-to-throw\n\n### ❌ Example of incorrect code\n\n```js\nasync function hello() {\n    return Promise.reject(Error('error'));\n}\n```\n\n### ✅ Example of correct code\n\n```js\nasync function hello() {\n    throw Error('error');\n}\n```\n\n## add-missing-await\n\n> Using `return await` inside an `async function` keeps the current `function` in the `call stack` until the `Promise` that is being awaited has resolved, at the cost of an extra microtask before resolving the outer `Promise`. `return await` can also be used in a `try/catch statement` to catch errors from another function that returns a Promise.\n\n> You can avoid the extra microtask by not awaiting the return value, with the trade off of the function no longer being a part of the stack trace if an error is thrown asynchronously from the `Promise` being returned. This can make debugging more difficult.\n>\n> (c) [ESLint](eslint.org/docs/latest/rules/no-return-await)\n\n### ❌ Example of incorrect code\n\n```js\nrunCli();\n\nasync function runCli() {}\n```\n\n### ✅ Example of correct code\n\n```js\nawait runCli();\n\nasync function runCli() {}\n```\n\n## add-missing-async\n\n> The `async` function declaration creates a binding of a new async function to a given name. The `await` keyword is permitted within the function body, enabling asynchronous, promise-based behavior to be written in a cleaner style and avoiding the need to explicitly configure promise chains.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)\n\n### ❌ Example of incorrect code\n\n```js\nfunction hello() {\n    await world();\n}\n```\n\n### ✅ Example of correct code\n\n```js\nasync function hello() {\n    await world();\n}\n```\n\n## convert-new-promise-to-async\n\n### ❌ Example of incorrect code\n\n```js\nfunction get() {\n    return new Promise((resolve, reject) => {\n        reject(Error('Cannot get'));\n    });\n}\n```\n\n### ✅ Example of correct code\n\n```js\nasync function get() {\n    throw Error('Cannot get');\n}\n```\n\n## apply-top-level-await\n\nApplies [top-level-await](https://v8.dev/features/top-level-await).\n\n### ❌ Example of incorrect code\n\n```js\nimport {readFile} from 'node:fs/promises';\n\n(async () => {\n    await readFile('./README.md', 'utf8');\n})();\n```\n\n### ✅ Example of correct code\n\n```js\nimport {readFile} from 'node:fs/promises';\n\nawait readFile('./README.md', 'utf8');\n```\n\n## remove-useless-variables\n\n### ❌ Example of incorrect code\n\n```js\nasync () => {\n    const result = transformer.transform(realTransformer, transformCode, code, parser);\n    \n    const result2 = await Promise.resolve(result);\n    \n    return result2;\n};\n```\n\n### ✅ Example of correct code\n\n```js\nasync () => {\n    const result = transformer.transform(realTransformer, transformCode, code, parser);\n    \n    return result;\n};\n```\n\n## License\n\nMIT\n","publish_time":1734384057294,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1734384057294,"dist-tags":{"latest":"20.2.0"}}