@putout/plugin-putout 29.32.0 → 29.33.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 +21 -1
- package/lib/index.js +2 -0
- package/lib/remove-useless-match/index.js +27 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,6 +103,7 @@ npm i @putout/plugin-putout -D
|
|
|
103
103
|
- ✅ [shorten-imports](#shorten-imports);
|
|
104
104
|
- ✅ [simplify-replace-template](#simplify-replace-template);
|
|
105
105
|
- ✅ [convert-replacer-to-includer](#convert-replacer-to-includer);
|
|
106
|
+
- ✅ [remove-useless-match](#remove-useless-match);
|
|
106
107
|
|
|
107
108
|
## File rules
|
|
108
109
|
|
|
@@ -202,7 +203,8 @@ npm i @putout/plugin-putout -D
|
|
|
202
203
|
"putout/shorten-imports": "on",
|
|
203
204
|
"putout/simplify-replace-template": "on",
|
|
204
205
|
"putout/sort-readme-file": "on",
|
|
205
|
-
"putout/convert-replacer-to-includer": "on"
|
|
206
|
+
"putout/convert-replacer-to-includer": "on",
|
|
207
|
+
"putout/remove-useless-match": "on"
|
|
206
208
|
}
|
|
207
209
|
}
|
|
208
210
|
```
|
|
@@ -2299,6 +2301,24 @@ export const include = () => [
|
|
|
2299
2301
|
];
|
|
2300
2302
|
```
|
|
2301
2303
|
|
|
2304
|
+
## remove-useless-match
|
|
2305
|
+
|
|
2306
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a813e8b3da2ccbe949a3156842c3112e/5e21a147247c2451f9f826ba384d62ab37c17a01).
|
|
2307
|
+
|
|
2308
|
+
### ❌ Example of incorrect code
|
|
2309
|
+
|
|
2310
|
+
```js
|
|
2311
|
+
export const match = () => ({
|
|
2312
|
+
'const [__a, {__b}] = __c(__d, __e)': () => true,
|
|
2313
|
+
'const [__a, {__b = {}} = {}] = __c(__d, __e)': () => true,
|
|
2314
|
+
});
|
|
2315
|
+
```
|
|
2316
|
+
|
|
2317
|
+
### ✅ Example of correct code
|
|
2318
|
+
|
|
2319
|
+
```js
|
|
2320
|
+
```
|
|
2321
|
+
|
|
2302
2322
|
## License
|
|
2303
2323
|
|
|
2304
2324
|
MIT
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeUselessMatch from './remove-useless-match/index.js';
|
|
1
2
|
import * as convertReplacerToIncluder from './convert-replacer-to-includer/index.js';
|
|
2
3
|
import * as applyTypeCheck from './apply-type-check/index.js';
|
|
3
4
|
import * as sortReadmeFile from './sort-readme-file/index.js';
|
|
@@ -182,4 +183,5 @@ export const rules = {
|
|
|
182
183
|
'sort-readme-file': sortReadmeFile,
|
|
183
184
|
'apply-type-check': applyTypeCheck,
|
|
184
185
|
'convert-replacer-to-includer': convertReplacerToIncluder,
|
|
186
|
+
'remove-useless-match': removeUselessMatch,
|
|
185
187
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {compare, remove} = operator;
|
|
4
|
+
const {booleanLiteral} = types;
|
|
5
|
+
|
|
6
|
+
export const report = () => `Avoid useless 'match'`;
|
|
7
|
+
|
|
8
|
+
export const fix = (path) => {
|
|
9
|
+
remove(path);
|
|
10
|
+
};
|
|
11
|
+
export const traverse = ({push}) => ({
|
|
12
|
+
'export const match = () => __object': (path) => {
|
|
13
|
+
const __objectPath = path.get('declaration.declarations.0.init.body');
|
|
14
|
+
const properties = __objectPath.get('properties');
|
|
15
|
+
const boolean = booleanLiteral(true);
|
|
16
|
+
|
|
17
|
+
for (const property of properties) {
|
|
18
|
+
const {body} = property.node.value;
|
|
19
|
+
|
|
20
|
+
if (compare(body, boolean))
|
|
21
|
+
push(property);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!__objectPath.get('properties').length)
|
|
25
|
+
push(path);
|
|
26
|
+
},
|
|
27
|
+
});
|
package/package.json
CHANGED