@putout/plugin-tape 3.7.0 → 3.10.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
@@ -20,6 +20,9 @@ npm i @putout/plugin-tape -D
20
20
  "rules": {
21
21
  "tape/apply-stub-operator": "on",
22
22
  "tape/apply-with-name": "on",
23
+ "tape/add-t-end": "on",
24
+ "tape/remove-useless-t-end": "on",
25
+ "tape/sync-with-name": "on",
23
26
  "tape/switch-expected-with-result": "on",
24
27
  "tape/convert-tape-to-supertape": "on",
25
28
  "tape/convert-throws-to-try-catch": "on",
@@ -343,6 +346,31 @@ test('should call init before show', (t) => {
343
346
  });
344
347
  ```
345
348
 
349
+ ## sync-with-name
350
+
351
+ ### ❌ Incorrect code example
352
+
353
+ ```js
354
+ test('should call init before show', (t) => {
355
+ const init = stub().withName('show');
356
+ const show = stub().withName('show');
357
+
358
+ t.calledInOrder([init, show]);
359
+ t.end();
360
+ });
361
+ ```
362
+
363
+ ### ✅ Correct code example
364
+
365
+ ```js
366
+ test('should call init before show', (t) => {
367
+ const init = stub().withName('init');
368
+ const show = stub().withName('show');
369
+
370
+ t.calledInOrder([init, show]);
371
+ t.end();
372
+ });
373
+ ```
346
374
 
347
375
  ## declare-stub
348
376
 
@@ -388,6 +416,42 @@ test('xxx', (t) => {
388
416
  });
389
417
  ```
390
418
 
419
+ ## add-t-end
420
+
421
+ ### ❌ Incorrect code example
422
+
423
+ ```js
424
+ test('xxx', () => {
425
+ });
426
+ ```
427
+
428
+ ### ✅ Correct code example
429
+
430
+ ```js
431
+ test('xxx', (t) => {
432
+ t.end();
433
+ });
434
+ ```
435
+
436
+ ## remove-useless-t-end
437
+
438
+ ### ❌ Incorrect code example
439
+
440
+ ```js
441
+ test('test: remove me', () => {
442
+ t.end();
443
+ t.end();
444
+ });
445
+ ```
446
+
447
+ ### ✅ Correct code example
448
+
449
+ ```js
450
+ test('test: remove me', () => {
451
+ t.end();
452
+ });
453
+ ```
454
+
391
455
  ## convert-ok-to-match
392
456
 
393
457
  ### ❌ Incorrect code example
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ types,
5
+ template,
6
+ operator,
7
+ } = require('putout');
8
+ const {compare} = operator;
9
+ const {ExpressionStatement} = types;
10
+
11
+ module.exports.report = () => `'t.end()' is missing at the end of the test`;
12
+
13
+ module.exports.match = () => ({
14
+ 'test(__a, (t) => __body)': ({__body}) => {
15
+ const {body} = __body;
16
+ const {length} = body;
17
+
18
+ if (!length)
19
+ return true;
20
+
21
+ return !compare(body[length - 1], 't.end()');
22
+ },
23
+ });
24
+
25
+ module.exports.replace = () => ({
26
+ 'test(__a, (t) => __body)': ({__body}, path) => {
27
+ __body.body.push(ExpressionStatement(template.ast('t.end()')));
28
+ return path;
29
+ },
30
+ });
@@ -55,7 +55,12 @@ function applyWithNameToArray({__array}, path) {
55
55
  function checkStub(node, path) {
56
56
  const {bindings} = path.scope;
57
57
  const {name} = node;
58
- const initPath = bindings[name].path.get('init');
58
+ const binding = bindings[name];
59
+
60
+ if (!binding)
61
+ return false;
62
+
63
+ const initPath = binding.path.get('init');
59
64
  const calleePath = initPath.get('callee');
60
65
 
61
66
  return !calleePath.isMemberExpression();
@@ -64,7 +69,12 @@ function checkStub(node, path) {
64
69
  function applyWithNameToNode(node, path) {
65
70
  const {bindings} = path.scope;
66
71
  const {name} = node;
67
- const initPath = bindings[name].path.get('init');
72
+ const binding = bindings[name];
73
+
74
+ if (!binding)
75
+ return;
76
+
77
+ const initPath = binding.path.get('init');
68
78
  const calleePath = initPath.get('callee');
69
79
 
70
80
  if (calleePath.isMemberExpression())
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ const getRule = (a) => ({
6
6
 
7
7
  module.exports.rules = {
8
8
  ...getRule('apply-with-name'),
9
+ ...getRule('sync-with-name'),
9
10
  ...getRule('convert-tape-to-supertape'),
10
11
  ...getRule('convert-throws-to-try-catch'),
11
12
  ...getRule('convert-does-not-throw-to-try-catch'),
@@ -25,5 +26,7 @@ module.exports.rules = {
25
26
  ...getRule('remove-useless-not-called-args'),
26
27
  ...getRule('switch-expected-with-result'),
27
28
  ...getRule('apply-stub-operator'),
29
+ ...getRule('add-t-end'),
30
+ ...getRule('remove-useless-t-end'),
28
31
  };
29
32
 
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+
5
+ const {traverse} = operator;
6
+
7
+ module.exports.report = () => `Avoid useless 't.end()'`;
8
+
9
+ module.exports.fix = (path) => {
10
+ path.remove();
11
+ };
12
+
13
+ const TEST = 'test("__a", (t) => __body)';
14
+
15
+ module.exports.traverse = ({push}) => ({
16
+ [TEST]: (path) => {
17
+ const paths = [];
18
+
19
+ traverse(path, {
20
+ 't.end()': (path) => {
21
+ paths.push(path);
22
+ },
23
+ });
24
+
25
+ if (paths.length > 1)
26
+ push(paths.pop());
27
+ },
28
+ });
29
+
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `'stub().withName(name)' should synced with variable name`;
4
+
5
+ module.exports.match = () => ({
6
+ 'const __a = stub().withName(__b)': ({__a, __b}) => __b.value !== __a.name,
7
+ });
8
+
9
+ module.exports.replace = () => ({
10
+ 'const __a = stub().withName(__b)': ({__a, __b}, path) => {
11
+ __b.value = __a.name;
12
+ return path;
13
+ },
14
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "3.7.0",
3
+ "version": "3.10.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",
@@ -39,6 +39,7 @@
39
39
  "eslint-plugin-putout": "^10.0.0",
40
40
  "lerna": "^4.0.0",
41
41
  "madrun": "^8.0.1",
42
+ "montag": "^1.2.1",
42
43
  "nodemon": "^2.0.1"
43
44
  },
44
45
  "peerDependencies": {