@putout/plugin-putout 29.31.1 → 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 CHANGED
@@ -102,6 +102,8 @@ npm i @putout/plugin-putout -D
102
102
  - ✅ [replace-test-message](#replace-test-message);
103
103
  - ✅ [shorten-imports](#shorten-imports);
104
104
  - ✅ [simplify-replace-template](#simplify-replace-template);
105
+ - ✅ [convert-replacer-to-includer](#convert-replacer-to-includer);
106
+ - ✅ [remove-useless-match](#remove-useless-match);
105
107
 
106
108
  ## File rules
107
109
 
@@ -151,7 +153,6 @@ npm i @putout/plugin-putout -D
151
153
  "putout/apply-string-to-property-key": "on",
152
154
  "putout/apply-transform-with-options": "on",
153
155
  "putout/apply-traverser-to-ignore": "on",
154
-
155
156
  "putout/apply-type-check": "on",
156
157
  "putout/apply-vars": "on",
157
158
  "putout/check-declare": "on",
@@ -201,7 +202,9 @@ npm i @putout/plugin-putout -D
201
202
  "putout/replace-test-message": "on",
202
203
  "putout/shorten-imports": "on",
203
204
  "putout/simplify-replace-template": "on",
204
- "putout/sort-readme-file": "on"
205
+ "putout/sort-readme-file": "on",
206
+ "putout/convert-replacer-to-includer": "on",
207
+ "putout/remove-useless-match": "on"
205
208
  }
206
209
  }
207
210
  ```
@@ -2275,6 +2278,47 @@ if (a.type === 'CallExpression') {}
2275
2278
  if (isCallExpression(a)) {}
2276
2279
  ```
2277
2280
 
2281
+ ## convert-replacer-to-includer
2282
+
2283
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4b5e172466fda5e8fb114e767639f7ee/d3af95da4418b8c0e761d8cd50c1fa38a412b55c).
2284
+
2285
+ ### ❌ Example of incorrect code
2286
+
2287
+ ```js
2288
+ export const replace = () => ({
2289
+ 'const [__a, {__b}] = __c(__d, __e)': 'const [__a, {__b}] = __c(__d, __e)',
2290
+ 'const [__a, {__b = {}} = {}] = __c(__d, __e)': 'const [__a, {__b = {}} = {}] = __c(__d, __e)',
2291
+ });
2292
+ ```
2293
+
2294
+ ### ✅ Example of correct code
2295
+
2296
+ ```js
2297
+ export const fix = () => {};
2298
+ export const include = () => [
2299
+ 'const [__a, {__b}] = __c(__d, __e)',
2300
+ 'const [__a, {__b = {}} = {}] = __c(__d, __e)',
2301
+ ];
2302
+ ```
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
+
2278
2322
  ## License
2279
2323
 
2280
2324
  MIT
@@ -0,0 +1,61 @@
1
+ import {
2
+ template,
3
+ operator,
4
+ types,
5
+ } from 'putout';
6
+
7
+ const {
8
+ compare,
9
+ insertBefore,
10
+ replaceWith,
11
+ } = operator;
12
+
13
+ const {
14
+ stringLiteral,
15
+ arrayExpression,
16
+ } = types;
17
+
18
+ const createInclude = template('export const include = () => LIST');
19
+
20
+ export const report = () => `Use 'Includer' instead of 'Replacer'`;
21
+
22
+ export const fix = ({path, properties}) => {
23
+ const list = [];
24
+
25
+ for (const property of properties) {
26
+ const {key} = property.node;
27
+
28
+ list.push(key.value);
29
+ }
30
+
31
+ replaceWith(path, createInclude({
32
+ LIST: arrayExpression(list.map(stringLiteral)),
33
+ }));
34
+
35
+ insertBefore(path, template.ast('export const fix = () => {}'));
36
+ };
37
+ export const traverse = ({push}) => ({
38
+ 'export const replace = () => __object': (path) => {
39
+ const __objectPath = path.get('declaration.declarations.0.init.body');
40
+ const properties = __objectPath.get('properties');
41
+
42
+ for (const property of properties) {
43
+ const {
44
+ key,
45
+ value,
46
+ computed,
47
+ } = property.node;
48
+
49
+ if (computed)
50
+ return;
51
+
52
+ if (!compare(key, value))
53
+ return;
54
+ }
55
+
56
+ push({
57
+ path,
58
+ properties,
59
+ });
60
+ },
61
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import * as removeUselessMatch from './remove-useless-match/index.js';
2
+ import * as convertReplacerToIncluder from './convert-replacer-to-includer/index.js';
1
3
  import * as applyTypeCheck from './apply-type-check/index.js';
2
4
  import * as sortReadmeFile from './sort-readme-file/index.js';
3
5
  import * as applyStringToPropertyKey from './apply-string-to-property-key/index.js';
@@ -180,4 +182,6 @@ export const rules = {
180
182
  'apply-string-to-property-key': applyStringToPropertyKey,
181
183
  'sort-readme-file': sortReadmeFile,
182
184
  'apply-type-check': applyTypeCheck,
185
+ 'convert-replacer-to-includer': convertReplacerToIncluder,
186
+ 'remove-useless-match': removeUselessMatch,
183
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "29.31.1",
3
+ "version": "29.33.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",