@putout/plugin-tape 3.3.0 → 3.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 CHANGED
@@ -30,7 +30,11 @@ npm i @putout/plugin-tape -D
30
30
  "tape/convert-emitter-to-promise": "on",
31
31
  "tape/convert-ok-to-match": "on",
32
32
  "tape/convert-ok-to-called-with": "on",
33
- "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",
36
+ "tape/remove-default-messages": "on",
37
+ "tape/remove-useless-not-called-args": "on"
34
38
  }
35
39
  }
36
40
  ```
@@ -46,7 +50,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
46
50
  });
47
51
  ```
48
52
 
49
- ### ✅ Correct code Example
53
+ ### ✅ Correct code example
50
54
 
51
55
  ```js
52
56
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -63,7 +67,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
63
67
  const test = require('tape');
64
68
  ```
65
69
 
66
- ### ✅ Correct code Example
70
+ ### ✅ Correct code example
67
71
 
68
72
  ```js
69
73
  const test = require('supertape');
@@ -82,7 +86,7 @@ test('some message', (t) => {
82
86
  });
83
87
  ```
84
88
 
85
- ### ✅ Correct code Example
89
+ ### ✅ Correct code example
86
90
 
87
91
  ```js
88
92
  const tryCatch = require('try-catch');
@@ -109,6 +113,20 @@ test('some message', (t) => {
109
113
  });
110
114
  ```
111
115
 
116
+ ### ✅ Correct code example
117
+
118
+ ```js
119
+ const test = require('supertape');
120
+ const tryCatch = require('try-catch');
121
+
122
+ test('some test', (t) => {
123
+ const [error] = tryCatch(copymitter);
124
+
125
+ t.notOk(error, 'should not throw when no args');
126
+ t.end();
127
+ });
128
+ ```
129
+
112
130
  ## convert-called-with-args
113
131
 
114
132
  ### ❌ Incorrect code example
@@ -127,7 +145,7 @@ test('some message', (t) => {
127
145
  });
128
146
  ```
129
147
 
130
- ### ✅ Correct code Example
148
+ ### ✅ Correct code example
131
149
 
132
150
  ```js
133
151
  const test = require('supertape');
@@ -143,7 +161,7 @@ test('some message', (t) => {
143
161
  });
144
162
  ```
145
163
 
146
- ### ✅ Correct code Example
164
+ ### ✅ Correct code example
147
165
 
148
166
  ```js
149
167
  const tryCatch = require('try-catch');
@@ -175,7 +193,7 @@ test('some message', (t) => {
175
193
  });
176
194
  ```
177
195
 
178
- ### ✅ Correct code Example
196
+ ### ✅ Correct code example
179
197
 
180
198
  ```js
181
199
  const test = require('supertape');
@@ -209,7 +227,7 @@ test('some message', (t) => {
209
227
  });
210
228
  ```
211
229
 
212
- ### ✅ Correct code Example
230
+ ### ✅ Correct code example
213
231
 
214
232
  ```js
215
233
  const test = require('supertape');
@@ -239,7 +257,7 @@ test('copymitter', (t) => {
239
257
  });
240
258
  ```
241
259
 
242
- ### ✅ Correct code Example
260
+ ### ✅ Correct code example
243
261
 
244
262
  ```js
245
263
  const {once} = require('events');
@@ -266,7 +284,7 @@ test('some message', (t) => {
266
284
  });
267
285
  ```
268
286
 
269
- ### ✅ Correct code Example
287
+ ### ✅ Correct code example
270
288
 
271
289
  ```js
272
290
  import tryCatch from 'try-catch';
@@ -289,7 +307,7 @@ test('some message', (t) => {
289
307
  });
290
308
  ```
291
309
 
292
- ### ✅ Correct code Example
310
+ ### ✅ Correct code example
293
311
 
294
312
  ```js
295
313
  test('some message', (t) => {
@@ -312,7 +330,7 @@ test('xxx', (t) => {
312
330
  });
313
331
  ```
314
332
 
315
- ### ✅ Correct code Example
333
+ ### ✅ Correct code example
316
334
 
317
335
  ```js
318
336
  const {test, stub} = require('supertape');
@@ -324,6 +342,24 @@ test('xxx', (t) => {
324
342
  });
325
343
  ```
326
344
 
345
+ ## declare-t
346
+
347
+ ### ❌ Incorrect code example
348
+
349
+ ```js
350
+ test('xxx', () => {
351
+ t.end();
352
+ });
353
+ ```
354
+
355
+ ### ✅ Correct code example
356
+
357
+ ```js
358
+ test('xxx', (t) => {
359
+ t.end();
360
+ });
361
+ ```
362
+
327
363
  ## convert-ok-to-match
328
364
 
329
365
  ### ❌ Incorrect code example
@@ -332,7 +368,7 @@ test('xxx', (t) => {
332
368
  t.ok(result.includes('hello'));
333
369
  ```
334
370
 
335
- ### ✅ Correct code Example
371
+ ### ✅ Correct code example
336
372
 
337
373
  ```js
338
374
  t.match(result, /hello/);
@@ -346,7 +382,7 @@ t.match(result, /hello/);
346
382
  t.ok(set.calledWith(1, 2));
347
383
  ```
348
384
 
349
- ### ✅ Correct code Example
385
+ ### ✅ Correct code example
350
386
 
351
387
  ```js
352
388
  t.calledWith(set, [1, 2]);
@@ -360,7 +396,7 @@ t.calledWith(set, [1, 2]);
360
396
  t.equal(error, null);
361
397
  ```
362
398
 
363
- ### ✅ Correct code Example
399
+ ### ✅ Correct code example
364
400
 
365
401
  ```js
366
402
  t.notOk(error);
@@ -374,7 +410,7 @@ t.notOk(error);
374
410
  t.equal(result, true);
375
411
  ```
376
412
 
377
- ### ✅ Correct code Example
413
+ ### ✅ Correct code example
378
414
 
379
415
  ```js
380
416
  t.ok(result);
@@ -388,12 +424,43 @@ t.ok(result);
388
424
  t.match(result, RegExp('hello'));
389
425
  ```
390
426
 
391
- ### ✅ Correct code Example
427
+ ### ✅ Correct code example
392
428
 
393
429
  ```js
394
430
  t.match(result, 'hello');
395
431
  ```
396
432
 
433
+ ## remove-default-messages
434
+
435
+ `supertape` will put this information for you, and it is always the same.
436
+ No need to repeat the same information twice on one line, better to avoid it.
437
+
438
+ ### ❌ Incorrect code example
439
+
440
+ ```js
441
+ t.equal(result, expected, 'should equal');
442
+ ```
443
+
444
+ ### ✅ Correct code example
445
+
446
+ ```js
447
+ t.equal(result, expected);
448
+ ```
449
+
450
+ ## remove-useless-not-called-args
451
+
452
+ ### ❌ Incorrect code example
453
+
454
+ ```js
455
+ t.notCalled(fn, []);
456
+ ```
457
+
458
+ ### ✅ Correct code example
459
+
460
+ ```js
461
+ t.notCalled(fn);
462
+ ```
463
+
397
464
  ## License
398
465
 
399
466
  MIT
@@ -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
@@ -21,5 +21,8 @@ module.exports.rules = {
21
21
  ...getRule('expand-try-catch-arguments'),
22
22
  ...getRule('apply-stub-operator'),
23
23
  ...getRule('declare-stub'),
24
+ ...getRule('declare-t'),
25
+ ...getRule('remove-default-messages'),
26
+ ...getRule('remove-useless-not-called-args'),
24
27
  };
25
28
 
@@ -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
+
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => 'Remove useless "notCalled" args';
4
+
5
+ module.exports.replace = () => ({
6
+ 't.notCalled(__a, __array)': 't.notCalled(__a)',
7
+ });
8
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "3.3.0",
3
+ "version": "3.6.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",