@putout/plugin-putout 29.33.4 → 29.34.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 +20 -1
- package/lib/index.js +2 -0
- package/lib/remove-useless-type-check-declaration/index.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -104,6 +104,7 @@ npm i @putout/plugin-putout -D
|
|
|
104
104
|
- ✅ [simplify-replace-template](#simplify-replace-template);
|
|
105
105
|
- ✅ [convert-replacer-to-includer](#convert-replacer-to-includer);
|
|
106
106
|
- ✅ [remove-useless-match](#remove-useless-match);
|
|
107
|
+
- ✅ [remove-useless-type-check-declaration](#remove-useless-type-check-declaration);
|
|
107
108
|
|
|
108
109
|
## File rules
|
|
109
110
|
|
|
@@ -204,7 +205,8 @@ npm i @putout/plugin-putout -D
|
|
|
204
205
|
"putout/simplify-replace-template": "on",
|
|
205
206
|
"putout/sort-readme-file": "on",
|
|
206
207
|
"putout/convert-replacer-to-includer": "on",
|
|
207
|
-
"putout/remove-useless-match": "on"
|
|
208
|
+
"putout/remove-useless-match": "on",
|
|
209
|
+
"putout/remove-useless-type-check-declaration": "on"
|
|
208
210
|
}
|
|
209
211
|
}
|
|
210
212
|
```
|
|
@@ -2319,6 +2321,23 @@ export const match = () => ({
|
|
|
2319
2321
|
```js
|
|
2320
2322
|
```
|
|
2321
2323
|
|
|
2324
|
+
## remove-useless-type-check-declaration
|
|
2325
|
+
|
|
2326
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/443f742c8cda2b50e1722cdf2577d5c3/1f269a3d5ae0dcfa8661ca283b329c53c2450b39).
|
|
2327
|
+
|
|
2328
|
+
### ❌ Example of incorrect code
|
|
2329
|
+
|
|
2330
|
+
```js
|
|
2331
|
+
const isStringLiteral = (arg) => arg.type === 'StringLiteral';
|
|
2332
|
+
const isMemberExpression = (arg) => arg.type === 'Identifier';
|
|
2333
|
+
```
|
|
2334
|
+
|
|
2335
|
+
### ✅ Example of correct code
|
|
2336
|
+
|
|
2337
|
+
```js
|
|
2338
|
+
const isMemberExpression = (arg) => arg.type === 'Identifier';
|
|
2339
|
+
```
|
|
2340
|
+
|
|
2322
2341
|
## License
|
|
2323
2342
|
|
|
2324
2343
|
MIT
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeUselessTypeCheckDeclaration from './remove-useless-type-check-declaration/index.js';
|
|
1
2
|
import * as removeUselessMatch from './remove-useless-match/index.js';
|
|
2
3
|
import * as convertReplacerToIncluder from './convert-replacer-to-includer/index.js';
|
|
3
4
|
import * as applyTypeCheck from './apply-type-check/index.js';
|
|
@@ -184,4 +185,5 @@ export const rules = {
|
|
|
184
185
|
'apply-type-check': applyTypeCheck,
|
|
185
186
|
'convert-replacer-to-includer': convertReplacerToIncluder,
|
|
186
187
|
'remove-useless-match': removeUselessMatch,
|
|
188
|
+
'remove-useless-type-check-declaration': removeUselessTypeCheckDeclaration,
|
|
187
189
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {types} from 'putout';
|
|
2
|
+
|
|
3
|
+
export const report = () => `Avoid useless 'is-' declaration`;
|
|
4
|
+
|
|
5
|
+
export const match = () => ({
|
|
6
|
+
'const __a = (__b) => __b.type === "__c"': check,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const replace = () => ({
|
|
10
|
+
'const __a = (__b) => __b.type === "__c"': '',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function check({__a, __c}) {
|
|
14
|
+
const name = `is${__c.value}`;
|
|
15
|
+
|
|
16
|
+
if (!types[name])
|
|
17
|
+
return false;
|
|
18
|
+
|
|
19
|
+
return name === __a.name;
|
|
20
|
+
}
|
package/package.json
CHANGED