@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 +43 -12
- package/lib/index.js +4 -2
- package/lib/remove-useless-promisify/index.js +7 -0
- package/package.json +6 -6
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
|
|
420
|
+
Add **strict mode** to **CommonJS**:
|
|
412
421
|
|
|
413
422
|
### β Example of incorrect code
|
|
414
423
|
|
|
415
|
-
|
|
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
|
-
|
|
433
|
+
const a = require('b');
|
|
421
434
|
```
|
|
422
435
|
|
|
423
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
467
|
+
export const readSize = promisify(async (dir, options, callback) => {});
|
|
468
|
+
```
|
|
441
469
|
|
|
442
|
-
|
|
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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "
|
|
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": "^
|
|
46
|
-
"c8": "^
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"eslint-plugin-n": "^
|
|
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": ">=
|
|
56
|
+
"putout": ">=35"
|
|
57
57
|
},
|
|
58
58
|
"license": "MIT",
|
|
59
59
|
"engines": {
|