@putout/plugin-tape 21.3.0 → 21.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
@@ -39,12 +39,14 @@ npm i @putout/plugin-tape -D
39
39
  - ✅ [convert-tape-to-supertape](#convert-tape-to-supertape);
40
40
  - ✅ [convert-throws-to-try-catch](#convert-throws-to-try-catch);
41
41
  - ✅ [declare](#declare);
42
+ - ✅ [extract-args-from-called-with](#extract-args-from-called-with);
42
43
  - ✅ [jest](#jest);
43
44
  - ✅ [remove-default-messages](#remove-default-messages);
44
45
  - ✅ [remove-only](#remove-only);
45
46
  - ✅ [remove-skip](#remove-skip);
46
47
  - ✅ [remove-useless-not-called-args](#remove-useless-not-called-args);
47
48
  - ✅ [remove-useless-t-end](#remove-useless-t-end);
49
+ - ✅ [remove-useless-undefined](#remove-useless-undefined);
48
50
  - ✅ [switch-expected-with-result](#switch-expected-with-result);
49
51
  - ✅ [sync-with-name](#sync-with-name);
50
52
 
@@ -77,8 +79,10 @@ npm i @putout/plugin-tape -D
77
79
  "tape/convert-match-regexp-to-string": "on",
78
80
  "tape/add-args": "on",
79
81
  "tape/declare": "on",
82
+ "tape/extract-args-from-called-with": "on",
80
83
  "tape/remove-default-messages": "on",
81
84
  "tape/remove-useless-not-called-args": "on",
85
+ "tape/remove-useless-undefined": "on",
82
86
  "tape/remove-only": ["on", {
83
87
  "allowed": ["test"]
84
88
  }],
@@ -486,6 +490,36 @@ test('should call init before show', (t) => {
486
490
  });
487
491
  ```
488
492
 
493
+ ## extract-args-from-called-with
494
+
495
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/1a4b8e28b15ada7c7ad17e544ae03e2a/c6ca31508b8d4f2572d6a0c65dfbfe28c53016b1).
496
+
497
+ ### ❌ Example of incorrect code
498
+
499
+ ```js
500
+ test('abc: def', (t) => {
501
+ t.calledWith(executeFn, [
502
+ ['tape', 'test.js'], {
503
+ exit,
504
+ },
505
+ ]);
506
+ });
507
+ ```
508
+
509
+ ### ✅ Example of correct code
510
+
511
+ ```js
512
+ test('abc: def', (t) => {
513
+ const args = [
514
+ ['tape', 'test.js'], {
515
+ exit,
516
+ },
517
+ ];
518
+
519
+ t.calledWith(executeFn, args);
520
+ });
521
+ ```
522
+
489
523
  ## declare
490
524
 
491
525
  ### ❌ Example of incorrect code
@@ -561,6 +595,22 @@ test('test: remove me', () => {
561
595
  });
562
596
  ```
563
597
 
598
+ ## remove-useless-undefined
599
+
600
+ ### ❌ Example of incorrect code
601
+
602
+ ```js
603
+ stub().returns(undefined);
604
+ stub().resolves(undefined);
605
+ ```
606
+
607
+ ### ✅ Example of correct code
608
+
609
+ ```js
610
+ stub();
611
+ stub().resolves();
612
+ ```
613
+
564
614
  ## convert-ok-to-match
565
615
 
566
616
  ### ❌ Example of incorrect code
@@ -0,0 +1,48 @@
1
+ import {types, operator} from 'putout';
2
+
3
+ const {
4
+ isArrayExpression,
5
+ isObjectExpression,
6
+ variableDeclarator,
7
+ variableDeclaration,
8
+ identifier,
9
+ } = types;
10
+
11
+ const {insertBefore} = operator;
12
+
13
+ export const report = () => `Extract 'args' from 't.calledWith()'`;
14
+
15
+ export const fix = (path) => {
16
+ const id = identifier('args');
17
+ const init = path.node.arguments.pop();
18
+
19
+ path.node.arguments.push(id);
20
+
21
+ insertBefore(path.parentPath, variableDeclaration('const', [
22
+ variableDeclarator(id, init),
23
+ ]));
24
+ };
25
+
26
+ export const traverse = ({push}) => ({
27
+ 't.calledWith(__a, __b)': (path) => {
28
+ if (path.scope.bindings.args)
29
+ return;
30
+
31
+ const [, args] = path.node.arguments;
32
+
33
+ if (!isArrayExpression(args))
34
+ return;
35
+
36
+ for (const element of args.elements) {
37
+ if (isObjectExpression(element)) {
38
+ push(path);
39
+ return;
40
+ }
41
+
42
+ if (isArrayExpression(element)) {
43
+ push(path);
44
+ return;
45
+ }
46
+ }
47
+ },
48
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import * as removeUselessUndefined from './remove-useless-undefined/index.js';
2
+ import * as extractArgsFromCalledWith from './extract-args-from-called-with/index.js';
1
3
  import * as applyStub from './apply-stub/index.js';
2
4
  import * as applyDestructuring from './apply-destructuring/index.js';
3
5
  import * as applyWithName from './apply-with-name/index.js';
@@ -62,4 +64,6 @@ export const rules = {
62
64
  'remove-useless-t-end': removeUselessTEnd,
63
65
  'remove-only': removeOnly,
64
66
  'remove-skip': removeSkip,
67
+ 'extract-args-from-called-with': extractArgsFromCalledWith,
68
+ 'remove-useless-undefined': removeUselessUndefined,
65
69
  };
@@ -0,0 +1,6 @@
1
+ export const report = () => `Avoid useless 'returns/resolves(undefined)'`;
2
+
3
+ export const replace = () => ({
4
+ 'stub().returns(undefined)': 'stub()',
5
+ 'stub().resolves(undefined)': 'stub().resolves()',
6
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "21.3.0",
3
+ "version": "21.5.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",
@@ -33,7 +33,6 @@
33
33
  "@putout/plugin-putout": "*",
34
34
  "@putout/test": "^15.0.0",
35
35
  "eslint": "^10.0.0",
36
- "eslint-plugin-n": "^17.0.0",
37
36
  "eslint-plugin-putout": "^31.0.0",
38
37
  "madrun": "^13.0.0",
39
38
  "montag": "^2.0.0",