@putout/plugin-putout 8.4.0 → 8.7.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 +68 -0
- package/lib/apply-create-test/index.js +8 -0
- package/lib/check-replace-code/index.js +18 -38
- package/lib/convert-dirname-to-url/index.js +17 -0
- package/lib/convert-url-to-dirname/index.js +15 -0
- package/lib/declare/declarations.js +2 -1
- package/lib/index.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ npm i @putout/plugin-putout -D
|
|
|
16
16
|
```json
|
|
17
17
|
{
|
|
18
18
|
"rules": {
|
|
19
|
+
"putout/apply-create-test": "on",
|
|
19
20
|
"putout/apply-processors-destructuring": "on",
|
|
20
21
|
"putout/apply-async-formatter": "on",
|
|
21
22
|
"putout/add-args": "on",
|
|
@@ -31,6 +32,8 @@ npm i @putout/plugin-putout -D
|
|
|
31
32
|
"putout/convert-process-to-find": "on",
|
|
32
33
|
"putout/convert-method-to-property": "on",
|
|
33
34
|
"putout/convert-add-argument-to-add-args": "on",
|
|
35
|
+
"putout/convert-dirname-to-url": "on",
|
|
36
|
+
"putout/convert-url-to-dirname": "on",
|
|
34
37
|
"putout/shorten-imports": "on",
|
|
35
38
|
"putout/check-replace-code": "on",
|
|
36
39
|
"putout/declare": "on",
|
|
@@ -77,6 +80,25 @@ test('formatter: codeframea', async ({format}) => {
|
|
|
77
80
|
});
|
|
78
81
|
```
|
|
79
82
|
|
|
83
|
+
## apply-create-test
|
|
84
|
+
|
|
85
|
+
### ❌ Incorrect code example
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
const test = require('@putout/test')({
|
|
89
|
+
'remove-debugger': plugin,
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### ✅ Correct code example
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const {createTest} = require('@putout/test');
|
|
97
|
+
const test = createTest({
|
|
98
|
+
'remove-debugger': plugin,
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
80
102
|
## convert-putout-test-to-create-test"
|
|
81
103
|
|
|
82
104
|
Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm) work.
|
|
@@ -396,6 +418,52 @@ module.exports = addArgs({
|
|
|
396
418
|
});
|
|
397
419
|
```
|
|
398
420
|
|
|
421
|
+
## convert-dirname-to-url
|
|
422
|
+
|
|
423
|
+
```js
|
|
424
|
+
import {createTest} from '@putout/test';
|
|
425
|
+
import plugin from '@putout/plugin-debugger';
|
|
426
|
+
import {createSimport} from 'simport';
|
|
427
|
+
const {__dirname} = createSimport(import.meta.url);
|
|
428
|
+
|
|
429
|
+
const test = createTest(__dirname, {
|
|
430
|
+
'remove-debugger': plugin,
|
|
431
|
+
});
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### ✅ Correct code Example
|
|
435
|
+
|
|
436
|
+
```js
|
|
437
|
+
import {createTest} from '@putout/test';
|
|
438
|
+
import plugin from '@putout/plugin-debugger';
|
|
439
|
+
|
|
440
|
+
const test = createTest(import.meta.url, {
|
|
441
|
+
'remove-debugger': plugin,
|
|
442
|
+
});
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
## convert-url-to-dirname-
|
|
446
|
+
|
|
447
|
+
```js
|
|
448
|
+
const {createTest} = require('@putout/test');
|
|
449
|
+
const plugin = require('@putout/plugin-debugger');
|
|
450
|
+
|
|
451
|
+
const test = createTest(import.meta.url, {
|
|
452
|
+
'remove-debugger': plugin,
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### ✅ Correct code Example
|
|
457
|
+
|
|
458
|
+
```js
|
|
459
|
+
const {createTest} = require('@putout/test');
|
|
460
|
+
const plugin = require('@putout/plugin-debugger');
|
|
461
|
+
|
|
462
|
+
const test = createTest(import.meta.url, {
|
|
463
|
+
'remove-debugger': plugin,
|
|
464
|
+
});
|
|
465
|
+
```
|
|
466
|
+
|
|
399
467
|
## move-require-on-top-level
|
|
400
468
|
|
|
401
469
|
### ❌ Incorrect code example
|
|
@@ -5,16 +5,12 @@ const tryCatch = require('try-catch');
|
|
|
5
5
|
|
|
6
6
|
const generateCode = require('./generate-code');
|
|
7
7
|
|
|
8
|
-
const {operator
|
|
9
|
-
const {
|
|
10
|
-
isMemberExpression,
|
|
11
|
-
isObjectExpression,
|
|
12
|
-
} = types;
|
|
8
|
+
const {operator} = putout;
|
|
13
9
|
|
|
14
10
|
const {
|
|
15
11
|
compare,
|
|
16
12
|
extract,
|
|
17
|
-
|
|
13
|
+
compute,
|
|
18
14
|
} = operator;
|
|
19
15
|
|
|
20
16
|
const name = '__putout_plugin_check_replace_code';
|
|
@@ -33,7 +29,7 @@ module.exports.report = ({path, code, error}) => {
|
|
|
33
29
|
if (error)
|
|
34
30
|
return error.message;
|
|
35
31
|
|
|
36
|
-
const key =
|
|
32
|
+
const [, key] = parseKey(path);
|
|
37
33
|
const value = extract(path.node.value);
|
|
38
34
|
|
|
39
35
|
return `transform mismatch: "${key}" -> "${value}" !== "${code}"`;
|
|
@@ -53,13 +49,18 @@ module.exports.traverse = ({push}) => ({
|
|
|
53
49
|
continue;
|
|
54
50
|
|
|
55
51
|
const {node} = propertyPath;
|
|
56
|
-
const key =
|
|
52
|
+
const [parseError, key] = parseKey(propertyPath);
|
|
57
53
|
|
|
58
|
-
if (
|
|
59
|
-
|
|
54
|
+
if (parseError) {
|
|
55
|
+
push({
|
|
56
|
+
error: parseError,
|
|
57
|
+
mainPath: path,
|
|
58
|
+
path: propertyPath,
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
60
62
|
|
|
61
63
|
const template = extract(node.value);
|
|
62
|
-
|
|
63
64
|
const [generateError, keyCode] = generateCode(path, key);
|
|
64
65
|
|
|
65
66
|
if (generateError) {
|
|
@@ -106,34 +107,13 @@ module.exports.traverse = ({push}) => ({
|
|
|
106
107
|
},
|
|
107
108
|
});
|
|
108
109
|
|
|
109
|
-
function
|
|
110
|
-
const
|
|
110
|
+
function parseKey(propertyPath) {
|
|
111
|
+
const keyPath = propertyPath.get('key');
|
|
112
|
+
const [isComputed, key] = compute(keyPath);
|
|
111
113
|
|
|
112
|
-
if (!
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
if (!isMemberExpression(key))
|
|
116
|
-
return '';
|
|
117
|
-
|
|
118
|
-
const bindingPath = getBindingPath(path, extract(key.object));
|
|
119
|
-
|
|
120
|
-
if (!bindingPath)
|
|
121
|
-
return '';
|
|
122
|
-
|
|
123
|
-
const bindingNode = bindingPath.node;
|
|
124
|
-
|
|
125
|
-
if (!isObjectExpression(bindingNode.init))
|
|
126
|
-
return '';
|
|
127
|
-
|
|
128
|
-
const keyPropertyValue = extract(key.property);
|
|
129
|
-
|
|
130
|
-
for (const property of bindingNode.init.properties) {
|
|
131
|
-
const keyValue = extract(property.key);
|
|
132
|
-
|
|
133
|
-
if (keyValue === keyPropertyValue)
|
|
134
|
-
return extract(property.value);
|
|
135
|
-
}
|
|
114
|
+
if (!isComputed)
|
|
115
|
+
return [Error(`Replace key cannot be computed: '${keyPath.toString()}'`)];
|
|
136
116
|
|
|
137
|
-
return
|
|
117
|
+
return [null, key];
|
|
138
118
|
}
|
|
139
119
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator} = require('putout');
|
|
4
|
+
const {isESM} = operator;
|
|
5
|
+
|
|
6
|
+
module.exports.report = () => `Use 'createTest(import.meta.url)' instead of 'createTest(__dirname)'`;
|
|
7
|
+
|
|
8
|
+
module.exports.match = () => ({
|
|
9
|
+
'createTest(__dirname, __a)': (vars, path) => {
|
|
10
|
+
return isESM(path);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
module.exports.replace = () => ({
|
|
15
|
+
'createTest(__dirname, __a)': 'createTest(import.meta.url, __a)',
|
|
16
|
+
});
|
|
17
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator} = require('putout');
|
|
4
|
+
const {isESM} = operator;
|
|
5
|
+
|
|
6
|
+
module.exports.report = () => `Use 'createTest(__dirname)' instead of 'createTest(import.meta.url)' in CommonJS'`;
|
|
7
|
+
|
|
8
|
+
module.exports.match = () => ({
|
|
9
|
+
'createTest(import.meta.url, __a)': (vars, path) => !isESM(path),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
module.exports.replace = () => ({
|
|
13
|
+
'createTest(import.meta.url, __a)': 'createTest(__dirname, __a)',
|
|
14
|
+
});
|
|
15
|
+
|
|
@@ -4,7 +4,8 @@ const types = require('./types');
|
|
|
4
4
|
const operator = require('./operator');
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
template: `
|
|
7
|
+
template: `import {template} from 'putout'`,
|
|
8
|
+
createTest: `import {createTest} from '@putout/test'`,
|
|
8
9
|
...operator,
|
|
9
10
|
...types,
|
|
10
11
|
};
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const getRule = (a) => ({
|
|
|
7
7
|
module.exports.rules = {
|
|
8
8
|
...getRule('apply-processors-destructuring'),
|
|
9
9
|
...getRule('apply-async-formatter'),
|
|
10
|
+
...getRule('apply-create-test'),
|
|
10
11
|
...getRule('convert-putout-test-to-create-test'),
|
|
11
12
|
...getRule('convert-to-no-transform-code'),
|
|
12
13
|
...getRule('convert-find-to-traverse'),
|
|
@@ -20,6 +21,8 @@ module.exports.rules = {
|
|
|
20
21
|
...getRule('convert-process-to-find'),
|
|
21
22
|
...getRule('convert-method-to-property'),
|
|
22
23
|
...getRule('convert-add-argument-to-add-args'),
|
|
24
|
+
...getRule('convert-dirname-to-url'),
|
|
25
|
+
...getRule('convert-url-to-dirname'),
|
|
23
26
|
...getRule('rename-operate-to-operator'),
|
|
24
27
|
...getRule('replace-operate-with-operator'),
|
|
25
28
|
...getRule('shorten-imports'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.7.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "putout plugin helps with plugins development",
|
|
6
6
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout",
|