@putout/plugin-putout 23.2.0 → 23.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.
|
@@ -57,7 +57,7 @@ const check = ({__a}, path) => {
|
|
|
57
57
|
const regEnd = RegExp(`: ${name}$`);
|
|
58
58
|
const regMiddle = RegExp(`: ${name}: .*`);
|
|
59
59
|
|
|
60
|
-
return !
|
|
60
|
+
return !regEnd.test(value) && !regMiddle.test(value);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const transform = ({__a}, path) => {
|
package/lib/check-match/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const {isStringLiteral} = types;
|
|
|
11
11
|
|
|
12
12
|
const PATTERN_MATCH = 'module.exports.match = () => __object';
|
|
13
13
|
const PATTERN_REPLACE = 'module.exports.replace = () => __object';
|
|
14
|
+
const PATTERN_REPLACE_RETURN = 'module.exports.replace = (__args) => __body';
|
|
14
15
|
|
|
15
16
|
module.exports.report = () => `☝️ Looks like 'match()' template absent in 'replace()'`;
|
|
16
17
|
|
|
@@ -20,27 +21,19 @@ module.exports.replace = () => ({
|
|
|
20
21
|
|
|
21
22
|
module.exports.match = () => ({
|
|
22
23
|
[PATTERN_MATCH]: ({__object}, path) => {
|
|
23
|
-
const namesMatch =
|
|
24
|
-
|
|
25
|
-
for (const prop of __object.properties) {
|
|
26
|
-
if (!isStringLiteral(prop.key))
|
|
27
|
-
continue;
|
|
28
|
-
|
|
29
|
-
namesMatch.push(prop.key.value);
|
|
30
|
-
}
|
|
31
|
-
|
|
24
|
+
const namesMatch = getNames(__object);
|
|
32
25
|
const namesReplace = [];
|
|
33
26
|
|
|
34
27
|
traverse(path.parentPath.parentPath, {
|
|
28
|
+
[PATTERN_REPLACE_RETURN]: (path) => {
|
|
29
|
+
const {__body} = getTemplateValues(path, PATTERN_REPLACE_RETURN);
|
|
30
|
+
const object = __body.body.at(-1).argument;
|
|
31
|
+
|
|
32
|
+
namesReplace.push(...getNames(object));
|
|
33
|
+
},
|
|
35
34
|
[PATTERN_REPLACE]: (path) => {
|
|
36
35
|
const {__object} = getTemplateValues(path, PATTERN_REPLACE);
|
|
37
|
-
|
|
38
|
-
for (const prop of __object.properties) {
|
|
39
|
-
if (!isStringLiteral(prop.key))
|
|
40
|
-
continue;
|
|
41
|
-
|
|
42
|
-
namesReplace.push(prop.key.value);
|
|
43
|
-
}
|
|
36
|
+
namesReplace.push(...getNames(__object));
|
|
44
37
|
},
|
|
45
38
|
});
|
|
46
39
|
|
|
@@ -52,3 +45,16 @@ module.exports.match = () => ({
|
|
|
52
45
|
return false;
|
|
53
46
|
},
|
|
54
47
|
});
|
|
48
|
+
|
|
49
|
+
function getNames({properties}) {
|
|
50
|
+
const names = [];
|
|
51
|
+
|
|
52
|
+
for (const prop of properties) {
|
|
53
|
+
if (!isStringLiteral(prop.key))
|
|
54
|
+
continue;
|
|
55
|
+
|
|
56
|
+
names.push(prop.key.value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return names;
|
|
60
|
+
}
|
package/package.json
CHANGED