@putout/plugin-types 1.5.0 → 1.7.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
@@ -62,9 +62,7 @@ When you want to skip some declaration use `dismiss`:
62
62
  {
63
63
  "rules": {
64
64
  "types/declare": ["on", {
65
- "dismiss": [
66
- "isString"
67
- ]
65
+ "dismiss": ["isString"]
68
66
  }]
69
67
  }
70
68
  }
@@ -14,4 +14,3 @@ module.exports.replace = ({options}) => {
14
14
  },
15
15
  };
16
16
  };
17
-
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const {operator} = require('putout');
4
- const {compare, getBindingPath} = operator;
4
+ const {
5
+ compare,
6
+ getBindingPath,
7
+ } = operator;
5
8
 
6
9
  const NAMES = {
7
10
  function: 'isFn',
@@ -12,6 +15,8 @@ const NAMES = {
12
15
  symbol: 'isSymbol',
13
16
  };
14
17
 
18
+ const GENERAL = 'typeof __a === "__b"';
19
+
15
20
  const BODIES = {
16
21
  function: `typeof __a === 'function'`,
17
22
  string: `typeof __a === 'string'`,
@@ -23,7 +28,7 @@ const BODIES = {
23
28
 
24
29
  module.exports.report = () => `Use function to check type instead of 'typeof'`;
25
30
  module.exports.match = () => ({
26
- 'typeof __a === "__b"': ({__a, __b}, path) => {
31
+ [GENERAL]: ({__a, __b}, path) => {
27
32
  if (path.parentPath.isFunction())
28
33
  return false;
29
34
 
@@ -33,10 +38,7 @@ module.exports.match = () => ({
33
38
  if (isBind(path, __b.value))
34
39
  return false;
35
40
 
36
- if (!getBindingPath(path, __a))
37
- return false;
38
-
39
- return true;
41
+ return Boolean(getBindingPath(path, __a));
40
42
  },
41
43
  });
42
44
 
@@ -57,8 +59,10 @@ function isBind(path, name) {
57
59
  if (!bindingPath)
58
60
  return false;
59
61
 
62
+ if (!bindingPath.isVariableDeclarator())
63
+ return false;
64
+
60
65
  const {body} = bindingPath.node.init;
61
66
 
62
67
  return !compare(body, fnBody);
63
68
  }
64
-
@@ -11,4 +11,3 @@ module.exports.declare = () => ({
11
11
  isSymbol: `const isSymbol = (a) => typeof a === 'symbol'`,
12
12
  isNull: `const isNull = (a) => !a && typeof a === 'object'`,
13
13
  });
14
-
package/lib/index.js CHANGED
@@ -12,4 +12,3 @@ module.exports.rules = {
12
12
  ...getRule('remove-double-negations'),
13
13
  ...getRule('remove-useless-typeof'),
14
14
  };
15
-
@@ -9,8 +9,9 @@ module.exports.replace = () => ({
9
9
  '!!__a ? __b : __c': '__a ? __b : __c',
10
10
  '!!__a && __b': '__a && __b',
11
11
  '!!__a.includes(__b)': '__a.includes(__b)',
12
+ '!!__a.startsWith(__b)': '__a.startsWith(__b)',
13
+
12
14
  'while(!!__a) __b': 'while(__a) __b',
13
15
  'do __a; while(!!__b)': 'do __a; while(__b)',
14
16
  'for (__a; !!__b; __c) __d': 'for (__a; __b; __c) __d',
15
17
  });
16
-
@@ -13,4 +13,3 @@ module.exports.replace = () => ({
13
13
  'for (; Boolean(__b);__c) __d': 'for (; __b; __c) __d',
14
14
  'for (; Boolean(__b);) __d': 'for (; __b;) __d',
15
15
  });
16
-
@@ -5,4 +5,3 @@ module.exports.report = () => `Useless typeof should be avoided`;
5
5
  module.exports.replace = () => ({
6
6
  'typeof typeof __a': 'typeof __a',
7
7
  });
8
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code related to types assertions",
@@ -35,7 +35,7 @@
35
35
  "@putout/test": "^6.0.0",
36
36
  "c8": "^7.5.0",
37
37
  "eslint": "^8.0.1",
38
- "eslint-plugin-n": "^15.2.4",
38
+ "eslint-plugin-n": "^16.0.0",
39
39
  "eslint-plugin-putout": "^17.0.0",
40
40
  "lerna": "^6.0.1",
41
41
  "madrun": "^9.0.0",