@putout/plugin-nodejs 4.6.3 β 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
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
|
+
|
|
@@ -55,6 +55,9 @@ module.exports.traverse = ({push, listStore}) => ({
|
|
|
55
55
|
if (path.node.__putoutNodeDeclareAfterRequire)
|
|
56
56
|
continue;
|
|
57
57
|
|
|
58
|
+
if (!path.isVariableDeclaration())
|
|
59
|
+
continue;
|
|
60
|
+
|
|
58
61
|
if (path.node.declarations[0].id.name === 'require')
|
|
59
62
|
continue;
|
|
60
63
|
|
|
@@ -119,6 +122,9 @@ function getReferenceLine(path) {
|
|
|
119
122
|
|
|
120
123
|
const [firstReference] = referencePaths;
|
|
121
124
|
|
|
125
|
+
if (!firstReference.node.loc)
|
|
126
|
+
return -1;
|
|
127
|
+
|
|
122
128
|
return firstReference.node.loc.start.line;
|
|
123
129
|
}
|
|
124
130
|
|
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",
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"nodejs"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@putout/plugin-convert-commonjs-to-esm": "*",
|
|
34
35
|
"@putout/plugin-convert-esm-to-commonjs": "*",
|
|
35
36
|
"@putout/plugin-putout": "*",
|
|
36
37
|
"@putout/test": "^5.0.0",
|
|
37
38
|
"c8": "^7.5.0",
|
|
38
39
|
"eslint": "^8.0.1",
|
|
39
|
-
"eslint-plugin-
|
|
40
|
-
"eslint-plugin-putout": "^
|
|
40
|
+
"eslint-plugin-n": "^15.2.4",
|
|
41
|
+
"eslint-plugin-putout": "^16.0.0",
|
|
41
42
|
"lerna": "^5.0.0",
|
|
42
43
|
"madrun": "^9.0.0",
|
|
43
44
|
"montag": "^1.2.1",
|