@putout/plugin-types 10.2.0 → 10.3.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
@@ -14,6 +14,7 @@ npm i putout @putout/plugin-types -D
14
14
  ## Rules
15
15
 
16
16
  - ✅ [apply-is-array](#apply-is-array);
17
+ - ✅ [apply-number](#apply-number);
17
18
  - ✅ [convert-typeof-to-is-type](#convert-typeof-to-is-type);
18
19
  - ✅ [declare](#declare);
19
20
  - ✅ [remove-double-negations](#remove-double-negations);
@@ -26,17 +27,86 @@ npm i putout @putout/plugin-types -D
26
27
  ```json
27
28
  {
28
29
  "rules": {
30
+ "types/apply-is-array": "on",
31
+ "types/apply-number": "on",
29
32
  "types/declare": "on",
30
33
  "types/convert-typeof-to-istype": "on",
31
34
  "types/remove-useless-conversion": "on",
32
35
  "types/remove-useless-constructor": "on",
33
36
  "types/remove-double-negations": "on",
34
- "types/remove-useless-typeof": "on",
35
- "types/apply-is-array": "on"
37
+ "types/remove-useless-typeof": "on"
36
38
  }
37
39
  }
38
40
  ```
39
41
 
42
+ ## apply-number
43
+
44
+ > The `Number` constructor contains constants and methods for working with numbers. Values of other types can be converted to numbers using the `Number()` function
45
+ >
46
+ > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
47
+
48
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/05ad2a403eb6d765a190297c492fd6d1/3cf396d108bbb4822317b6d6856db3a4c26fa3c1).
49
+
50
+ ### ❌ Example of incorrect code
51
+
52
+ ```js
53
+ const a = {
54
+ BooleanLiteral(node) {
55
+ return {
56
+ value: node.value ? 1 : 0,
57
+ };
58
+ },
59
+ };
60
+ ```
61
+
62
+ ### ✅ Example of correct code
63
+
64
+ ```js
65
+ const a = {
66
+ BooleanLiteral(node) {
67
+ return {
68
+ value: Number(node.value),
69
+ };
70
+ },
71
+ };
72
+ ```
73
+
74
+ ## apply-is-array
75
+
76
+ > The `Array.isArray()` method determines whether the passed value is an `Array`.
77
+ > When checking for `Array` instance, `Array.isArray()` is preferred over `instanceof` because it works through `iframes`.
78
+
79
+ ### ❌ Example of incorrect code
80
+
81
+ ```js
82
+ x instanceof Array;
83
+ ```
84
+
85
+ ### ✅ Example of correct code
86
+
87
+ ```js
88
+ const {isArray} = Array;
89
+ isArray(x);
90
+ ```
91
+
92
+ In case of using `inline` option:
93
+
94
+ ```json
95
+ {
96
+ "rules": {
97
+ "types/apply-is-array": ["on", {
98
+ "inline": true
99
+ }]
100
+ }
101
+ }
102
+ ```
103
+
104
+ `Array.isArray` will be inlined:
105
+
106
+ ```js
107
+ Array.isArray(x);
108
+ ```
109
+
40
110
  ## declare
41
111
 
42
112
  Based on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#putoutoperator-declare-).
@@ -190,52 +260,12 @@ typeof typeof 'hello';
190
260
  typeof 'hello';
191
261
  ```
192
262
 
193
- ## apply-is-array
194
-
195
- > The `Array.isArray()` method determines whether the passed value is an `Array`.
196
- > When checking for `Array` instance, `Array.isArray()` is preferred over `instanceof` because it works through `iframes`.
197
-
198
- ### ❌ Example of incorrect code
199
-
200
- ```js
201
- x instanceof Array;
202
- ```
203
-
204
- ### ✅ Example of correct code
205
-
206
- ```js
207
- const {isArray} = Array;
208
- isArray(x);
209
- ```
210
-
211
- In case of using `inline` option:
212
-
213
- ```json
214
- {
215
- "rules": {
216
- "types/apply-is-array": ["on", {
217
- "inline": true
218
- }]
219
- }
220
- }
221
- ```
222
-
223
- `Array.isArray` will be inlined:
224
-
225
- ```js
226
- Array.isArray(x);
227
- ```
228
-
229
- ## License
230
-
231
- MIT
232
-
233
263
  ## Comparison
234
264
 
235
- Linter | Rule | Fix
236
- --------|-------|------------|
237
- 🐊 **Putout** | [`types`](https://github.com/coderaiser/putout/tree/master/packages/plugin-types#readme)| ✅
238
- ⏣ **ESLint** | [`no-implicit-coercion`](https://eslint.org/docs/rules/no-implicit-coercion) | ✅
265
+ | Linter | Rule | Fix |
266
+ |---------------|------|-----|
267
+ | 🐊 **Putout** | [`types`](https://github.com/coderaiser/putout/tree/master/packages/plugin-types#readme) | ✅ |
268
+ | ⏣ **ESLint** | [`no-implicit-coercion`](https://eslint.org/docs/rules/no-implicit-coercion) | ✅ |
239
269
 
240
270
  ## License
241
271
 
@@ -0,0 +1,5 @@
1
+ export const report = () => `Use 'Number()' instead of 'ternary expression'`;
2
+
3
+ export const replace = () => ({
4
+ '__a ? 1 : 0': 'Number(__a)',
5
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as applyNumber from './apply-number/index.js';
1
2
  import * as applyIsArray from './apply-is-array/index.js';
2
3
  import * as declare from './declare/index.js';
3
4
  import * as convertTypeofToIsType from './convert-typeof-to-is-type/index.js';
@@ -14,4 +15,5 @@ export const rules = {
14
15
  'remove-useless-constructor': removeUselessConstructor,
15
16
  'remove-double-negations': removeDoubleNegations,
16
17
  'remove-useless-typeof': removeUselessTypeof,
18
+ 'apply-number': applyNumber,
17
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
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",
@@ -36,10 +36,9 @@
36
36
  "@putout/plugin-putout": "*",
37
37
  "@putout/test": "^15.0.0",
38
38
  "eslint": "^10.0.0",
39
- "eslint-plugin-n": "^17.0.0",
40
39
  "eslint-plugin-putout": "^31.0.0",
41
40
  "madrun": "^13.0.0",
42
- "montag": "^1.2.1",
41
+ "montag": "^2.0.0",
43
42
  "nodemon": "^3.0.1",
44
43
  "superc8": "^12.0.0"
45
44
  },