@putout/plugin-nodejs 10.3.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
@@ -36,7 +36,9 @@ npm i putout @putout/plugin-nodejs -D
36
36
  "nodejs/declare": "on",
37
37
  "nodejs/declare-after-require": "on",
38
38
  "nodejs/remove-process-exit": "on",
39
- "nodejs/strict-mode": "on"
39
+ "nodejs/add-missing-strict-mode": "on",
40
+ "nodejs/remove-useless-strict-mode": "on",
41
+ "nodejs/remove-useless-promisify": "on"
40
42
  }
41
43
  }
42
44
  ```
@@ -61,6 +63,13 @@ import fs from 'fs';
61
63
  import fs from 'node:fs';
62
64
  ```
63
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
+
64
73
  ## convert-buffer-to-buffer-alloc
65
74
 
66
75
  > The `Buffer()` function and `new Buffer()` constructor are **deprecated** due to API usability issues that can lead to accidental security issues.
@@ -398,7 +407,7 @@ Rename `*.mjs` files when `module === "module"`:
398
407
 
399
408
  Check out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/94fb3298b210e703b01db9a6826942bc/dfe2462451c6b3d4d47da7fd8d39dc8e53bb16eb).
400
409
 
401
- ## strict-mode
410
+ ## add-missing-strict-mode
402
411
 
403
412
  > **Strict mode** makes several changes to normal **JavaScript** semantics:
404
413
  >
@@ -408,38 +417,60 @@ Check out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/94fb3298b210e
408
417
  >
409
418
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)
410
419
 
411
- Add **strict mode** to **CommonJS**, and remove from **ESM**, where it enabled by default.
420
+ Add **strict mode** to **CommonJS**:
412
421
 
413
422
  ### ❌ Example of incorrect code
414
423
 
415
- ESM:
424
+ ```js
425
+ const a = require('b');
426
+ ```
427
+
428
+ ### βœ… Example of correct code
416
429
 
417
430
  ```js
418
431
  'strict mode';
419
432
 
420
- import a from 'b';
433
+ const a = require('b');
421
434
  ```
422
435
 
423
- CommonJS:
436
+ ### βœ… Example of correct code
437
+
438
+ ## remove-useless-strict-mode
439
+
440
+ Remove `'use strict'` from **ESM**.
441
+
442
+ ### ❌ Example of incorrect code
424
443
 
425
444
  ```js
426
- const a = require('b');
445
+ 'strict mode';
446
+
447
+ import a from 'b';
427
448
  ```
428
449
 
429
450
  ### βœ… Example of correct code
430
451
 
431
- ESM:
432
-
433
452
  ```js
434
453
  import a from 'b';
435
454
  ```
436
455
 
437
- CommonJS:
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
438
465
 
439
466
  ```js
440
- 'strict mode';
467
+ export const readSize = promisify(async (dir, options, callback) => {});
468
+ ```
441
469
 
442
- const a = require('b');
470
+ ### βœ… Example of correct code
471
+
472
+ ```js
473
+ export const readSize = async (dir, options, callback) => {};
443
474
  ```
444
475
 
445
476
  ## License
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,
@@ -50,6 +51,7 @@ module.exports.rules = {
50
51
  'rename-file-cjs-to-js': ['off', renameFileCjsToJs],
51
52
  'rename-file-mjs-to-js': ['off', renameFileMjsToJs],
52
53
 
53
- 'add-strict-mode': strictMode.rules['add-missing'],
54
- 'remove-strict-mode': strictMode.rules['remove-useless'],
54
+ 'add-missing-strict-mode': strictMode.rules['add-missing'],
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": "10.3.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",
@@ -42,10 +42,10 @@
42
42
  "@putout/plugin-declare": "*",
43
43
  "@putout/plugin-putout": "*",
44
44
  "@putout/plugin-typescript": "*",
45
- "@putout/test": "^8.0.0",
46
- "c8": "^8.0.0",
47
- "eslint": "^8.0.1",
48
- "eslint-plugin-n": "^16.0.0",
45
+ "@putout/test": "^9.0.0",
46
+ "c8": "^9.0.0",
47
+ "eslint": "^9.0.0-alpha.0",
48
+ "eslint-plugin-n": "^17.0.0-0",
49
49
  "eslint-plugin-putout": "^22.0.0",
50
50
  "lerna": "^6.0.1",
51
51
  "madrun": "^10.0.0",
@@ -53,7 +53,7 @@
53
53
  "nodemon": "^3.0.1"
54
54
  },
55
55
  "peerDependencies": {
56
- "putout": ">=34"
56
+ "putout": ">=35"
57
57
  },
58
58
  "license": "MIT",
59
59
  "engines": {