@putout/plugin-nodejs 7.2.0 β†’ 8.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
@@ -5,7 +5,7 @@
5
5
 
6
6
  > **Node.js** is an open-source, cross-platform, **JavaScript** runtime environment.
7
7
  >
8
- > (c) [nodejs.org](https://nodejs.org/en/)
8
+ > (c) [Nodejs.org](https://nodejs.org/en/)
9
9
 
10
10
  🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to transform to new **Node.js** API and apply best practices.
11
11
 
@@ -25,6 +25,7 @@ npm i putout @putout/plugin-nodejs -D
25
25
  "nodejs/convert-fs-promises": "on",
26
26
  "nodejs/convert-promisify-to-fs-promises": "on",
27
27
  "nodejs/convert-dirname-to-url": "on",
28
+ "nodejs/convert-exportst-to-module-exports": "on",
28
29
  "nodejs/convert-url-to-dirname": "on",
29
30
  "nodejs/convert-top-level-return": "on",
30
31
  "nodejs/declare": "on",
@@ -171,6 +172,23 @@ In most cases `process.exit()` is called from `bin` directory, if not - disable
171
172
  -process.exit();
172
173
  ```
173
174
 
175
+ ### convert-exports-to-module-exports
176
+
177
+ Since `exports = 5` wan't make any export, just change value of variable.
178
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8b2af2c4ad005ed1c77cde41377caaad/dfdccc794037d7f67bde1e7d7244bf5f14abebce).
179
+
180
+ #### ❌ Example of incorrect code
181
+
182
+ ```js
183
+ exports.x = 5;
184
+ ```
185
+
186
+ #### βœ… Example of correct code
187
+
188
+ ```js
189
+ module.exports.x = 5;
190
+ ```
191
+
174
192
  ### convert-top-level-return
175
193
 
176
194
  #### ❌ Example of incorrect code
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const {operator} = require('putout');
4
+ const {compute} = operator;
4
5
 
5
6
  const isNumber = (a) => typeof a === 'number';
6
7
 
7
- const {compute} = operator;
8
-
9
8
  module.exports.report = () => `Use 'Buffer.alloc()' or 'Buffer.from()' instead of 'Buffer()' and 'new Buffer()'`;
10
9
 
11
10
  module.exports.match = () => ({
@@ -19,14 +18,18 @@ module.exports.match = () => ({
19
18
 
20
19
  module.exports.replace = () => ({
21
20
  'new Buffer(__a)': transform,
21
+ 'new Buffer(__a, __b)': transform,
22
22
  'Buffer(__a)': transform,
23
23
  });
24
24
 
25
- function transform(vars, path) {
25
+ function transform({__b}, path) {
26
26
  const [, value] = compute(path.get('arguments.0'));
27
27
 
28
28
  if (isNumber(value))
29
29
  return 'Buffer.alloc(__a)';
30
30
 
31
+ if (__b)
32
+ return 'Buffer.from(__a, __b)';
33
+
31
34
  return 'Buffer.from(__a)';
32
35
  }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `Use 'module.exports' instead of 'exports'`;
4
+
5
+ module.exports.replace = () => ({
6
+ 'exports.__a': 'module.exports.__a',
7
+ });
package/lib/index.js CHANGED
@@ -10,6 +10,7 @@ const declare = require('./declare');
10
10
  const declareAfterRequire = require('./declare-after-require');
11
11
  const removeProcessExit = require('./remove-process-exit');
12
12
  const addNodePrefix = require('./add-node-prefix');
13
+ const convertExportsToModuleExports = require('./convert-exports-to-module-exports');
13
14
 
14
15
  module.exports.rules = {
15
16
  'convert-buffer-to-buffer-alloc': convertBufferToBufferAlloc,
@@ -22,4 +23,5 @@ module.exports.rules = {
22
23
  'declare-after-require': declareAfterRequire,
23
24
  'remove-process-exit': removeProcessExit,
24
25
  'add-node-prefix': addNodePrefix,
26
+ 'convert-exports-to-module-exports': convertExportsToModuleExports,
25
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "7.2.0",
3
+ "version": "8.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",
@@ -38,14 +38,14 @@
38
38
  "c8": "^8.0.0",
39
39
  "eslint": "^8.0.1",
40
40
  "eslint-plugin-n": "^16.0.0",
41
- "eslint-plugin-putout": "^19.0.0",
41
+ "eslint-plugin-putout": "^21.0.0",
42
42
  "lerna": "^6.0.1",
43
43
  "madrun": "^9.0.0",
44
44
  "montag": "^1.2.1",
45
45
  "nodemon": "^3.0.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "putout": ">=31"
48
+ "putout": ">=32"
49
49
  },
50
50
  "license": "MIT",
51
51
  "engines": {