@putout/plugin-tape 7.5.0 → 7.6.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 +25 -0
- package/lib/convert-equal-to-deep-equal/index.js +45 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,6 +31,7 @@ npm i @putout/plugin-tape -D
|
|
|
31
31
|
"tape/convert-called-with-to-called-with-no-args": "on",
|
|
32
32
|
"tape/convert-called-with-no-args-to-called-with": "on",
|
|
33
33
|
"tape/convert-equal-to-called-once": "on",
|
|
34
|
+
"tape/convert-equal-to-deep-equal": "on",
|
|
34
35
|
"tape/convert-deep-equal-to-equal": "on",
|
|
35
36
|
"tape/expand-try-catch-arguments": "on",
|
|
36
37
|
"tape/convert-emitter-to-promise": "on",
|
|
@@ -644,6 +645,30 @@ t.equal(result, true);
|
|
|
644
645
|
t.ok(result);
|
|
645
646
|
```
|
|
646
647
|
|
|
648
|
+
## convert-equal-to-deep-equal
|
|
649
|
+
|
|
650
|
+
### ❌ Incorrect code example
|
|
651
|
+
|
|
652
|
+
```js
|
|
653
|
+
const expected = {
|
|
654
|
+
hello: 'world',
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
t.equal(error, expected);
|
|
658
|
+
t.end();
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
### ✅ Correct code example
|
|
662
|
+
|
|
663
|
+
```js
|
|
664
|
+
const expected = {
|
|
665
|
+
hello: 'world',
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
t.deepEqual(error, expected);
|
|
669
|
+
t.end();
|
|
670
|
+
```
|
|
671
|
+
|
|
647
672
|
## convert-match-regexp-to-string
|
|
648
673
|
|
|
649
674
|
### ❌ Incorrect code example
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
isArrayExpression,
|
|
7
|
+
isIdentifier,
|
|
8
|
+
isObjectExpression,
|
|
9
|
+
} = types;
|
|
10
|
+
|
|
11
|
+
module.exports.report = () => `Use 't.deepEqual()' when comparing Objects an Arrays`;
|
|
12
|
+
|
|
13
|
+
module.exports.match = () => ({
|
|
14
|
+
't.equal(__a, __b)': check,
|
|
15
|
+
't.notEqual(__a, __b)': check,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
module.exports.replace = () => ({
|
|
19
|
+
't.equal(__a, __b)': 't.deepEqual(__a, __b)',
|
|
20
|
+
't.notEqual(__a, __b)': 't.notDeepEqual(__a, __b)',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function check({__b}, path) {
|
|
24
|
+
if (isObjectExpression(__b))
|
|
25
|
+
return true;
|
|
26
|
+
|
|
27
|
+
if (isArrayExpression(__b))
|
|
28
|
+
return true;
|
|
29
|
+
|
|
30
|
+
if (!isIdentifier(__b))
|
|
31
|
+
return false;
|
|
32
|
+
|
|
33
|
+
const __bDeclaration = path.scope.bindings[__b.name];
|
|
34
|
+
|
|
35
|
+
if (!__bDeclaration)
|
|
36
|
+
return false;
|
|
37
|
+
|
|
38
|
+
const {id, init} = __bDeclaration.path.node;
|
|
39
|
+
|
|
40
|
+
if (!isIdentifier(id, {name: 'expected'}))
|
|
41
|
+
return false;
|
|
42
|
+
|
|
43
|
+
return isObjectExpression(init) || isArrayExpression(init);
|
|
44
|
+
}
|
|
45
|
+
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ module.exports.rules = {
|
|
|
19
19
|
...getRule('convert-ok-to-called-with'),
|
|
20
20
|
...getRule('convert-match-regexp-to-string'),
|
|
21
21
|
...getRule('convert-equal-to-not-ok'),
|
|
22
|
+
...getRule('convert-equal-to-deep-equal'),
|
|
22
23
|
...getRule('convert-equal-to-ok'),
|
|
23
24
|
...getRule('convert-equal-to-called-once'),
|
|
24
25
|
...getRule('convert-deep-equal-to-equal'),
|