@putout/plugin-tape 21.2.0 → 21.4.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,6 +39,7 @@ 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);
@@ -77,6 +78,7 @@ npm i @putout/plugin-tape -D
77
78
  "tape/convert-match-regexp-to-string": "on",
78
79
  "tape/add-args": "on",
79
80
  "tape/declare": "on",
81
+ "tape/extract-args-from-called-with": "on",
80
82
  "tape/remove-default-messages": "on",
81
83
  "tape/remove-useless-not-called-args": "on",
82
84
  "tape/remove-only": ["on", {
@@ -486,6 +488,36 @@ test('should call init before show', (t) => {
486
488
  });
487
489
  ```
488
490
 
491
+ ## extract-args-from-called-with
492
+
493
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/1a4b8e28b15ada7c7ad17e544ae03e2a/c6ca31508b8d4f2572d6a0c65dfbfe28c53016b1).
494
+
495
+ ### ❌ Example of incorrect code
496
+
497
+ ```js
498
+ test('abc: def', (t) => {
499
+ t.calledWith(executeFn, [
500
+ ['tape', 'test.js'], {
501
+ exit,
502
+ },
503
+ ]);
504
+ });
505
+ ```
506
+
507
+ ### ✅ Example of correct code
508
+
509
+ ```js
510
+ test('abc: def', (t) => {
511
+ const args = [
512
+ ['tape', 'test.js'], {
513
+ exit,
514
+ },
515
+ ];
516
+
517
+ t.calledWith(executeFn, args);
518
+ });
519
+ ```
520
+
489
521
  ## declare
490
522
 
491
523
  ### ❌ Example of incorrect code
@@ -1,17 +1,21 @@
1
1
  import {template, operator} from 'putout';
2
2
 
3
- const {insertBefore} = operator;
3
+ const {
4
+ insertBefore,
5
+ getStringFromRegExp,
6
+ } = operator;
4
7
 
5
8
  export const report = () => 'try-catch should be used instead of t.throws';
6
9
 
7
10
  export const replace = () => ({
8
11
  't.throws(__a, __b)': ({__a}, path) => {
9
12
  putTryCatch(__a, path);
10
- return `t.ok(error, __b)`;
13
+ return '';
11
14
  },
12
15
  't.throws(__a, __b, __c)': ({__a, __b}, path) => {
13
16
  putTryCatch(__a, path);
14
- return `t.equal(error.message, '${__b.pattern}', __c)`;
17
+
18
+ return `t.equal(error.message, '${getStringFromRegExp(__b)}', __c)`;
15
19
  },
16
20
  });
17
21
 
@@ -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,4 @@
1
+ import * as extractArgsFromCalledWith from './extract-args-from-called-with/index.js';
1
2
  import * as applyStub from './apply-stub/index.js';
2
3
  import * as applyDestructuring from './apply-destructuring/index.js';
3
4
  import * as applyWithName from './apply-with-name/index.js';
@@ -62,4 +63,5 @@ export const rules = {
62
63
  'remove-useless-t-end': removeUselessTEnd,
63
64
  'remove-only': removeOnly,
64
65
  'remove-skip': removeSkip,
66
+ 'extract-args-from-called-with': extractArgsFromCalledWith,
65
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "21.2.0",
3
+ "version": "21.4.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",