@putout/plugin-tape 9.9.0 → 9.11.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.
@@ -26,12 +26,14 @@ function checkStubs({__a, __b}, path) {
26
26
  const __array = {
27
27
  elements,
28
28
  };
29
+
29
30
  return checkStubsArray({__array}, path);
30
31
  }
31
32
 
32
33
  function applyWithName({__a, __b}, path) {
33
34
  applyWithNameToNode(__a, path);
34
35
  applyWithNameToNode(__b, path);
36
+
35
37
  return path;
36
38
  }
37
39
 
@@ -6,7 +6,7 @@ const {
6
6
  isArrayExpression,
7
7
  } = types;
8
8
 
9
- module.exports.report = () => `Use 'array' as calledWith 'args'`;
9
+ module.exports.report = () => `Use an array as args to 'calledWith()'`;
10
10
 
11
11
  module.exports.match = () => ({
12
12
  't.calledWith(__a, __b)': ({__b}) => {
@@ -23,3 +23,4 @@ module.exports.match = () => ({
23
23
  module.exports.replace = () => ({
24
24
  't.calledWith(__a, __b)': 't.calledWith(__a, [__b])',
25
25
  });
26
+
@@ -1,6 +1,15 @@
1
1
  'use strict';
2
2
 
3
- const {types} = require('putout');
3
+ const {
4
+ types,
5
+ operator,
6
+ } = require('putout');
7
+
8
+ const isNumber = (a) => typeof a === 'number';
9
+
10
+ const isString = (a) => typeof a === 'string';
11
+
12
+ const {compute} = operator;
4
13
 
5
14
  const {
6
15
  isLiteral,
@@ -16,11 +25,23 @@ module.exports.report = (path) => {
16
25
  return `Use 't.equal(${args[0]}, ${args[1]}, ${args[2]})' instead of '${path} when comparin with primitive'`;
17
26
  };
18
27
 
19
- const check = ({__b}) => {
28
+ const check = ({__b}, path) => {
20
29
  if (isRegExpLiteral(__b))
21
30
  return false;
22
31
 
23
- return isLiteral(__b);
32
+ if (isLiteral(__b))
33
+ return true;
34
+
35
+ const expectedPath = path.get('arguments.1');
36
+ const [is, value] = compute(expectedPath);
37
+
38
+ if (is && isString(value) || isNumber(value))
39
+ return true;
40
+
41
+ if (checkExpected(expectedPath))
42
+ return true;
43
+
44
+ return false;
24
45
  };
25
46
 
26
47
  module.exports.match = () => ({
@@ -33,3 +54,23 @@ module.exports.replace = () => ({
33
54
  't.deepEqual(__a, __b, __c)': 't.equal(__a, __b, __c)',
34
55
  });
35
56
 
57
+ function checkExpected(path) {
58
+ if (!path.isIdentifier())
59
+ return false;
60
+
61
+ const {name} = path.node;
62
+ const binding = path.scope.bindings[name];
63
+
64
+ if (!binding)
65
+ return false;
66
+
67
+ if (!binding.path.isVariableDeclarator())
68
+ return false;
69
+
70
+ const initPath = binding.path.get('init');
71
+
72
+ if (initPath.isTaggedTemplateExpression())
73
+ return true;
74
+
75
+ return false;
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-tape",
3
- "version": "9.9.0",
3
+ "version": "9.11.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with tests",