@putout/plugin-putout 29.30.1 → 29.31.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 +18 -34
- package/lib/apply-type-check/index.js +38 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ npm i @putout/plugin-putout -D
|
|
|
13
13
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
|
+
- ✅ [apply-type-check](#apply-type-check)
|
|
16
17
|
- ✅ [add-await-to-progress](#add-await-to-progress);
|
|
17
18
|
- ✅ [add-crawl-file](#add-crawl-file);
|
|
18
19
|
- ✅ [add-path-arg-to-filter](#add-path-arg-to-filter);
|
|
@@ -115,22 +116,16 @@ npm i @putout/plugin-putout -D
|
|
|
115
116
|
"putout/add-crawl-file": "on",
|
|
116
117
|
"putout/add-path-arg-to-filter": "on",
|
|
117
118
|
"putout/add-path-arg-to-fix": "on",
|
|
118
|
-
|
|
119
119
|
"putout/add-path-arg-to-match": "on",
|
|
120
120
|
"putout/add-path-arg-to-visitors": "on",
|
|
121
121
|
"putout/add-places-to-compare-places": "on",
|
|
122
|
-
|
|
123
122
|
"putout/add-push-arg": "on",
|
|
124
123
|
"putout/add-test-args": "on",
|
|
125
|
-
|
|
126
124
|
"putout/add-track-file": "on",
|
|
127
125
|
"putout/add-traverse-args": "on",
|
|
128
|
-
|
|
129
126
|
"putout/apply-async-formatter": "on",
|
|
130
|
-
|
|
131
127
|
"putout/apply-create-nested-directory": "on",
|
|
132
128
|
"putout/apply-create-test": "on",
|
|
133
|
-
|
|
134
129
|
"putout/apply-declare": "on",
|
|
135
130
|
"putout/apply-destructuring": "on",
|
|
136
131
|
"putout/apply-destructuring-to-options": "on",
|
|
@@ -139,100 +134,73 @@ npm i @putout/plugin-putout -D
|
|
|
139
134
|
"putout/apply-exports-to-add-args": "on",
|
|
140
135
|
"putout/apply-exports-to-match-files": "on",
|
|
141
136
|
"putout/apply-exports-to-rename-files": "on",
|
|
142
|
-
|
|
143
137
|
"putout/apply-fixture-name-to-message": "on",
|
|
144
138
|
"putout/apply-for-of-to-track-file": "on",
|
|
145
139
|
"putout/apply-get-binding": "on",
|
|
146
|
-
|
|
147
140
|
"putout/apply-insert-after": "on",
|
|
148
141
|
"putout/apply-insert-before": "on",
|
|
149
|
-
|
|
150
142
|
"putout/apply-lowercase-to-node-builders": "on",
|
|
151
143
|
"putout/apply-name-to-is-identifier": "on",
|
|
152
|
-
|
|
153
144
|
"putout/apply-namespace-specifier": "on",
|
|
154
145
|
"putout/apply-parens": "on",
|
|
155
146
|
"putout/apply-processors-destructuring": "on",
|
|
156
|
-
|
|
157
147
|
"putout/apply-remove": "on",
|
|
158
148
|
"putout/apply-rename": "on",
|
|
159
149
|
"putout/apply-report": "on",
|
|
160
|
-
|
|
161
150
|
"putout/apply-short-processors": "on",
|
|
162
151
|
"putout/apply-string-to-property-key": "on",
|
|
163
152
|
"putout/apply-transform-with-options": "on",
|
|
164
|
-
|
|
165
153
|
"putout/apply-traverser-to-ignore": "on",
|
|
166
154
|
|
|
155
|
+
"putout/apply-type-check": "on",
|
|
167
156
|
"putout/apply-vars": "on",
|
|
168
|
-
|
|
169
157
|
"putout/check-declare": "on",
|
|
170
158
|
"putout/check-match": "on",
|
|
171
|
-
|
|
172
159
|
"putout/check-replace-code": ["on", {
|
|
173
160
|
"once": true
|
|
174
161
|
}],
|
|
175
|
-
|
|
176
162
|
"putout/convert-add-argument-to-add-args": "on",
|
|
177
163
|
"putout/convert-babel-types": "on",
|
|
178
164
|
"putout/convert-destructuring-to-identifier": "on",
|
|
179
|
-
|
|
180
165
|
"putout/convert-dirname-to-url": "on",
|
|
181
|
-
|
|
182
166
|
"putout/convert-get-file-content-to-read-file-content": "on",
|
|
183
167
|
"putout/convert-get-rule-to-require": "on",
|
|
184
168
|
"putout/convert-include-to-traverse": "on",
|
|
185
169
|
"putout/convert-match-to-function": "on",
|
|
186
|
-
|
|
187
170
|
"putout/convert-method-to-property": "on",
|
|
188
171
|
"putout/convert-node-to-path-in-get-template-values": "on",
|
|
189
172
|
"putout/convert-number-to-numeric": "on",
|
|
190
|
-
|
|
191
173
|
"putout/convert-plugins-element-to-tuple": "on",
|
|
192
174
|
"putout/convert-process-to-find": "on",
|
|
193
|
-
|
|
194
175
|
"putout/convert-progress-to-track-file": "on",
|
|
195
|
-
|
|
196
176
|
"putout/convert-push-object-to-push-path": "on",
|
|
197
177
|
"putout/convert-putout-test-to-create-test": "on",
|
|
198
|
-
|
|
199
178
|
"putout/convert-replace-to-function": "on",
|
|
200
179
|
"putout/convert-replace-to-traverse": "on",
|
|
201
180
|
"putout/convert-replace-with": "on",
|
|
202
181
|
"putout/convert-replace-with-multiple": "on",
|
|
203
|
-
|
|
204
182
|
"putout/convert-report-to-function": "on",
|
|
205
183
|
"putout/convert-to-no-transform-code": "on",
|
|
206
|
-
|
|
207
184
|
"putout/convert-traverse-to-include": "on",
|
|
208
185
|
"putout/convert-traverse-to-replace": "on",
|
|
209
186
|
"putout/convert-traverse-to-scan": "on",
|
|
210
187
|
"putout/convert-traverse-to-super-traverse": "on",
|
|
211
|
-
|
|
212
188
|
"putout/convert-url-to-dirname": "on",
|
|
213
|
-
|
|
214
189
|
"putout/create-test": "on",
|
|
215
190
|
"putout/declare": "on",
|
|
216
|
-
|
|
217
191
|
"putout/declare-path-variable": "on",
|
|
218
192
|
"putout/declare-template-variables": "on",
|
|
219
|
-
|
|
220
193
|
"putout/includer": "on",
|
|
221
194
|
"putout/move-require-on-top-level": "on",
|
|
222
|
-
|
|
223
195
|
"putout/remove-empty-array-from-process": "on",
|
|
224
196
|
"putout/remove-empty-object-from-transform": "on",
|
|
225
|
-
|
|
226
197
|
"putout/remove-message-from-no-report-after-transform": "on",
|
|
227
198
|
"putout/remove-unused-get-properties-argument": "on",
|
|
228
|
-
|
|
229
199
|
"putout/remove-useless-printer-option": "on",
|
|
230
200
|
"putout/remove-useless-source-argument": "on",
|
|
231
201
|
"putout/replace-test-message": "on",
|
|
232
|
-
|
|
233
202
|
"putout/shorten-imports": "on",
|
|
234
203
|
"putout/simplify-replace-template": "on",
|
|
235
|
-
|
|
236
204
|
"putout/sort-readme-file": "on"
|
|
237
205
|
}
|
|
238
206
|
}
|
|
@@ -2291,6 +2259,22 @@ test('flatlint: convert-comma-to-semicolon: no report: array', (t) => {
|
|
|
2291
2259
|
});
|
|
2292
2260
|
```
|
|
2293
2261
|
|
|
2262
|
+
## apply-type-check
|
|
2263
|
+
|
|
2264
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3176ff5d9bfb388723c977735e49d599/00036b9cbd71b1a778c8423e2e7a707abd9f2f1f).
|
|
2265
|
+
|
|
2266
|
+
### ❌ Example of incorrect code
|
|
2267
|
+
|
|
2268
|
+
```js
|
|
2269
|
+
if (a.type === 'CallExpression') {}
|
|
2270
|
+
```
|
|
2271
|
+
|
|
2272
|
+
### ✅ Example of correct code
|
|
2273
|
+
|
|
2274
|
+
```js
|
|
2275
|
+
if (isCallExpression(a)) {}
|
|
2276
|
+
```
|
|
2277
|
+
|
|
2294
2278
|
## License
|
|
2295
2279
|
|
|
2296
2280
|
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isTemplateLiteral,
|
|
5
|
+
isStringLiteral,
|
|
6
|
+
} = types;
|
|
7
|
+
|
|
8
|
+
const {extract} = operator;
|
|
9
|
+
|
|
10
|
+
export const report = () => `Use 'is-' function to check type`;
|
|
11
|
+
|
|
12
|
+
export const match = () => ({
|
|
13
|
+
'__a.type === __b': check,
|
|
14
|
+
'__a.type !== __b': check,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const replace = () => ({
|
|
18
|
+
'__a.type === __b': ({__b}) => {
|
|
19
|
+
const value = extract(__b);
|
|
20
|
+
return `is${value}(__a)`;
|
|
21
|
+
},
|
|
22
|
+
'__a.type !== __b': ({__b}) => {
|
|
23
|
+
const value = extract(__b);
|
|
24
|
+
return `!is${value}(__a)`;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
function check({__b}) {
|
|
29
|
+
if (!isStringLiteral(__b) && !isTemplateLiteral(__b))
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
const value = extract(__b);
|
|
33
|
+
|
|
34
|
+
if (!value)
|
|
35
|
+
return false;
|
|
36
|
+
|
|
37
|
+
return types[`is${value}`];
|
|
38
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyTypeCheck from './apply-type-check/index.js';
|
|
1
2
|
import * as sortReadmeFile from './sort-readme-file/index.js';
|
|
2
3
|
import * as applyStringToPropertyKey from './apply-string-to-property-key/index.js';
|
|
3
4
|
import * as convertTraverseToSuperTraverse from './convert-traverse-to-super-traverse/index.js';
|
|
@@ -178,4 +179,5 @@ export const rules = {
|
|
|
178
179
|
'convert-traverse-to-super-traverse': convertTraverseToSuperTraverse,
|
|
179
180
|
'apply-string-to-property-key': applyStringToPropertyKey,
|
|
180
181
|
'sort-readme-file': sortReadmeFile,
|
|
182
|
+
'apply-type-check': applyTypeCheck,
|
|
181
183
|
};
|
package/package.json
CHANGED