@putout/plugin-tape 21.17.1 → 21.19.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
@@ -17,6 +17,7 @@ npm i @putout/plugin-tape -D
17
17
 
18
18
  ## Rules
19
19
 
20
+ - ✅ [convert-ok-to-pass](#convert-ok-to-pass)
20
21
  - ✅ [add-args](#add-args);
21
22
  - ✅ [add-t-end](#add-t-end);
22
23
  - ✅ [apply-assertions-order](#apply-assertions-order);
@@ -98,7 +99,8 @@ npm i @putout/plugin-tape -D
98
99
  "tape/remove-skip": ["on", {
99
100
  "allowed": ["test"]
100
101
  }],
101
- "tape/extract-result-from-assertion": "on"
102
+ "tape/extract-result-from-assertion": "on",
103
+ "tape/convert-ok-to-pass": "on"
102
104
  }
103
105
  }
104
106
  ```
@@ -946,6 +948,22 @@ test('hello: world', (t) => {
946
948
  });
947
949
  ```
948
950
 
951
+ ## convert-ok-to-pass
952
+
953
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/33a05ac444d013db10fc5a1986b6ac49/f1bc8eda628a5ce5dc6ad5ee20e796b727e40083).
954
+
955
+ ### ❌ Example of incorrect code
956
+
957
+ ```js
958
+ t.ok(true);
959
+ ```
960
+
961
+ ### ✅ Example of correct code
962
+
963
+ ```js
964
+ t.pass();
965
+ ```
966
+
949
967
  ## License
950
968
 
951
969
  MIT
@@ -14,15 +14,15 @@ const printNode = (a) => print(a, {
14
14
  }],
15
15
  });
16
16
 
17
- export const report = ({prev, prevPrev}) => {
18
- return `Use '${printNode(prev)}' before '${printNode(prevPrev)}'`;
17
+ export const report = ({prev, assertion}) => {
18
+ return `Use '${printNode(prev)}' before '${printNode(assertion)}'`;
19
19
  };
20
20
 
21
- export const fix = ({prev, prevPrev}) => {
21
+ export const fix = ({prev, assertion}) => {
22
22
  const prevNode = prev.node;
23
23
 
24
24
  remove(prev);
25
- insertBefore(prevPrev, prevNode);
25
+ insertBefore(assertion, prevNode);
26
26
  };
27
27
 
28
28
  export const traverse = ({push}) => ({
@@ -35,15 +35,27 @@ export const traverse = ({push}) => ({
35
35
  if (compare(prev, 't.__a(__args)'))
36
36
  return;
37
37
 
38
- const prevPrev = prev.getPrevSibling();
38
+ const assertion = findAssertion(prev);
39
39
 
40
- if (!compare(prevPrev, 't.__a(__args)'))
40
+ if (!assertion)
41
41
  return;
42
42
 
43
43
  push({
44
44
  path,
45
45
  prev,
46
- prevPrev,
46
+ assertion,
47
47
  });
48
48
  },
49
49
  });
50
+
51
+ function findAssertion(path) {
52
+ const prev = path.getPrevSibling();
53
+
54
+ if (compare(prev, 't.__a(__args)'))
55
+ return prev;
56
+
57
+ if (!prev.node)
58
+ return null;
59
+
60
+ return findAssertion(prev);
61
+ }
@@ -0,0 +1,5 @@
1
+ export const report = () => `Use 't.pass()' instead of 't.ok()'`;
2
+
3
+ export const replace = () => ({
4
+ 't.ok(true)': 't.pass()',
5
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as convertOkToPass from './convert-ok-to-pass/index.js';
1
2
  import * as convertEqualLengthToMatchString from './convert-equal-length-to-match-string/index.js';
2
3
  import * as removeTFromAsync from './remove-t-from-async/index.js';
3
4
  import * as applyStringify from './apply-stringify/index.js';
@@ -76,4 +77,5 @@ export const rules = {
76
77
  'apply-stringify': applyStringify,
77
78
  'remove-t-from-async': removeTFromAsync,
78
79
  'convert-equal-length-to-match-string': convertEqualLengthToMatchString,
80
+ 'convert-ok-to-pass': convertOkToPass,
79
81
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "21.17.1",
3
+ "version": "21.19.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",