@putout/plugin-types 3.0.0 → 4.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.
package/README.md CHANGED
@@ -11,7 +11,16 @@
11
11
  npm i putout @putout/plugin-types -D
12
12
  ```
13
13
 
14
- ## Options
14
+ ## Rules
15
+
16
+ - ✅ [apply-is-array](#apply-is-array);
17
+ - ✅ [convert-typeof-to-is-type](#convert-typeof-to-is-type);
18
+ - ✅ [declare](#declare);
19
+ - ✅ [remove-double-negations](#remove-double-negations);
20
+ - ✅ [remove-useless-conversion](#remove-useless-conversion);
21
+ - ✅ [remove-useless-typeof](#remove-useless-typeof);
22
+
23
+ ## Config
15
24
 
16
25
  ```json
17
26
  {
@@ -26,9 +35,7 @@ npm i putout @putout/plugin-types -D
26
35
  }
27
36
  ```
28
37
 
29
- ## Rules
30
-
31
- ### declare
38
+ ## declare
32
39
 
33
40
  Based on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#putoutoperator-declare-).
34
41
  Supported assertions:
@@ -43,14 +50,16 @@ Supported assertions:
43
50
  - `isSymbol`;
44
51
  - `isNull`;
45
52
  - `isBigInt`;
53
+ - `isArray`;
54
+ - `isEmptyArray`;
46
55
 
47
- #### ❌ Example of incorrect code
56
+ ### ❌ Example of incorrect code
48
57
 
49
58
  ```js
50
59
  isString('hello');
51
60
  ```
52
61
 
53
- #### ✅ Example of correct code
62
+ ### ✅ Example of correct code
54
63
 
55
64
  ```js
56
65
  const isString = (a) => typeof a === 'string';
@@ -69,20 +78,20 @@ When you want to skip some declaration use `dismiss`:
69
78
  }
70
79
  ```
71
80
 
72
- ### convert-typeof-to-is-type
81
+ ## convert-typeof-to-is-type
73
82
 
74
83
  > The `typeof` operator returns a string indicating the type of the unevaluated operand.
75
84
  >
76
85
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
77
86
 
78
- #### ❌ Example of incorrect code
87
+ ### ❌ Example of incorrect code
79
88
 
80
89
  ```js
81
90
  if (typeof a === 'boolean')
82
91
  return x;
83
92
  ```
84
93
 
85
- #### ✅ Example of correct code
94
+ ### ✅ Example of correct code
86
95
 
87
96
  ```js
88
97
  const isBool = (a) => typeof a === 'boolean';
@@ -91,22 +100,22 @@ if (isBool(a))
91
100
  return x;
92
101
  ```
93
102
 
94
- ### remove-useless-conversion
103
+ ## remove-useless-conversion
95
104
 
96
- #### ❌ Example of incorrect code
105
+ ### ❌ Example of incorrect code
97
106
 
98
107
  ```js
99
108
  const a = !![1].includes(1);
100
109
  const b = Boolean([1].includes(1));
101
110
  ```
102
111
 
103
- #### ✅ Example of correct code
112
+ ### ✅ Example of correct code
104
113
 
105
114
  ```js
106
115
  const a = [1].includes(1);
107
116
  ```
108
117
 
109
- ### remove-double-negations
118
+ ## remove-double-negations
110
119
 
111
120
  > It is possible to use a couple of **NOT** operators (`!!`) in series to explicitly force the conversion of any value to the corresponding boolean primitive. The conversion is based on the "truthyness" or "falsyness" of the value.
112
121
  >
@@ -114,52 +123,50 @@ const a = [1].includes(1);
114
123
  >
115
124
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT)
116
125
 
117
- #### ❌ Example of incorrect code
126
+ ### ❌ Example of incorrect code
118
127
 
119
128
  ```js
120
- if (!!a) {
129
+ if (!!a)
121
130
  console.log('hi');
122
- }
123
131
  ```
124
132
 
125
- #### ✅ Example of correct code
133
+ ### ✅ Example of correct code
126
134
 
127
135
  ```js
128
- if (a) {
136
+ if (a)
129
137
  console.log('hi');
130
- }
131
138
  ```
132
139
 
133
- ### remove-useless-typeof
140
+ ## remove-useless-typeof
134
141
 
135
142
  > The `typeof` operator returns a string indicating the type of the unevaluated operand.
136
143
  >
137
144
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
138
145
 
139
- #### ❌ Example of incorrect code
146
+ ### ❌ Example of incorrect code
140
147
 
141
148
  ```js
142
149
  typeof typeof 'hello';
143
150
  ```
144
151
 
145
- #### ✅ Example of correct code
152
+ ### ✅ Example of correct code
146
153
 
147
154
  ```js
148
155
  typeof 'hello';
149
156
  ```
150
157
 
151
- ### apply-is-array
158
+ ## apply-is-array
152
159
 
153
160
  > The `Array.isArray()` method determines whether the passed value is an `Array`.
154
161
  > When checking for `Array` instance, `Array.isArray()` is preferred over `instanceof` because it works through `iframes`.
155
162
 
156
- #### ❌ Example of incorrect code
163
+ ### ❌ Example of incorrect code
157
164
 
158
165
  ```js
159
166
  x instanceof Array;
160
167
  ```
161
168
 
162
- #### ✅ Example of correct code
169
+ ### ✅ Example of correct code
163
170
 
164
171
  ```js
165
172
  const {isArray} = Array;
@@ -11,4 +11,6 @@ module.exports.declare = () => ({
11
11
  isSymbol: `const isSymbol = (a) => typeof a === 'symbol'`,
12
12
  isBigInt: `const isBigInt = (a) => typeof a === 'bigint'`,
13
13
  isNull: `const isNull = (a) => !a && typeof a === 'object'`,
14
+ isArray: 'const {isArray} = Array',
15
+ isEmptyArray: 'const isEmptyArray = (a) => isArray(a) && !a.length',
14
16
  });
@@ -6,6 +6,7 @@ module.exports.replace = () => ({
6
6
  'Boolean(__a.includes(__b))': '__a.includes(__b)',
7
7
  'String(typeof __a)': 'typeof __a',
8
8
  'if (Boolean(__a)) __b': 'if (__a) __b',
9
+ 'Boolean(__a) ? __b : __c': '__a ? __b : __c',
9
10
  'while (Boolean(__a)) __b': 'while (__a) __b',
10
11
  'do __b; while (Boolean(__a))': 'do __b; while (__a)',
11
12
  'for (__a; Boolean(__b); __c) __d': 'for (__a; __b; __c) __d',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "3.0.0",
3
+ "version": "4.1.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",
@@ -32,22 +32,22 @@
32
32
  ],
33
33
  "devDependencies": {
34
34
  "@putout/plugin-putout": "*",
35
- "@putout/test": "^7.0.0",
36
- "c8": "^8.0.0",
37
- "eslint": "^8.0.1",
38
- "eslint-plugin-n": "^16.0.0",
39
- "eslint-plugin-putout": "^19.0.0",
35
+ "@putout/test": "^9.0.0",
36
+ "c8": "^9.0.0",
37
+ "eslint": "^9.0.0",
38
+ "eslint-plugin-n": "^17.0.0",
39
+ "eslint-plugin-putout": "^22.0.0",
40
40
  "lerna": "^6.0.1",
41
- "madrun": "^9.0.0",
41
+ "madrun": "^10.0.0",
42
42
  "montag": "^1.2.1",
43
43
  "nodemon": "^3.0.1"
44
44
  },
45
45
  "peerDependencies": {
46
- "putout": ">=31"
46
+ "putout": ">=35"
47
47
  },
48
48
  "license": "MIT",
49
49
  "engines": {
50
- "node": ">=16"
50
+ "node": ">=18"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"