@putout/plugin-putout 25.1.0 → 25.3.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 +20 -28
- package/lib/add-test-args/index.js +1 -7
- package/lib/add-track-file/index.js +1 -7
- package/lib/apply-exports/index.js +1 -6
- package/lib/apply-exports-to-add-args/index.js +1 -6
- package/lib/apply-exports-to-match-files/index.js +1 -6
- package/lib/apply-exports-to-rename-files/index.js +1 -6
- package/lib/apply-fixture-name-to-message/index.js +3 -0
- package/lib/apply-namespace-specifier/index.js +4 -2
- package/lib/apply-report/index.js +3 -0
- package/lib/convert-replace-with/index.js +3 -54
- package/lib/replace-test-message/index.js +16 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -493,7 +493,7 @@ export default createRenameProperty([
|
|
|
493
493
|
### ✅ Example of correct code
|
|
494
494
|
|
|
495
495
|
```js
|
|
496
|
-
const {
|
|
496
|
+
export const {
|
|
497
497
|
report,
|
|
498
498
|
fix,
|
|
499
499
|
scan,
|
|
@@ -501,12 +501,6 @@ const {
|
|
|
501
501
|
...v32,
|
|
502
502
|
...v29,
|
|
503
503
|
]);
|
|
504
|
-
|
|
505
|
-
export {
|
|
506
|
-
report,
|
|
507
|
-
fix,
|
|
508
|
-
scan,
|
|
509
|
-
};
|
|
510
504
|
```
|
|
511
505
|
|
|
512
506
|
## apply-exports-to-add-args
|
|
@@ -522,17 +516,11 @@ export default addArgs(__args);
|
|
|
522
516
|
### ✅ Example of correct code
|
|
523
517
|
|
|
524
518
|
```js
|
|
525
|
-
const {
|
|
519
|
+
export const {
|
|
526
520
|
report,
|
|
527
521
|
fix,
|
|
528
522
|
traverse,
|
|
529
523
|
} = addArgs(__args);
|
|
530
|
-
|
|
531
|
-
export {
|
|
532
|
-
report,
|
|
533
|
-
fix,
|
|
534
|
-
traverse,
|
|
535
|
-
};
|
|
536
524
|
```
|
|
537
525
|
|
|
538
526
|
## apply-exports-to-match-files
|
|
@@ -550,19 +538,13 @@ export default matchFiles({
|
|
|
550
538
|
### ✅ Example of correct code
|
|
551
539
|
|
|
552
540
|
```js
|
|
553
|
-
const {
|
|
541
|
+
export const {
|
|
554
542
|
report,
|
|
555
543
|
fix,
|
|
556
544
|
scan,
|
|
557
545
|
} = matchFiles({
|
|
558
546
|
'*.cjs': plugin,
|
|
559
547
|
});
|
|
560
|
-
|
|
561
|
-
export {
|
|
562
|
-
report,
|
|
563
|
-
fix,
|
|
564
|
-
scan,
|
|
565
|
-
};
|
|
566
548
|
```
|
|
567
549
|
|
|
568
550
|
## apply-exports-to-rename-files
|
|
@@ -584,7 +566,7 @@ export default renameFiles({
|
|
|
584
566
|
### ✅ Example of correct code
|
|
585
567
|
|
|
586
568
|
```js
|
|
587
|
-
const {
|
|
569
|
+
export const {
|
|
588
570
|
report,
|
|
589
571
|
fix,
|
|
590
572
|
scan,
|
|
@@ -595,12 +577,6 @@ const {
|
|
|
595
577
|
return name.replace(/mjs$/, 'js');
|
|
596
578
|
},
|
|
597
579
|
});
|
|
598
|
-
|
|
599
|
-
export {
|
|
600
|
-
report,
|
|
601
|
-
fix,
|
|
602
|
-
scan,
|
|
603
|
-
};
|
|
604
580
|
```
|
|
605
581
|
|
|
606
582
|
## apply-async-formatter
|
|
@@ -660,6 +636,22 @@ const dirPath = createNestedDirectory(path, '/hello/world');
|
|
|
660
636
|
const dirPath2 = createDirectory(path, 'world');
|
|
661
637
|
```
|
|
662
638
|
|
|
639
|
+
## apply-namespace-specifier
|
|
640
|
+
|
|
641
|
+
Most likely what you need is [`esm/resolve-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#resolve-imported-file).
|
|
642
|
+
|
|
643
|
+
### ❌ Example of incorrect code
|
|
644
|
+
|
|
645
|
+
```js
|
|
646
|
+
import rmUnused from '@putout/plugin-remove-unused-variables';
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
### ✅ Example of correct code
|
|
650
|
+
|
|
651
|
+
```js
|
|
652
|
+
import * as rmUnused from '@putout/plugin-remove-unused-variables';
|
|
653
|
+
```
|
|
654
|
+
|
|
663
655
|
## apply-for-of-to-track-file
|
|
664
656
|
|
|
665
657
|
> The **Generator** object is returned by a `generator function` and it conforms to both the iterable protocol and the `iterator` protocol.
|
|
@@ -2,7 +2,7 @@ import {operator} from 'putout';
|
|
|
2
2
|
|
|
3
3
|
const {addArgs} = operator;
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
export const {
|
|
6
6
|
report,
|
|
7
7
|
fix,
|
|
8
8
|
traverse,
|
|
@@ -28,9 +28,3 @@ const {
|
|
|
28
28
|
'test.only("__a", async (__args) => __body)',
|
|
29
29
|
]],
|
|
30
30
|
});
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
report,
|
|
34
|
-
fix,
|
|
35
|
-
traverse,
|
|
36
|
-
};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {createApplyExports} from '../create-apply-exports.js';
|
|
2
2
|
|
|
3
|
-
const {report, replace} = createApplyExports({
|
|
3
|
+
export const {report, replace} = createApplyExports({
|
|
4
4
|
addArgs: [
|
|
5
5
|
'report',
|
|
6
6
|
'fix',
|
|
7
7
|
'traverse',
|
|
8
8
|
],
|
|
9
9
|
});
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
report,
|
|
13
|
-
replace,
|
|
14
|
-
};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {createApplyExports} from '../create-apply-exports.js';
|
|
2
2
|
|
|
3
|
-
const {report, replace} = createApplyExports({
|
|
3
|
+
export const {report, replace} = createApplyExports({
|
|
4
4
|
matchFiles: [
|
|
5
5
|
'report',
|
|
6
6
|
'fix',
|
|
7
7
|
'scan',
|
|
8
8
|
],
|
|
9
9
|
});
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
report,
|
|
13
|
-
replace,
|
|
14
|
-
};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {createApplyExports} from '../create-apply-exports.js';
|
|
2
2
|
|
|
3
|
-
const {report, replace} = createApplyExports({
|
|
3
|
+
export const {report, replace} = createApplyExports({
|
|
4
4
|
renameFiles: [
|
|
5
5
|
'report',
|
|
6
6
|
'fix',
|
|
7
7
|
'scan',
|
|
8
8
|
],
|
|
9
9
|
});
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
report,
|
|
13
|
-
replace,
|
|
14
|
-
};
|
|
@@ -14,12 +14,14 @@ const NAMES = [
|
|
|
14
14
|
...FIXTURE,
|
|
15
15
|
'no report',
|
|
16
16
|
'no transform',
|
|
17
|
+
'no report after transform',
|
|
17
18
|
];
|
|
18
19
|
|
|
19
20
|
export const report = () => `Apply 'fixture' name to 'message'`;
|
|
20
21
|
|
|
21
22
|
export const match = () => ({
|
|
22
23
|
't.noReport(__a)': check,
|
|
24
|
+
't.noReportAfterTransform(__a)': check,
|
|
23
25
|
't.report(__a, __b)': check,
|
|
24
26
|
't.transform(__a)': check,
|
|
25
27
|
't.transform(__a, __b)': check,
|
|
@@ -32,6 +34,7 @@ export const replace = () => ({
|
|
|
32
34
|
't.transform(__a)': transform,
|
|
33
35
|
't.transform(__a, __b)': transform,
|
|
34
36
|
't.noTransform(__a)': transform,
|
|
37
|
+
't.noReportAfterTransform(__a)': transform,
|
|
35
38
|
});
|
|
36
39
|
|
|
37
40
|
const isTest = (path) => compare(path, 'test(__a, (t) => __body)', {
|
|
@@ -19,8 +19,6 @@ export const traverse = ({push, listStore, pathStore}) => ({
|
|
|
19
19
|
names: [
|
|
20
20
|
'@putout/plugin-',
|
|
21
21
|
'./index.js',
|
|
22
|
-
'../lib/index.js',
|
|
23
|
-
'../',
|
|
24
22
|
],
|
|
25
23
|
}),
|
|
26
24
|
'Program': {
|
|
@@ -66,6 +64,10 @@ const createImportVisitor = ({push, names, pathStore = noop}) => ({
|
|
|
66
64
|
return;
|
|
67
65
|
|
|
68
66
|
for (const name of names) {
|
|
67
|
+
if (!value.replace('.js', '').replace('./', '')
|
|
68
|
+
.includes('/'))
|
|
69
|
+
continue;
|
|
70
|
+
|
|
69
71
|
if (value === name || value.startsWith(name) || name === 'any') {
|
|
70
72
|
push({
|
|
71
73
|
path,
|
|
@@ -19,6 +19,9 @@ export const report = (path) => {
|
|
|
19
19
|
return `Use 't.${TYPES[name]}()' instead of 't.${name}()'`;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
export const exclude = () => [
|
|
23
|
+
't.noReport(__a, __array)',
|
|
24
|
+
];
|
|
22
25
|
export const replace = () => ({
|
|
23
26
|
't.noReport(__a, __object)': 't.noReportWithOptions(__a, __object)',
|
|
24
27
|
't.noReport(__a, __b)': 't.noReport(__a)',
|
|
@@ -1,68 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
operator,
|
|
3
|
-
template,
|
|
4
|
-
types,
|
|
5
|
-
} from 'putout';
|
|
1
|
+
import {operator} from 'putout';
|
|
6
2
|
import fullstore from 'fullstore';
|
|
7
3
|
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
replaceWith,
|
|
12
|
-
insertAfter,
|
|
13
|
-
insertBefore,
|
|
14
|
-
} = operator;
|
|
4
|
+
const {replaceWith} = operator;
|
|
15
5
|
|
|
16
6
|
export const report = () => {
|
|
17
7
|
return `Use 'operator.replaceWith()' instead of 'path.replaceWith()'`;
|
|
18
8
|
};
|
|
19
9
|
|
|
20
|
-
export const fix = ({path, calleePath, property, object
|
|
10
|
+
export const fix = ({path, calleePath, property, object}) => {
|
|
21
11
|
replaceWith(calleePath, property);
|
|
22
|
-
const {bindings} = program.scope;
|
|
23
|
-
|
|
24
12
|
path.node.arguments.unshift(object);
|
|
25
|
-
|
|
26
|
-
if (bindings.replaceWith || isInserted())
|
|
27
|
-
return;
|
|
28
|
-
|
|
29
|
-
if (!bindings.replaceWithMultiple && !bindings.insertAfter && !isInserted()) {
|
|
30
|
-
const replaceWithAST = template.ast.fresh(`
|
|
31
|
-
const {replaceWith} = require('putout').operator;
|
|
32
|
-
`);
|
|
33
|
-
|
|
34
|
-
const {types} = bindings;
|
|
35
|
-
const first = program.get('body.0');
|
|
36
|
-
const pathToInsert = types ? types.path.parentPath : first;
|
|
37
|
-
|
|
38
|
-
if (types)
|
|
39
|
-
insertAfter(pathToInsert, replaceWithAST);
|
|
40
|
-
else
|
|
41
|
-
insertBefore(pathToInsert, replaceWithAST);
|
|
42
|
-
|
|
43
|
-
isInserted(true);
|
|
44
|
-
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const id = identifier('replaceWith');
|
|
49
|
-
const varPath = getVarPath(bindings);
|
|
50
|
-
|
|
51
|
-
varPath.node.id.properties.unshift(objectProperty(id, id, false, true));
|
|
52
13
|
};
|
|
53
14
|
|
|
54
|
-
function getVarPath(bindings) {
|
|
55
|
-
const {
|
|
56
|
-
replaceWithMultiple,
|
|
57
|
-
insertAfter,
|
|
58
|
-
} = bindings;
|
|
59
|
-
|
|
60
|
-
if (replaceWithMultiple)
|
|
61
|
-
return replaceWithMultiple.path;
|
|
62
|
-
|
|
63
|
-
return insertAfter.path;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
15
|
export const traverse = ({push}) => {
|
|
67
16
|
const isInserted = fullstore();
|
|
68
17
|
|
|
@@ -13,10 +13,11 @@ export const fix = ({path, incorrect, correct}) => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
const INCORRECT = {
|
|
16
|
-
TRANSFORM: /: (no transform|report|no report)/,
|
|
17
|
-
NO_TRANSFORM: /: (transform|report|no report)/,
|
|
18
|
-
REPORT: /: (no report|transform|no transform)/,
|
|
19
|
-
NO_REPORT: /: (report|transform|no transform)/,
|
|
16
|
+
TRANSFORM: /: (no report after transform|no transform|report|no report)/,
|
|
17
|
+
NO_TRANSFORM: /: (no report after transform|transform|report|no report)/,
|
|
18
|
+
REPORT: /: (no report after transform|no report|transform|no transform)/,
|
|
19
|
+
NO_REPORT: /: (no report after transform|report|transform|no transform)/,
|
|
20
|
+
NO_REPORT_AFTER_TRANSFORM: /: (report|transform|no transform|no report)/,
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export const traverse = ({push}) => ({
|
|
@@ -45,12 +46,18 @@ export const traverse = ({push}) => ({
|
|
|
45
46
|
incorrect: INCORRECT.NO_REPORT,
|
|
46
47
|
correct: ': no report',
|
|
47
48
|
}),
|
|
49
|
+
't.noReportAfterTransform(__a)': convert({
|
|
50
|
+
push,
|
|
51
|
+
incorrect: INCORRECT.NO_REPORT_AFTER_TRANSFORM,
|
|
52
|
+
correct: ': no report after transform',
|
|
53
|
+
}),
|
|
48
54
|
});
|
|
49
55
|
|
|
50
56
|
const convert = ({push, correct, incorrect}) => (path) => {
|
|
51
57
|
const [is, messagePath] = isCorrect({
|
|
52
58
|
incorrect,
|
|
53
59
|
path,
|
|
60
|
+
correct,
|
|
54
61
|
});
|
|
55
62
|
|
|
56
63
|
if (is)
|
|
@@ -66,7 +73,7 @@ const convert = ({push, correct, incorrect}) => (path) => {
|
|
|
66
73
|
|
|
67
74
|
const CORRECT = true;
|
|
68
75
|
|
|
69
|
-
function isCorrect({path, incorrect}) {
|
|
76
|
+
function isCorrect({path, correct, incorrect}) {
|
|
70
77
|
const calleePath = path.findParent(isCallExpression);
|
|
71
78
|
|
|
72
79
|
if (!calleePath)
|
|
@@ -78,6 +85,10 @@ function isCorrect({path, incorrect}) {
|
|
|
78
85
|
return [CORRECT];
|
|
79
86
|
|
|
80
87
|
const {value} = messagePath.node;
|
|
88
|
+
|
|
89
|
+
if (value.includes(correct))
|
|
90
|
+
return [CORRECT];
|
|
91
|
+
|
|
81
92
|
const is = !incorrect.test(value);
|
|
82
93
|
|
|
83
94
|
return [is, messagePath];
|
package/package.json
CHANGED