@putout/plugin-nodejs 11.0.0 β†’ 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,8 @@ npm i putout @putout/plugin-nodejs -D
37
37
  "nodejs/declare-after-require": "on",
38
38
  "nodejs/remove-process-exit": "on",
39
39
  "nodejs/add-missing-strict-mode": "on",
40
- "nodejs/remove-useless-strict-mode": "on"
40
+ "nodejs/remove-useless-strict-mode": "on",
41
+ "nodejs/remove-useless-promisify": "on"
41
42
  }
42
43
  }
43
44
  ```
@@ -62,6 +63,13 @@ import fs from 'fs';
62
63
  import fs from 'node:fs';
63
64
  ```
64
65
 
66
+ ### Comparison
67
+
68
+ Linter | Rule | Fix
69
+ --------|-------|------------|
70
+ 🐊 **Putout** | [`apply-node-prefix`](https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs/apply-node-prefix#readme) | βœ…
71
+ ⏣ **ESLint** | [`prefer-node-protocol`](https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/prefer-node-protocol.md#readme) | βœ…
72
+
65
73
  ## convert-buffer-to-buffer-alloc
66
74
 
67
75
  > The `Buffer()` function and `new Buffer()` constructor are **deprecated** due to API usability issues that can lead to accidental security issues.
@@ -445,6 +453,26 @@ import a from 'b';
445
453
  import a from 'b';
446
454
  ```
447
455
 
456
+ ## remove-useless-promisify
457
+
458
+ > Takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises.
459
+ >
460
+ > (c) [nodejs.org](https://nodejs.org/dist/latest-v21.x/docs/api/util.html#utilpromisifyoriginal)
461
+
462
+ Remove useless [`promisify()`](https://nodejs.org/dist/latest-v21.x/docs/api/util.html#utilpromisifyoriginal). Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/31000391865a36dfec2f8db5c2e98601/ce8867f83a84ecbe073637b9ceae58a443817187).
463
+
464
+ ### ❌ Example of incorrect code
465
+
466
+ ```js
467
+ export const readSize = promisify(async (dir, options, callback) => {});
468
+ ```
469
+
470
+ ### βœ… Example of correct code
471
+
472
+ ```js
473
+ export const readSize = async (dir, options, callback) => {};
474
+ ```
475
+
448
476
  ## License
449
477
 
450
478
  MIT
package/lib/index.js CHANGED
@@ -25,6 +25,7 @@ const renameFileCjsToJs = require('./rename-file-cjs-to-js');
25
25
  const renameFileMjsToJs = require('./rename-file-mjs-to-js');
26
26
 
27
27
  const strictMode = require('./strict-mode');
28
+ const removeUselessPromisify = require('./remove-useless-promisify');
28
29
 
29
30
  module.exports.rules = {
30
31
  'convert-buffer-to-buffer-alloc': convertBufferToBufferAlloc,
@@ -52,4 +53,5 @@ module.exports.rules = {
52
53
 
53
54
  'add-missing-strict-mode': strictMode.rules['add-missing'],
54
55
  'remove-useless-strict-mode': strictMode.rules['remove-useless'],
56
+ 'remove-useless-promisify': removeUselessPromisify,
55
57
  };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `Calling 'promisify' on a function that returns a Promise is likely a mistake`;
4
+
5
+ module.exports.replace = () => ({
6
+ 'promisify(async (__args) => __body)': 'async (__args) => __body',
7
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code to new API of Node.js",