@putout/plugin-tape 21.9.1 → 21.11.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
@@ -42,6 +42,7 @@ npm i @putout/plugin-tape -D
42
42
  - ✅ [convert-throws-to-try-catch](#convert-throws-to-try-catch);
43
43
  - ✅ [declare](#declare);
44
44
  - ✅ [extract-args-from-called-with](#extract-args-from-called-with);
45
+ - ✅ [extract-result-from-assertion](#extract-result-from-assertion);
45
46
  - ✅ [jest](#jest);
46
47
  - ✅ [remove-default-messages](#remove-default-messages);
47
48
  - ✅ [remove-only](#remove-only);
@@ -49,9 +50,9 @@ npm i @putout/plugin-tape -D
49
50
  - ✅ [remove-useless-not-called-args](#remove-useless-not-called-args);
50
51
  - ✅ [remove-useless-t-end](#remove-useless-t-end);
51
52
  - ✅ [remove-useless-undefined](#remove-useless-undefined);
53
+ - ✅ [remove-t-from-async](#remove-t-from-async);
52
54
  - ✅ [switch-expected-with-result](#switch-expected-with-result);
53
55
  - ✅ [sync-with-name](#sync-with-name);
54
- - ✅ [move-out-result-from-assertion](#move-out-result-from-assertion);
55
56
 
56
57
  ## Config
57
58
 
@@ -88,13 +89,14 @@ npm i @putout/plugin-tape -D
88
89
  "tape/remove-default-messages": "on",
89
90
  "tape/remove-useless-not-called-args": "on",
90
91
  "tape/remove-useless-undefined": "on",
92
+ "tape/remove-t-from-async": "on",
91
93
  "tape/remove-only": ["on", {
92
94
  "allowed": ["test"]
93
95
  }],
94
96
  "tape/remove-skip": ["on", {
95
97
  "allowed": ["test"]
96
98
  }],
97
- "tape/move-out-result-from-assertion": "on"
99
+ "tape/extract-result-from-assertion": "on"
98
100
  }
99
101
  }
100
102
  ```
@@ -640,6 +642,38 @@ test('test: remove me', () => {
640
642
  });
641
643
  ```
642
644
 
645
+ ## remove-t-from-async
646
+
647
+ ### ❌ Example of incorrect code
648
+
649
+ ```js
650
+ test('sqlite: all returns empty array', async (t) => {
651
+ const db = await createDb();
652
+ await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
653
+ const rows = await db.all('SELECT x FROM t WHERE x = :x', {
654
+ x: 'missing',
655
+ });
656
+
657
+ await t.dbAll(rows, []);
658
+
659
+ t.end();
660
+ });
661
+ ```
662
+
663
+ ### ✅ Example of correct code
664
+
665
+ ```js
666
+ test('sqlite: all returns empty array', async ({dbAll}) => {
667
+ const db = await createDb();
668
+ await db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, x TEXT)');
669
+ const rows = await db.all('SELECT x FROM t WHERE x = :x', {
670
+ x: 'missing',
671
+ });
672
+
673
+ await dbAll(rows, []);
674
+ });
675
+ ```
676
+
643
677
  ## remove-useless-undefined
644
678
 
645
679
  ### ❌ Example of incorrect code
@@ -841,7 +875,7 @@ test('some test', (t) => {
841
875
  });
842
876
  ```
843
877
 
844
- ## move-out-result-from-assertion
878
+ ## extract-result-from-assertion
845
879
 
846
880
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/264bc87f56eae9aa2b2884ff64fe7a06/94836a115a072a18fd717d5454792c1895ab0476).
847
881
 
@@ -7,9 +7,10 @@ const {
7
7
  isMemberExpression,
8
8
  isOptionalMemberExpression,
9
9
  isObjectExpression,
10
+ isArrayExpression,
10
11
  } = types;
11
12
 
12
- export const report = () => `Move out result from assertion`;
13
+ export const report = () => `Extract result from assertion`;
13
14
  export const match = () => ({
14
15
  't.__(__a(__b))': (vars, path) => !getBinding(path, 'result'),
15
16
  't.__a(__b, __c)': ({__a, __b, __c}, path) => {
@@ -37,6 +38,9 @@ export const match = () => ({
37
38
  if (expectedBinding)
38
39
  return false;
39
40
 
41
+ if (isArrayExpression(__c))
42
+ return true;
43
+
40
44
  return isObjectExpression(__c);
41
45
  },
42
46
  });
package/lib/index.js CHANGED
@@ -1,8 +1,9 @@
1
+ import * as removeTFromAsync from './remove-t-from-async/index.js';
1
2
  import * as applyStringify from './apply-stringify/index.js';
2
- import * as movOutResultFromAssertion from './move-out-result-from-assertion/index.js';
3
3
  import * as applyAssertionsOrder from './apply-assertions-order/index.js';
4
- import * as removeUselessUndefined from './remove-useless-undefined/index.js';
5
4
  import * as extractArgsFromCalledWith from './extract-args-from-called-with/index.js';
5
+ import * as extractResultFromAssertion from './extract-result-from-assertion/index.js';
6
+ import * as removeUselessUndefined from './remove-useless-undefined/index.js';
6
7
  import * as applyStub from './apply-stub/index.js';
7
8
  import * as applyDestructuring from './apply-destructuring/index.js';
8
9
  import * as applyWithName from './apply-with-name/index.js';
@@ -68,8 +69,9 @@ export const rules = {
68
69
  'remove-only': removeOnly,
69
70
  'remove-skip': removeSkip,
70
71
  'extract-args-from-called-with': extractArgsFromCalledWith,
72
+ 'extract-result-from-assertion': extractResultFromAssertion,
71
73
  'remove-useless-undefined': removeUselessUndefined,
72
74
  'apply-assertions-order': applyAssertionsOrder,
73
- 'move-out-result-from-assertion': movOutResultFromAssertion,
74
75
  'apply-stringify': applyStringify,
76
+ 'remove-t-from-async': removeTFromAsync,
75
77
  };
@@ -0,0 +1,22 @@
1
+ import {types, operator} from 'putout';
2
+
3
+ const {remove} = operator;
4
+ const {objectProperty, objectPattern} = types;
5
+
6
+ export const report = () => `Use 'if condition' instead of 'ternary expression'`;
7
+
8
+ export const replace = () => ({
9
+ 'await t.__a(__args)': ({__a}, path) => {
10
+ const next = path.parentPath.getNextSibling();
11
+
12
+ path.scope.block.params = [
13
+ objectPattern([
14
+ objectProperty(__a, __a),
15
+ ]),
16
+ ];
17
+
18
+ remove(next);
19
+
20
+ return 'await __a(__args)';
21
+ },
22
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "21.9.1",
3
+ "version": "21.11.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",