@putout/plugin-putout 11.2.0 β 11.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 +35 -1
- package/lib/index.js +1 -0
- package/lib/replace-test-message/index.js +74 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,8 @@ npm i @putout/plugin-putout -D
|
|
|
42
42
|
"putout/check-replace-code": "on",
|
|
43
43
|
"putout/declare": "on",
|
|
44
44
|
"putout/includer": "on",
|
|
45
|
-
"putout/move-require-on-top-level": "on"
|
|
45
|
+
"putout/move-require-on-top-level": "on",
|
|
46
|
+
"putout/replace-test-message": "on"
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
```
|
|
@@ -618,6 +619,39 @@ module.exports.include = () => ['cons __a = __b'];
|
|
|
618
619
|
module.exports.exclude = () => ['var __a = __b'];
|
|
619
620
|
```
|
|
620
621
|
|
|
622
|
+
## replace-test-message
|
|
623
|
+
|
|
624
|
+
Checks that `test message` and used `operator` are synchronized.
|
|
625
|
+
Check it out in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d9c6972ea848ba8e7e745d2479727b65/199c30b986ce7d544397c344ebfc5031c4b53181).
|
|
626
|
+
|
|
627
|
+
### β Example of incorrect code
|
|
628
|
+
|
|
629
|
+
```js
|
|
630
|
+
test('plugin-putout: rename-operate-to-operator: transform: operator exist', (t) => {
|
|
631
|
+
t.noTransform('operator');
|
|
632
|
+
t.end();
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
test('plugin-putout: rename-operate-to-operator: report: operator exist', (t) => {
|
|
636
|
+
t.noReport('operator');
|
|
637
|
+
t.end();
|
|
638
|
+
});
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### β
Example of correct code
|
|
642
|
+
|
|
643
|
+
```js
|
|
644
|
+
test('plugin-putout: rename-operate-to-operator: no transform: operator exist', (t) => {
|
|
645
|
+
t.noTransform('operator');
|
|
646
|
+
t.end();
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
test('plugin-putout: rename-operate-to-operator: no report: operator exist', (t) => {
|
|
650
|
+
t.noReport('operator');
|
|
651
|
+
t.end();
|
|
652
|
+
});
|
|
653
|
+
```
|
|
654
|
+
|
|
621
655
|
## License
|
|
622
656
|
|
|
623
657
|
MIT
|
package/lib/index.js
CHANGED
|
@@ -26,6 +26,7 @@ module.exports.rules = {
|
|
|
26
26
|
...getRule('convert-add-argument-to-add-args'),
|
|
27
27
|
...getRule('convert-dirname-to-url'),
|
|
28
28
|
...getRule('convert-url-to-dirname'),
|
|
29
|
+
...getRule('replace-test-message'),
|
|
29
30
|
...getRule('rename-operate-to-operator'),
|
|
30
31
|
...getRule('replace-operate-with-operator'),
|
|
31
32
|
...getRule('shorten-imports'),
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
|
|
5
|
+
const {isCallExpression} = types;
|
|
6
|
+
|
|
7
|
+
module.exports.report = ({correct, operatorPath}) => {
|
|
8
|
+
const calleePath = operatorPath.get('callee');
|
|
9
|
+
return `Use '${correct}' in test message when using '${calleePath}()'`;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports.fix = ({path, incorrect, correct}) => {
|
|
13
|
+
path.node.value = path.node.value.replace(incorrect, correct);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports.traverse = ({push}) => ({
|
|
17
|
+
't.transform(__a)': convert({
|
|
18
|
+
push,
|
|
19
|
+
incorrect: /: no transform/,
|
|
20
|
+
correct: ': transform',
|
|
21
|
+
}),
|
|
22
|
+
't.noTransform(__a)': convert({
|
|
23
|
+
push,
|
|
24
|
+
incorrect: /: transform/,
|
|
25
|
+
correct: ': no transform',
|
|
26
|
+
}),
|
|
27
|
+
't.report(__a)': convert({
|
|
28
|
+
push,
|
|
29
|
+
incorrect: /: no report/,
|
|
30
|
+
correct: ': report',
|
|
31
|
+
}),
|
|
32
|
+
't.noReport(__a)': convert({
|
|
33
|
+
push,
|
|
34
|
+
incorrect: /: (report|transform|no transform)/,
|
|
35
|
+
correct: ': no report',
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const convert = ({push, correct, incorrect}) => (path) => {
|
|
40
|
+
const [is, messagePath] = isCorrect({
|
|
41
|
+
incorrect,
|
|
42
|
+
path,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (is)
|
|
46
|
+
return;
|
|
47
|
+
|
|
48
|
+
push({
|
|
49
|
+
path: messagePath,
|
|
50
|
+
operatorPath: path,
|
|
51
|
+
incorrect,
|
|
52
|
+
correct,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const CORRECT = true;
|
|
57
|
+
|
|
58
|
+
function isCorrect({path, incorrect}) {
|
|
59
|
+
const calleePath = path.findParent(isCallExpression);
|
|
60
|
+
|
|
61
|
+
if (!calleePath)
|
|
62
|
+
return [CORRECT];
|
|
63
|
+
|
|
64
|
+
const messagePath = calleePath.get('arguments.0');
|
|
65
|
+
|
|
66
|
+
if (!messagePath.isStringLiteral())
|
|
67
|
+
return [CORRECT];
|
|
68
|
+
|
|
69
|
+
const {value} = messagePath.node;
|
|
70
|
+
const is = !incorrect.test(value);
|
|
71
|
+
|
|
72
|
+
return [is, messagePath];
|
|
73
|
+
}
|
|
74
|
+
|
package/package.json
CHANGED