@putout/plugin-putout 12.6.0 → 12.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
|
@@ -23,6 +23,8 @@ npm i @putout/plugin-putout -D
|
|
|
23
23
|
"putout/apply-declare": "on",
|
|
24
24
|
"putout/add-args": "on",
|
|
25
25
|
"putout/add-push": "on",
|
|
26
|
+
"putout/check-match": "on",
|
|
27
|
+
"putout/check-replace-code": "on",
|
|
26
28
|
"putout/convert-putout-test-to-create-test": "on",
|
|
27
29
|
"putout/convert-to-no-transform-code": "on",
|
|
28
30
|
"putout/convert-number-to-numeric": "on",
|
|
@@ -43,7 +45,6 @@ npm i @putout/plugin-putout -D
|
|
|
43
45
|
"putout/convert-report-to-function": "on",
|
|
44
46
|
"putout/create-test": "on",
|
|
45
47
|
"putout/shorten-imports": "on",
|
|
46
|
-
"putout/check-replace-code": "on",
|
|
47
48
|
"putout/declare": "on",
|
|
48
49
|
"putout/includer": "on",
|
|
49
50
|
"putout/move-require-on-top-level": "on",
|
|
@@ -502,8 +503,28 @@ module.exports.replace = () => ({
|
|
|
502
503
|
});
|
|
503
504
|
```
|
|
504
505
|
|
|
505
|
-
There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
506
|
-
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable
|
|
506
|
+
☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
507
|
+
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
508
|
+
|
|
509
|
+
## check-match
|
|
510
|
+
|
|
511
|
+
Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) `match()` keys exists in `replace`.
|
|
512
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c245bee6b129614b2f68c2e89fc3b101/d9f935ccd7f41ff166111cd62277f3244b1d526e).
|
|
513
|
+
|
|
514
|
+
### ❌ Example of incorrect code
|
|
515
|
+
|
|
516
|
+
```js
|
|
517
|
+
module.exports.match = () => ({
|
|
518
|
+
'__a = __b': (vars, path) => {},
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
module.exports.replace = () => ({
|
|
522
|
+
'__a = __': '__a',
|
|
523
|
+
});
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
527
|
+
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
507
528
|
|
|
508
529
|
## declare
|
|
509
530
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
operator,
|
|
5
|
+
types,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
getTemplateValues,
|
|
10
|
+
traverse,
|
|
11
|
+
} = operator;
|
|
12
|
+
|
|
13
|
+
const {isStringLiteral} = types;
|
|
14
|
+
|
|
15
|
+
const PATTERN_MATCH = 'module.exports.match = () => __object';
|
|
16
|
+
const PATTERN_REPLACE = 'module.exports.replace = () => __object';
|
|
17
|
+
|
|
18
|
+
module.exports.report = () => `☝️ Looks like 'match()' template absent in 'replace()'`;
|
|
19
|
+
|
|
20
|
+
module.exports.replace = () => ({
|
|
21
|
+
[PATTERN_MATCH]: PATTERN_MATCH,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
module.exports.match = () => ({
|
|
25
|
+
[PATTERN_MATCH]: ({__object}, path) => {
|
|
26
|
+
const namesMatch = [];
|
|
27
|
+
|
|
28
|
+
for (const prop of __object.properties) {
|
|
29
|
+
if (!isStringLiteral(prop.key))
|
|
30
|
+
continue;
|
|
31
|
+
|
|
32
|
+
namesMatch.push(prop.key.value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const namesReplace = [];
|
|
36
|
+
|
|
37
|
+
traverse(path.parentPath.parentPath, {
|
|
38
|
+
[PATTERN_REPLACE]: (path) => {
|
|
39
|
+
const {__object} = getTemplateValues(path, PATTERN_REPLACE);
|
|
40
|
+
|
|
41
|
+
for (const prop of __object.properties) {
|
|
42
|
+
if (!isStringLiteral(prop.key))
|
|
43
|
+
continue;
|
|
44
|
+
|
|
45
|
+
namesReplace.push(prop.key.value);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
for (const name of namesMatch) {
|
|
51
|
+
if (!namesReplace.includes(name)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
@@ -54,6 +54,11 @@ module.exports = (rootPath, key) => {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
if (/__args/.test(name)) {
|
|
58
|
+
path.node.name = getVar(name);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
if (name === '__array') {
|
|
58
63
|
if (path.parentPath.isVariableDeclarator())
|
|
59
64
|
return replaceWith(path, ArrayPattern([]));
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,8 @@ module.exports.rules = {
|
|
|
10
10
|
...getRule('apply-create-test'),
|
|
11
11
|
...getRule('apply-remove'),
|
|
12
12
|
...getRule('apply-declare'),
|
|
13
|
+
...getRule('check-replace-code'),
|
|
14
|
+
...getRule('check-match'),
|
|
13
15
|
...getRule('convert-putout-test-to-create-test'),
|
|
14
16
|
...getRule('convert-to-no-transform-code'),
|
|
15
17
|
...getRule('convert-find-to-traverse'),
|
|
@@ -33,7 +35,6 @@ module.exports.rules = {
|
|
|
33
35
|
...getRule('rename-operate-to-operator'),
|
|
34
36
|
...getRule('replace-operate-with-operator'),
|
|
35
37
|
...getRule('shorten-imports'),
|
|
36
|
-
...getRule('check-replace-code'),
|
|
37
38
|
...getRule('declare'),
|
|
38
39
|
...getRule('add-args'),
|
|
39
40
|
...getRule('add-push'),
|
package/package.json
CHANGED