@putout/plugin-tape 9.9.1 → 9.12.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.
|
@@ -26,12 +26,14 @@ function checkStubs({__a, __b}, path) {
|
|
|
26
26
|
const __array = {
|
|
27
27
|
elements,
|
|
28
28
|
};
|
|
29
|
+
|
|
29
30
|
return checkStubsArray({__array}, path);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
function applyWithName({__a, __b}, path) {
|
|
33
34
|
applyWithNameToNode(__a, path);
|
|
34
35
|
applyWithNameToNode(__b, path);
|
|
36
|
+
|
|
35
37
|
return path;
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
types,
|
|
5
|
+
operator,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
8
|
+
const isNull = (a) => !a && typeof a === 'object';
|
|
9
|
+
|
|
10
|
+
const isUndefined = (a) => typeof a === 'undefined';
|
|
11
|
+
const isBool = (a) => typeof a === 'boolean';
|
|
12
|
+
|
|
13
|
+
const isNumber = (a) => typeof a === 'number';
|
|
14
|
+
const isString = (a) => typeof a === 'string';
|
|
15
|
+
const isPrimitive = (a) => isString(a) || isNumber(a) || isBool(a) || isNull(a) || isUndefined(a);
|
|
16
|
+
|
|
17
|
+
const {compute} = operator;
|
|
4
18
|
|
|
5
19
|
const {
|
|
6
20
|
isLiteral,
|
|
7
21
|
isRegExpLiteral,
|
|
22
|
+
isIdentifier,
|
|
8
23
|
} = types;
|
|
9
24
|
|
|
10
25
|
module.exports.report = (path) => {
|
|
@@ -16,11 +31,27 @@ module.exports.report = (path) => {
|
|
|
16
31
|
return `Use 't.equal(${args[0]}, ${args[1]}, ${args[2]})' instead of '${path} when comparin with primitive'`;
|
|
17
32
|
};
|
|
18
33
|
|
|
19
|
-
const check = ({__b}) => {
|
|
34
|
+
const check = ({__b}, path) => {
|
|
20
35
|
if (isRegExpLiteral(__b))
|
|
21
36
|
return false;
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
if (isLiteral(__b))
|
|
39
|
+
return true;
|
|
40
|
+
|
|
41
|
+
if (isIdentifier(__b, {name: 'undefined'}))
|
|
42
|
+
return true;
|
|
43
|
+
|
|
44
|
+
const expectedPath = path.get('arguments.1');
|
|
45
|
+
|
|
46
|
+
if (checkExpected(expectedPath))
|
|
47
|
+
return true;
|
|
48
|
+
|
|
49
|
+
const [is, value] = compute(expectedPath);
|
|
50
|
+
|
|
51
|
+
if (is && isPrimitive(value))
|
|
52
|
+
return true;
|
|
53
|
+
|
|
54
|
+
return false;
|
|
24
55
|
};
|
|
25
56
|
|
|
26
57
|
module.exports.match = () => ({
|
|
@@ -33,3 +64,23 @@ module.exports.replace = () => ({
|
|
|
33
64
|
't.deepEqual(__a, __b, __c)': 't.equal(__a, __b, __c)',
|
|
34
65
|
});
|
|
35
66
|
|
|
67
|
+
function checkExpected(path) {
|
|
68
|
+
if (!path.isIdentifier())
|
|
69
|
+
return false;
|
|
70
|
+
|
|
71
|
+
const {name} = path.node;
|
|
72
|
+
const binding = path.scope.bindings[name];
|
|
73
|
+
|
|
74
|
+
if (!binding)
|
|
75
|
+
return false;
|
|
76
|
+
|
|
77
|
+
if (!binding.path.isVariableDeclarator())
|
|
78
|
+
return false;
|
|
79
|
+
|
|
80
|
+
const initPath = binding.path.get('init');
|
|
81
|
+
|
|
82
|
+
if (initPath.isTaggedTemplateExpression())
|
|
83
|
+
return true;
|
|
84
|
+
|
|
85
|
+
return false;
|
|
86
|
+
}
|