@putout/plugin-tape 3.2.0 → 3.5.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
@@ -22,6 +22,7 @@ npm i @putout/plugin-tape -D
22
22
  "tape/convert-tape-to-supertape": "on",
23
23
  "tape/convert-throws-to-try-catch": "on",
24
24
  "tape/convert-does-not-throw-to-try-catch": "on",
25
+ "tape/convert-called-with-args": "on",
25
26
  "tape/convert-called-with-to-called-with-no-args": "on",
26
27
  "tape/convert-called-with-no-args-to-called-with": "on",
27
28
  "tape/expand-try-catch-arguments": "on",
@@ -29,7 +30,9 @@ npm i @putout/plugin-tape -D
29
30
  "tape/convert-emitter-to-promise": "on",
30
31
  "tape/convert-ok-to-match": "on",
31
32
  "tape/convert-ok-to-called-with": "on",
32
- "tape/convert-match-regexp-to-string": "on"
33
+ "tape/convert-match-regexp-to-string": "on",
34
+ "tape/declare-stub": "on",
35
+ "tape/declare-t": "on"
33
36
  }
34
37
  }
35
38
  ```
@@ -45,7 +48,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
45
48
  });
46
49
  ```
47
50
 
48
- ### ✅ Correct code Example
51
+ ### ✅ Correct code example
49
52
 
50
53
  ```js
51
54
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -62,7 +65,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
62
65
  const test = require('tape');
63
66
  ```
64
67
 
65
- ### ✅ Correct code Example
68
+ ### ✅ Correct code example
66
69
 
67
70
  ```js
68
71
  const test = require('supertape');
@@ -81,7 +84,7 @@ test('some message', (t) => {
81
84
  });
82
85
  ```
83
86
 
84
- ### ✅ Correct code Example
87
+ ### ✅ Correct code example
85
88
 
86
89
  ```js
87
90
  const tryCatch = require('try-catch');
@@ -108,7 +111,55 @@ test('some message', (t) => {
108
111
  });
109
112
  ```
110
113
 
111
- ### ✅ Correct code Example
114
+ ### ✅ Correct code example
115
+
116
+ ```js
117
+ const test = require('supertape');
118
+ const tryCatch = require('try-catch');
119
+
120
+ test('some test', (t) => {
121
+ const [error] = tryCatch(copymitter);
122
+
123
+ t.notOk(error, 'should not throw when no args');
124
+ t.end();
125
+ });
126
+ ```
127
+
128
+ ## convert-called-with-args
129
+
130
+ ### ❌ Incorrect code example
131
+
132
+ ```js
133
+ const test = require('supertape');
134
+ const {stub} = test;
135
+
136
+ test('some message', (t) => {
137
+ const fn = stub();
138
+
139
+ fn();
140
+
141
+ t.calledWith(fn, 'hello');
142
+ t.end();
143
+ });
144
+ ```
145
+
146
+ ### ✅ Correct code example
147
+
148
+ ```js
149
+ const test = require('supertape');
150
+ const {stub} = test;
151
+
152
+ test('some message', (t) => {
153
+ const fn = stub();
154
+
155
+ fn();
156
+
157
+ t.calledWith(fn, ['hello']);
158
+ t.end();
159
+ });
160
+ ```
161
+
162
+ ### ✅ Correct code example
112
163
 
113
164
  ```js
114
165
  const tryCatch = require('try-catch');
@@ -117,7 +168,7 @@ const test = require('supertape');
117
168
  test('some message', (t) => {
118
169
  const [error] = tryCatch(copymitter);
119
170
 
120
- t.nottOk(error, 'should throw when no args');
171
+ t.notOk(error, 'should throw when no args');
121
172
  t.end();
122
173
  });
123
174
  ```
@@ -140,7 +191,7 @@ test('some message', (t) => {
140
191
  });
141
192
  ```
142
193
 
143
- ### ✅ Correct code Example
194
+ ### ✅ Correct code example
144
195
 
145
196
  ```js
146
197
  const test = require('supertape');
@@ -174,7 +225,7 @@ test('some message', (t) => {
174
225
  });
175
226
  ```
176
227
 
177
- ### ✅ Correct code Example
228
+ ### ✅ Correct code example
178
229
 
179
230
  ```js
180
231
  const test = require('supertape');
@@ -204,7 +255,7 @@ test('copymitter', (t) => {
204
255
  });
205
256
  ```
206
257
 
207
- ### ✅ Correct code Example
258
+ ### ✅ Correct code example
208
259
 
209
260
  ```js
210
261
  const {once} = require('events');
@@ -231,7 +282,7 @@ test('some message', (t) => {
231
282
  });
232
283
  ```
233
284
 
234
- ### ✅ Correct code Example
285
+ ### ✅ Correct code example
235
286
 
236
287
  ```js
237
288
  import tryCatch from 'try-catch';
@@ -254,7 +305,7 @@ test('some message', (t) => {
254
305
  });
255
306
  ```
256
307
 
257
- ### ✅ Correct code Example
308
+ ### ✅ Correct code example
258
309
 
259
310
  ```js
260
311
  test('some message', (t) => {
@@ -277,7 +328,7 @@ test('xxx', (t) => {
277
328
  });
278
329
  ```
279
330
 
280
- ### ✅ Correct code Example
331
+ ### ✅ Correct code example
281
332
 
282
333
  ```js
283
334
  const {test, stub} = require('supertape');
@@ -289,6 +340,24 @@ test('xxx', (t) => {
289
340
  });
290
341
  ```
291
342
 
343
+ ## declare-t
344
+
345
+ ### ❌ Incorrect code example
346
+
347
+ ```js
348
+ test('xxx', () => {
349
+ t.end();
350
+ });
351
+ ```
352
+
353
+ ### ✅ Correct code example
354
+
355
+ ```js
356
+ test('xxx', (t) => {
357
+ t.end();
358
+ });
359
+ ```
360
+
292
361
  ## convert-ok-to-match
293
362
 
294
363
  ### ❌ Incorrect code example
@@ -297,7 +366,7 @@ test('xxx', (t) => {
297
366
  t.ok(result.includes('hello'));
298
367
  ```
299
368
 
300
- ### ✅ Correct code Example
369
+ ### ✅ Correct code example
301
370
 
302
371
  ```js
303
372
  t.match(result, /hello/);
@@ -311,7 +380,7 @@ t.match(result, /hello/);
311
380
  t.ok(set.calledWith(1, 2));
312
381
  ```
313
382
 
314
- ### ✅ Correct code Example
383
+ ### ✅ Correct code example
315
384
 
316
385
  ```js
317
386
  t.calledWith(set, [1, 2]);
@@ -325,7 +394,7 @@ t.calledWith(set, [1, 2]);
325
394
  t.equal(error, null);
326
395
  ```
327
396
 
328
- ### ✅ Correct code Example
397
+ ### ✅ Correct code example
329
398
 
330
399
  ```js
331
400
  t.notOk(error);
@@ -339,7 +408,7 @@ t.notOk(error);
339
408
  t.equal(result, true);
340
409
  ```
341
410
 
342
- ### ✅ Correct code Example
411
+ ### ✅ Correct code example
343
412
 
344
413
  ```js
345
414
  t.ok(result);
@@ -353,12 +422,29 @@ t.ok(result);
353
422
  t.match(result, RegExp('hello'));
354
423
  ```
355
424
 
356
- ### ✅ Correct code Example
425
+ ### ✅ Correct code example
357
426
 
358
427
  ```js
359
428
  t.match(result, 'hello');
360
429
  ```
361
430
 
431
+ ## remove-default-messages
432
+
433
+ `supertape` will put this information for you, and it is always the same.
434
+ No need to repeat the same information twice on one line, better to avoid it.
435
+
436
+ ### ❌ Incorrect code example
437
+
438
+ ```js
439
+ t.equal(result, expected, 'should equal');
440
+ ```
441
+
442
+ ### ✅ Correct code example
443
+
444
+ ```js
445
+ t.equal(result, expected);
446
+ ```
447
+
362
448
  ## License
363
449
 
364
450
  MIT
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+ const {
5
+ isIdentifier,
6
+ isArrayExpression,
7
+ } = types;
8
+
9
+ module.exports.report = () => `Use 'array' as calledWith 'args'`;
10
+
11
+ module.exports.match = () => ({
12
+ 't.calledWith(__a, __b)': ({__b}) => {
13
+ if (isIdentifier(__b))
14
+ return false;
15
+
16
+ if (isArrayExpression(__b))
17
+ return false;
18
+
19
+ return true;
20
+ },
21
+ });
22
+
23
+ module.exports.replace = () => ({
24
+ 't.calledWith(__a, __b)': 't.calledWith(__a, [__b])',
25
+ });
@@ -5,5 +5,8 @@ module.exports.report = () => '"calledWithArgs" should be used when arguments ar
5
5
  module.exports.replace = () => ({
6
6
  't.calledWithNoArgs(__a, __array)': 't.calledWith(__a, __array)',
7
7
  't.calledWithNoArgs(__a, __array, __b)': 't.calledWith(__a, __array, __b)',
8
+
9
+ 't.calledWithNoArgs(__a, __identifier)': 't.calledWith(__a, __identifier)',
10
+ 't.calledWithNoArgs(__a, __identifier, __b)': 't.calledWith(__a, __identifier, __b)',
8
11
  });
9
12
 
@@ -11,16 +11,22 @@ module.exports.match = () => ({
11
11
  't.match(__a, RegExp(__b), __c)': checkStr,
12
12
  't.match(__a, /__b/)': checkRegExp,
13
13
  't.match(__a, /__b/, __c)': checkRegExp,
14
+
15
+ 't.notMatch(__a, RegExp(__b))': checkStr,
16
+ 't.notMatch(__a, RegExp(__b), __c)': checkStr,
17
+ 't.notMatch(__a, /__b/)': checkRegExp,
18
+ 't.notMatch(__a, /__b/, __c)': checkRegExp,
14
19
  });
15
20
 
16
21
  module.exports.replace = () => ({
17
22
  't.match(__a, RegExp(__b))': 't.match(__a, __b)',
18
23
  't.match(__a, RegExp(__b), __c)': 't.match(__a, __b, __c)',
19
- 't.match(__a, /__b/)': ({__b}) => {
20
- return `t.match(__a, '${__b.pattern}')`;
21
- },
22
- 't.match(__a, /__b/, __c)': ({__b}) => {
23
- return `t.match(__a, '${__b.pattern}', __c)`;
24
- },
24
+ 't.match(__a, /__b/)': ({__b}) => `t.match(__a, '${__b.pattern}')`,
25
+ 't.match(__a, /__b/, __c)': ({__b}) => `t.match(__a, '${__b.pattern}', __c)`,
26
+
27
+ 't.notMatch(__a, RegExp(__b))': 't.notMatch(__a, __b)',
28
+ 't.notMatch(__a, RegExp(__b), __c)': 't.notMatch(__a, __b, __c)',
29
+ 't.notMatch(__a, /__b/)': ({__b}) => `t.notMatch(__a, '${__b.pattern}')`,
30
+ 't.notMatch(__a, /__b/, __c)': ({__b}) => `t.notMatch(__a, '${__b.pattern}', __c)`,
25
31
  });
26
32
 
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+ const {Identifier} = types;
5
+
6
+ module.exports.report = () => 'Argument "t" is missing';
7
+
8
+ module.exports.fix = (path) => {
9
+ path.scope.block.params = [Identifier('t')];
10
+ };
11
+
12
+ module.exports.traverse = ({push}) => ({
13
+ 't.end()': (path) => {
14
+ if (path.scope.bindings.t)
15
+ return;
16
+
17
+ push(path);
18
+ },
19
+ });
package/lib/index.js CHANGED
@@ -10,6 +10,7 @@ module.exports.rules = {
10
10
  ...getRule('convert-throws-to-try-catch'),
11
11
  ...getRule('convert-does-not-throw-to-try-catch'),
12
12
  ...getRule('convert-called-with-to-called-with-no-args'),
13
+ ...getRule('convert-called-with-args'),
13
14
  ...getRule('convert-called-with-no-args-to-called-with'),
14
15
  ...getRule('convert-emitter-to-promise'),
15
16
  ...getRule('convert-ok-to-match'),
@@ -20,5 +21,7 @@ module.exports.rules = {
20
21
  ...getRule('expand-try-catch-arguments'),
21
22
  ...getRule('apply-stub-operator'),
22
23
  ...getRule('declare-stub'),
24
+ ...getRule('declare-t'),
25
+ ...getRule('remove-default-messages'),
23
26
  };
24
27
 
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => 'Avoid passing default messages to operators';
4
+
5
+ module.exports.replace = () => ({
6
+ 't.ok(__a, "should be truthy")': 't.ok(__a)',
7
+ 't.notOk(__a, "should be falsy")': 't.notOk(__a)',
8
+ 't.match(__a, __b, "should match")': 't.match(__a, __b)',
9
+ 't.notMatch(__a, __b, "should not match")': 't.notMatch(__a, __b)',
10
+ 't.equal(__a, __b, "should equal")': 't.equal(__a, __b)',
11
+ 't.notEqual(__a, __b, "should not equal")': 't.notEqual(__a, __b)',
12
+ 't.deepEqual(__a, __b, "should deep equal")': 't.deepEqual(__a, __b)',
13
+ 't.notDeepEqual(__a, __b, "should not deep equal")': 't.notDeepEqual(__a, __b)',
14
+ });
15
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "3.2.0",
3
+ "version": "3.5.0",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "putout plugin helps with tests",
6
6
  "homepage": "http://github.com/coderaiser/putout",
@@ -36,7 +36,7 @@
36
36
  "c8": "^7.5.0",
37
37
  "eslint": "^8.0.0-beta.0",
38
38
  "eslint-plugin-node": "^11.0.0",
39
- "eslint-plugin-putout": "^9.0.0",
39
+ "eslint-plugin-putout": "^10.0.0",
40
40
  "lerna": "^4.0.0",
41
41
  "madrun": "^8.0.1",
42
42
  "nodemon": "^2.0.1"