@putout/plugin-tape 21.7.0 β†’ 21.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
@@ -823,6 +823,8 @@ test('some test', (t) => {
823
823
 
824
824
  ## move-out-result-from-assertion
825
825
 
826
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/264bc87f56eae9aa2b2884ff64fe7a06/94836a115a072a18fd717d5454792c1895ab0476).
827
+
826
828
  ### ❌ Example of incorrect code
827
829
 
828
830
  ```js
@@ -1,17 +1,78 @@
1
- export const report = () => `Move out result from asssertion`;
1
+ import {operator, types} from 'putout';
2
+
3
+ const {getBinding} = operator;
4
+
5
+ const {
6
+ isIdentifier,
7
+ isMemberExpression,
8
+ isOptionalMemberExpression,
9
+ isObjectExpression,
10
+ } = types;
11
+
12
+ export const report = () => `Move out result from assertion`;
13
+ export const match = () => ({
14
+ 't.__a(__b, __c)': ({__a, __b, __c}, path) => {
15
+ if (!/equal/i.test(__a.name))
16
+ return false;
17
+
18
+ if (isMemberExpression(__b) && __b.property.name === 'callCount')
19
+ return false;
20
+
21
+ if (isMemberExpression(__b))
22
+ return false;
23
+
24
+ if (isOptionalMemberExpression(__b))
25
+ return false;
26
+
27
+ const resultBinding = getBinding(path, 'result');
28
+ const expectedBinding = getBinding(path, 'expected');
29
+
30
+ if (resultBinding && expectedBinding)
31
+ return false;
32
+
33
+ if (!resultBinding && !isIdentifier(__b))
34
+ return true;
35
+
36
+ if (expectedBinding)
37
+ return false;
38
+
39
+ return isObjectExpression(__c);
40
+ },
41
+ });
2
42
 
3
43
  export const replace = () => ({
4
44
  't.__(__a.__b(__args).__c)': `{
5
- const {__c} = __a.__b(__args);
45
+ const {__c} = __a.__b(__args);
6
46
  t.__(__c);
7
47
  }`,
8
- 't.__(__a(__b), __c)': `{
9
- const result = __a(__b);
10
- const expected = __c;
11
- t.__(result, expected);
12
- }`,
13
48
  't.__(__a(__b))': `{
14
- const result = __a(__b);
49
+ const result = __a(__b);
15
50
  t.__(result);
16
51
  }`,
52
+ 't.__a(__b, __c)': ({__b, __c}, path) => {
53
+ const resultBinding = getBinding(path, 'result');
54
+ const expectedBinding = getBinding(path, 'expected');
55
+
56
+ if (!resultBinding && !expectedBinding)
57
+ return `{
58
+ const result = __b;
59
+ const expected= __c;
60
+
61
+ t.__a(result, expected);
62
+ }`;
63
+
64
+ if (!expectedBinding && !isIdentifier(__c))
65
+ return `{
66
+ const expected = __c;
67
+
68
+ t.__a(__b, expected);
69
+ }`;
70
+
71
+ if (!resultBinding && !isIdentifier(__b))
72
+ return `{
73
+ const result = __b;
74
+
75
+ t.__a(result, __c);
76
+ }`;
77
+ },
17
78
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "21.7.0",
3
+ "version": "21.8.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with tests",