@putout/plugin-types 7.0.0 → 8.1.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.
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ export const report = () => `Use 'Array.isArray()' instead of 'instanceof'`;
2
2
 
3
- module.exports.report = () => `Use 'Array.isArray()' instead of 'instanceof'`;
4
-
5
- module.exports.replace = ({options}) => {
3
+ export const replace = ({options}) => {
6
4
  const {inline} = options;
7
5
 
8
6
  return {
@@ -1,7 +1,10 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
- const {compare, getBindingPath} = operator;
3
+ const {
4
+ compare,
5
+ getBindingPath,
6
+ extract,
7
+ } = operator;
5
8
 
6
9
  const NAMES = {
7
10
  function: 'isFn',
@@ -11,6 +14,7 @@ const NAMES = {
11
14
  undefined: 'isUndefined',
12
15
  symbol: 'isSymbol',
13
16
  bigint: 'isBigInt',
17
+ Object: 'isObject',
14
18
  };
15
19
 
16
20
  const EQUAL = 'typeof __a === "__b"';
@@ -50,17 +54,18 @@ const NOT_BODIES = {
50
54
  equalUndefined: '__a !== undefined',
51
55
  };
52
56
 
53
- module.exports.report = () => `Use function to check type instead of 'typeof' or 'instanceof'`;
54
- module.exports.match = () => ({
57
+ export const report = () => `Use function to check type instead of 'typeof' or 'instanceof'`;
58
+ export const match = () => ({
55
59
  [EQUAL]: check,
56
60
  [NOT_EQUAL]: check,
57
- [EQUAL_INSTANCE_OF]: check,
61
+
58
62
  [NOT_EQUAL_INSTANCE_OF]: check,
59
63
  [EQUAL_UNDEFINED]: check,
60
64
  [NOT_EQUAL_UNDEFINED]: check,
65
+ [EQUAL_INSTANCE_OF]: check,
61
66
  });
62
67
 
63
- module.exports.replace = () => ({
68
+ export const replace = () => ({
64
69
  [BODIES.function]: 'isFn(__a)',
65
70
  [BODIES.string]: 'isString(__a)',
66
71
  [BODIES.number]: 'isNumber(__a)',
@@ -89,7 +94,7 @@ function check({__a, __b}, path) {
89
94
  if (path.parentPath.isFunction())
90
95
  return false;
91
96
 
92
- if (__b && isBind(path, __b.value))
97
+ if (__b && isBind(path, extract(__b)))
93
98
  return false;
94
99
 
95
100
  return getBindingPath(path, __a);
@@ -104,7 +109,13 @@ function isBind(path, name) {
104
109
  return false;
105
110
 
106
111
  if (bindingPath.isVariableDeclarator()) {
107
- const {body} = bindingPath.node.init;
112
+ const initPath = bindingPath.get('init');
113
+
114
+ if (!initPath.isFunction())
115
+ return true;
116
+
117
+ const {body} = initPath.node;
118
+
108
119
  return !compare(body, fnBody);
109
120
  }
110
121
 
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.declare = () => ({
1
+ export const declare = () => ({
4
2
  isString: `const isString = (a) => typeof a === 'string'`,
5
3
  isEmptyString: `const isEmptyString = (a) => !a && isString(a)`,
6
4
  isNumber: `const isNumber = (a) => !Number.isNaN(a) && typeof a === 'number'`,
package/lib/index.js CHANGED
@@ -1,16 +1,14 @@
1
- 'use strict';
1
+ import * as applyIsArray from './apply-is-array/index.js';
2
+ import * as declare from './declare/index.js';
3
+ import * as convertTypeofToIsType from './convert-typeof-to-is-type/index.js';
4
+ import * as removeUselessConversion from './remove-useless-conversion/index.js';
5
+ import * as removeUselessConstructor from './remove-useless-constructor/index.js';
6
+ import * as removeDoubleNegations from './remove-double-negations/index.js';
7
+ import * as removeUselessTypeof from './remove-useless-typeof/index.js';
2
8
 
3
- const applyIsArray = require('./apply-is-array');
4
- const declare = require('./declare');
5
- const convertTypeofToIsType = require('./convert-typeof-to-is-type');
6
- const removeUselessConversion = require('./remove-useless-conversion');
7
- const removeUselessConstructor = require('./remove-useless-constructor');
8
- const removeDoubleNegations = require('./remove-double-negations');
9
- const removeUselessTypeof = require('./remove-useless-typeof');
10
-
11
- module.exports.rules = {
9
+ export const rules = {
12
10
  'apply-is-array': applyIsArray,
13
- declare,
11
+ 'declare': declare,
14
12
  'convert-typeof-to-is-type': convertTypeofToIsType,
15
13
  'remove-useless-conversion': removeUselessConversion,
16
14
  'remove-useless-constructor': removeUselessConstructor,
@@ -1,10 +1,8 @@
1
- 'use strict';
1
+ export const report = () => `Avoid double negations in conditions`;
2
2
 
3
- module.exports.report = () => `Avoid double negations in conditions`;
3
+ export const filter = ({parentPath}) => !parentPath.isJSXExpressionContainer();
4
4
 
5
- module.exports.filter = ({parentPath}) => !parentPath.isJSXExpressionContainer();
6
-
7
- module.exports.replace = () => ({
5
+ export const replace = () => ({
8
6
  'if (!!__a) __b': 'if (__a) __b',
9
7
  '!!__a ? __b : __c': '__a ? __b : __c',
10
8
  '!!__a && __b': '__a && __b',
@@ -1,19 +1,18 @@
1
- 'use strict';
1
+ import {types} from 'putout';
2
2
 
3
- const {types} = require('putout');
4
3
  const {
5
4
  isBooleanLiteral,
6
5
  isNumericLiteral,
7
6
  } = types;
8
7
 
9
- module.exports.report = () => 'Avoid useless constructor';
8
+ export const report = () => 'Avoid useless constructor';
10
9
 
11
- module.exports.match = () => ({
10
+ export const match = () => ({
12
11
  'Boolean(__a)': ({__a}) => isBooleanLiteral(__a),
13
12
  'Number(__a)': ({__a}) => isNumericLiteral(__a),
14
13
  });
15
14
 
16
- module.exports.replace = () => ({
15
+ export const replace = () => ({
17
16
  'String("__a")': '__a',
18
17
  'Boolean(__a)': '__a',
19
18
  'Number(__a)': '__a',
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ export const report = () => `Avoid useless type conversion`;
2
2
 
3
- module.exports.report = () => `Avoid useless type conversion`;
4
-
5
- module.exports.replace = () => ({
3
+ export const replace = () => ({
6
4
  'Boolean(__a.includes(__b))': '__a.includes(__b)',
7
5
  'String(typeof __a)': 'typeof __a',
8
6
  'if (Boolean(__a)) __b': 'if (__a) __b',
@@ -1,7 +1,5 @@
1
- 'use strict';
1
+ export const report = () => `Avoid useless 'typeof'`;
2
2
 
3
- module.exports.report = () => `Avoid useless 'typeof'`;
4
-
5
- module.exports.replace = () => ({
3
+ export const replace = () => ({
6
4
  'typeof typeof __a': 'typeof __a',
7
5
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "7.0.0",
4
- "type": "commonjs",
3
+ "version": "8.1.0",
4
+ "type": "module",
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",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-types#readme",
@@ -31,24 +31,24 @@
31
31
  "types"
32
32
  ],
33
33
  "devDependencies": {
34
- "@putout/eslint-flat": "^2.0.0",
34
+ "@putout/eslint-flat": "^3.0.0",
35
+ "@putout/plugin-declare-before-reference": "*",
35
36
  "@putout/plugin-putout": "*",
36
- "@putout/test": "^11.0.0",
37
+ "@putout/test": "^14.0.0",
37
38
  "c8": "^10.0.0",
38
39
  "eslint": "^9.0.0",
39
40
  "eslint-plugin-n": "^17.0.0",
40
- "eslint-plugin-putout": "^24.0.0",
41
- "lerna": "^6.0.1",
42
- "madrun": "^10.0.0",
41
+ "eslint-plugin-putout": "^28.0.0",
42
+ "madrun": "^11.0.0",
43
43
  "montag": "^1.2.1",
44
44
  "nodemon": "^3.0.1"
45
45
  },
46
46
  "peerDependencies": {
47
- "putout": ">=38"
47
+ "putout": ">=40"
48
48
  },
49
49
  "license": "MIT",
50
50
  "engines": {
51
- "node": ">=18"
51
+ "node": ">=20"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"