@putout/plugin-nodejs 4.7.1 β 4.8.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 +33 -0
- package/lib/convert-buffer-to-buffer-alloc/index.js +33 -0
- package/lib/index.js +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ npm i putout @putout/plugin-nodejs -D
|
|
|
20
20
|
```json
|
|
21
21
|
{
|
|
22
22
|
"rules": {
|
|
23
|
+
"nodejs/convert-buffer-to-buffer-alloc": "on",
|
|
23
24
|
"nodejs/convert-fs-promises": "on",
|
|
24
25
|
"nodejs/convert-promisify-to-fs-promises": "on",
|
|
25
26
|
"nodejs/convert-dirname-to-url": "on",
|
|
@@ -33,6 +34,38 @@ npm i putout @putout/plugin-nodejs -D
|
|
|
33
34
|
|
|
34
35
|
## Rules
|
|
35
36
|
|
|
37
|
+
### convert-buffer-to-buffer-alloc
|
|
38
|
+
|
|
39
|
+
According to [DEP0005](https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor). Check out in π[Putout Editor](https://putout.cloudcmd.io/#/gist/5379bcdfa3d76f7b7121c9671ae48375/2fc2c7f96fc8284788c00914a9b29bfeea8b13d4).
|
|
40
|
+
|
|
41
|
+
#### β Example of incorrect code
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const n = 100;
|
|
45
|
+
const buf = [];
|
|
46
|
+
|
|
47
|
+
new Buffer(123);
|
|
48
|
+
new Buffer(n);
|
|
49
|
+
new Buffer('hello');
|
|
50
|
+
|
|
51
|
+
new Buffer([]);
|
|
52
|
+
new Buffer(buf);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### β
Example of correct code
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
const n = 100;
|
|
59
|
+
const buf = [];
|
|
60
|
+
|
|
61
|
+
Buffer.alloc(123);
|
|
62
|
+
Buffer.alloc(n);
|
|
63
|
+
Buffer.from('hello');
|
|
64
|
+
|
|
65
|
+
Buffer.from([]);
|
|
66
|
+
Buffer.from(buf);
|
|
67
|
+
```
|
|
68
|
+
|
|
36
69
|
### convert-fs-promises
|
|
37
70
|
|
|
38
71
|
Convert [fs.promises](https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_promises_api) into form that will be simpler to use and convert to and from **ESM**.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator} = require('putout');
|
|
4
|
+
|
|
5
|
+
const isNumber = (a) => typeof a === 'number';
|
|
6
|
+
|
|
7
|
+
const {compute} = operator;
|
|
8
|
+
|
|
9
|
+
module.exports.report = () => `Use 'Buffer.alloc()' or 'Buffer.from()' instead of 'Buffer()' and 'new Buffer()'`;
|
|
10
|
+
|
|
11
|
+
module.exports.match = () => ({
|
|
12
|
+
'new Buffer(__a)': (vars, path) => {
|
|
13
|
+
const __aPath = path.get('arguments.0');
|
|
14
|
+
const [is] = compute(__aPath);
|
|
15
|
+
|
|
16
|
+
return is;
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
module.exports.replace = () => ({
|
|
21
|
+
'new Buffer(__a)': transform,
|
|
22
|
+
'Buffer(__a)': transform,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function transform(vars, path) {
|
|
26
|
+
const [, value] = compute(path.get('arguments.0'));
|
|
27
|
+
|
|
28
|
+
if (isNumber(value))
|
|
29
|
+
return 'Buffer.alloc(__a)';
|
|
30
|
+
|
|
31
|
+
return 'Buffer.from(__a)';
|
|
32
|
+
}
|
|
33
|
+
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.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",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@putout/test": "^5.0.0",
|
|
38
38
|
"c8": "^7.5.0",
|
|
39
39
|
"eslint": "^8.0.1",
|
|
40
|
-
"eslint-plugin-
|
|
41
|
-
"eslint-plugin-putout": "^
|
|
40
|
+
"eslint-plugin-n": "^15.2.4",
|
|
41
|
+
"eslint-plugin-putout": "^16.0.0",
|
|
42
42
|
"lerna": "^5.0.0",
|
|
43
43
|
"madrun": "^9.0.0",
|
|
44
44
|
"montag": "^1.2.1",
|