@putout/plugin-types 10.6.0 → 10.6.1

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
@@ -14,14 +14,14 @@ npm i putout @putout/plugin-types -D
14
14
  ## Rules
15
15
 
16
16
  - ✅ [apply-boolean](#apply-boolean);
17
- - ✅ [apply-number](#apply-number);
18
17
  - ✅ [apply-is-array](#apply-is-array);
19
18
  - ✅ [apply-is-nan](#apply-is-nan);
19
+ - ✅ [apply-number](#apply-number);
20
20
  - ✅ [convert-typeof-to-is-type](#convert-typeof-to-is-type);
21
21
  - ✅ [declare](#declare);
22
22
  - ✅ [remove-double-negations](#remove-double-negations);
23
- - ✅ [remove-useless-conversion](#remove-useless-conversion);
24
23
  - ✅ [remove-useless-constructor](#remove-useless-constructor);
24
+ - ✅ [remove-useless-conversion](#remove-useless-conversion);
25
25
  - ✅ [remove-useless-typeof](#remove-useless-typeof);
26
26
 
27
27
  ## Config
@@ -30,14 +30,18 @@ npm i putout @putout/plugin-types -D
30
30
  {
31
31
  "rules": {
32
32
  "types/apply-boolean": "on",
33
- "types/apply-number": "on",
33
+
34
34
  "types/apply-is-array": "on",
35
35
  "types/apply-is-nan": "on",
36
- "types/declare": "on",
36
+ "types/apply-number": "on",
37
+
37
38
  "types/convert-typeof-to-istype": "on",
38
- "types/remove-useless-conversion": "on",
39
- "types/remove-useless-constructor": "on",
39
+ "types/declare": "on",
40
+
40
41
  "types/remove-double-negations": "on",
42
+ "types/remove-useless-constructor": "on",
43
+ "types/remove-useless-conversion": "on",
44
+
41
45
  "types/remove-useless-typeof": "on"
42
46
  }
43
47
  }
@@ -63,38 +67,6 @@ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/150f85ffc7
63
67
  Boolean(a || b);
64
68
  ```
65
69
 
66
- ## apply-number
67
-
68
- > The `Number` constructor contains constants and methods for working with numbers. Values of other types can be converted to numbers using the `Number()` function
69
- >
70
- > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
71
-
72
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/05ad2a403eb6d765a190297c492fd6d1/3cf396d108bbb4822317b6d6856db3a4c26fa3c1).
73
-
74
- ### ❌ Example of incorrect code
75
-
76
- ```js
77
- const a = {
78
- BooleanLiteral(node) {
79
- return {
80
- value: node.value ? 1 : 0,
81
- };
82
- },
83
- };
84
- ```
85
-
86
- ### ✅ Example of correct code
87
-
88
- ```js
89
- const a = {
90
- BooleanLiteral(node) {
91
- return {
92
- value: Number(node.value),
93
- };
94
- },
95
- };
96
- ```
97
-
98
70
  ## apply-is-array
99
71
 
100
72
  > The `Array.isArray()` method determines whether the passed value is an `Array`.
@@ -141,7 +113,6 @@ Array.isArray(x);
141
113
 
142
114
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e8ff80a3f522626c2d049b771692ced1/7ea6eb75d7d39f20654753fc2d800f7d881abaca)
143
115
 
144
-
145
116
  ### ❌ Example of incorrect code
146
117
 
147
118
  ```js
@@ -156,6 +127,60 @@ if (Number.isNaN(a))
156
127
  console.log();
157
128
  ```
158
129
 
130
+ ## apply-number
131
+
132
+ > The `Number` constructor contains constants and methods for working with numbers. Values of other types can be converted to numbers using the `Number()` function
133
+ >
134
+ > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
135
+
136
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/05ad2a403eb6d765a190297c492fd6d1/3cf396d108bbb4822317b6d6856db3a4c26fa3c1).
137
+
138
+ ### ❌ Example of incorrect code
139
+
140
+ ```js
141
+ const a = {
142
+ BooleanLiteral(node) {
143
+ return {
144
+ value: node.value ? 1 : 0,
145
+ };
146
+ },
147
+ };
148
+ ```
149
+
150
+ ### ✅ Example of correct code
151
+
152
+ ```js
153
+ const a = {
154
+ BooleanLiteral(node) {
155
+ return {
156
+ value: Number(node.value),
157
+ };
158
+ },
159
+ };
160
+ ```
161
+
162
+ ## convert-typeof-to-is-type
163
+
164
+ > The `typeof` operator returns a string indicating the type of the unevaluated operand.
165
+ >
166
+ > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
167
+
168
+ ### ❌ Example of incorrect code
169
+
170
+ ```js
171
+ if (typeof a === 'boolean')
172
+ return x;
173
+ ```
174
+
175
+ ### ✅ Example of correct code
176
+
177
+ ```js
178
+ const isBool = (a) => typeof a === 'boolean';
179
+
180
+ if (isBool(a))
181
+ return x;
182
+ ```
183
+
159
184
  ## declare
160
185
 
161
186
  Based on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#putoutoperator-declare-).
@@ -208,41 +233,26 @@ When you want to skip some declaration use `dismiss`:
208
233
  }
209
234
  ```
210
235
 
211
- ## convert-typeof-to-is-type
236
+ ## remove-double-negations
212
237
 
213
- > The `typeof` operator returns a string indicating the type of the unevaluated operand.
238
+ > 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.
214
239
  >
215
- > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
216
-
217
- ### ❌ Example of incorrect code
218
-
219
- ```js
220
- if (typeof a === 'boolean')
221
- return x;
222
- ```
223
-
224
- ### ✅ Example of correct code
225
-
226
- ```js
227
- const isBool = (a) => typeof a === 'boolean';
228
-
229
- if (isBool(a))
230
- return x;
231
- ```
232
-
233
- ## remove-useless-conversion
240
+ > The same conversion can be done through the `Boolean` function.
241
+ >
242
+ > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT)
234
243
 
235
244
  ### ❌ Example of incorrect code
236
245
 
237
246
  ```js
238
- const a = !![1].includes(1);
239
- const b = Boolean([1].includes(1));
247
+ if (!!a)
248
+ console.log('hi');
240
249
  ```
241
250
 
242
251
  ### ✅ Example of correct code
243
252
 
244
253
  ```js
245
- const a = [1].includes(1);
254
+ if (a)
255
+ console.log('hi');
246
256
  ```
247
257
 
248
258
  ## remove-useless-constructor
@@ -269,26 +279,19 @@ const b = false;
269
279
  const n = 5;
270
280
  ```
271
281
 
272
- ## remove-double-negations
273
-
274
- > 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.
275
- >
276
- > The same conversion can be done through the `Boolean` function.
277
- >
278
- > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT)
282
+ ## remove-useless-conversion
279
283
 
280
284
  ### ❌ Example of incorrect code
281
285
 
282
286
  ```js
283
- if (!!a)
284
- console.log('hi');
287
+ const a = !![1].includes(1);
288
+ const b = Boolean([1].includes(1));
285
289
  ```
286
290
 
287
291
  ### ✅ Example of correct code
288
292
 
289
293
  ```js
290
- if (a)
291
- console.log('hi');
294
+ const a = [1].includes(1);
292
295
  ```
293
296
 
294
297
  ## remove-useless-typeof
@@ -92,7 +92,7 @@ export const replace = () => ({
92
92
  [NOT_BODIES.error]: '!isError(__a)',
93
93
  [NOT_BODIES.array]: '!isArray(__a)',
94
94
  [NOT_BODIES.object]: '!isObject(__a)',
95
- [NOT_BODIES.regexp]: 'isRegExp(__a)',
95
+ [NOT_BODIES.regexp]: '!isRegExp(__a)',
96
96
  [NOT_BODIES.equalUndefined]: '!isUndefined(__a)',
97
97
  });
98
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "10.6.0",
3
+ "version": "10.6.1",
4
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",