@putout/plugin-putout 26.11.0 → 26.13.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
@@ -41,6 +41,7 @@ npm i @putout/plugin-putout -D
41
41
  - ✅ [apply-rename](#apply-rename);
42
42
  - ✅ [apply-parens](#apply-parens);
43
43
  - ✅ [apply-short-processors](#apply-short-processors);
44
+ - ✅ [apply-transform-with-options](#apply-transform-with-options);
44
45
  - ✅ [check-match](#check-match);
45
46
  - ✅ [check-declare](#check-declare);
46
47
  - ✅ [check-replace-code](#check-replace-code);
@@ -109,6 +110,7 @@ npm i @putout/plugin-putout -D
109
110
  "putout/apply-rename": "on",
110
111
  "putout/apply-parens": "on",
111
112
  "putout/apply-remove": "on",
113
+ "putout/apply-transform-with-options": "on",
112
114
  "putout/apply-insert-before": "on",
113
115
  "putout/apply-insert-after": "on",
114
116
  "putout/apply-vars": "on",
@@ -210,6 +212,28 @@ t.report('a', 'Use b');
210
212
  t.noReport('a');
211
213
  ```
212
214
 
215
+ ## apply-transform-with-options
216
+
217
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/92d40d40c75481816a5b5507e01d8315/bb54e932b4fff4bc0b453d723c72c7a9ed796b98).
218
+
219
+ ### ❌ Example of incorrect code
220
+
221
+ ```js
222
+ t.transform('submenu', {
223
+ submenuIndex: 1,
224
+ insideSubmenu: true,
225
+ });
226
+ ```
227
+
228
+ ### ✅ Example of correct code
229
+
230
+ ```js
231
+ t.transformWithOptions('submenu', {
232
+ submenuIndex: 1,
233
+ insideSubmenu: true,
234
+ });
235
+ ```
236
+
213
237
  ## apply-processors-destructuring
214
238
 
215
239
  ### ❌ Example of incorrect code
@@ -45,6 +45,14 @@ export const match = () => ({
45
45
 
46
46
  return isObjectExpression(__b);
47
47
  },
48
+ 't.report(__a, __b, __c)': ({__c}) => {
49
+ if (!isObjectExpression(__c))
50
+ return false;
51
+
52
+ const [first] = __c.properties;
53
+
54
+ return !isIdentifier(first.value);
55
+ },
48
56
  });
49
57
  export const replace = () => ({
50
58
  't.noReport(__a, "__b")': 't.noReport(__a)',
@@ -66,6 +74,7 @@ export const replace = () => ({
66
74
  return path;
67
75
  },
68
76
  't.report(__a)': 't.noReport(__a)',
77
+ 't.report(__a, __b, __c)': 't.reportWithOptions(__a, __b, __c)',
69
78
  't.noReportWithOptions(__a)': 't.noReport(__a)',
70
79
  't.noReportWithOptions(__a, __b, __c)': 't.noReportWithOptions(__a, __c)',
71
80
  });
@@ -0,0 +1,27 @@
1
+ import {types} from 'putout';
2
+
3
+ const {
4
+ isLiteral,
5
+ isObjectExpression,
6
+ } = types;
7
+
8
+ export const report = () => `Use 'transformWithOptions()' instead of 'transform()'`;
9
+
10
+ export const match = () => ({
11
+ 't.transform(__a, __b)': ({__b}) => {
12
+ if (!isObjectExpression(__b))
13
+ return false;
14
+
15
+ if (!__b.properties.length)
16
+ return false;
17
+
18
+ const [first] = __b.properties;
19
+
20
+ return isLiteral(first.value);
21
+ },
22
+ });
23
+
24
+ export const replace = () => ({
25
+ 't.transform(__a, __b)': 't.transformWithOptions(__a, __b)',
26
+ 't.transformWithOptions(__a)': 't.transform(__a)',
27
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as applyTransformWithOptions from './apply-transform-with-options/index.js';
1
2
  import * as convertPluginsElementToTuple from './convert-plugins-element-to-tuple/index.js';
2
3
  import * as removeEmptyObjectFromTransform from './remove-empty-object-from-transform/index.js';
3
4
  import * as applyExports from './apply-exports/index.js';
@@ -140,4 +141,5 @@ export const rules = {
140
141
  'apply-exports': ['off', applyExports],
141
142
  'remove-empty-object-from-transform': removeEmptyObjectFromTransform,
142
143
  'convert-plugins-element-to-tuple': convertPluginsElementToTuple,
144
+ 'apply-transform-with-options': applyTransformWithOptions,
143
145
  };
@@ -17,7 +17,7 @@ const INCORRECT = {
17
17
  NO_REPORT: /: (no report after transform|report|(transform|no transform)(\swith options)?)/,
18
18
  NO_REPORT_AFTER_TRANSFORM: /: (report|transform|no transform|no report)/,
19
19
  NO_REPORT_WITH_OPTIONS: /: (no report after transform(\swith options)?|report|transform|no transform|no report)/,
20
- TRANSFORM: /: (no report after transform|no transform|report|no report)/,
20
+ TRANSFORM: /: (transform with options|no report after transform|no transform|report|no report)/,
21
21
  NO_TRANSFORM: /: (no report after transform|transform|report|no report)/,
22
22
  TRANSFORM_WITH_OPTIONS: /: (no report after transform|transform|no transform(\swith options)?|report|no report)/,
23
23
  NO_TRANSFORM_WITH_OPTIONS: /: (no report after transform|transform(\swith options)?|no transform|report|no report)/,
@@ -109,10 +109,19 @@ function isCorrect({path, correct, incorrect}) {
109
109
 
110
110
  const {value} = messagePath.node;
111
111
 
112
- if (value.includes(correct))
112
+ if (containsCorrect(value, correct))
113
113
  return [CORRECT];
114
114
 
115
115
  const is = !incorrect.test(value);
116
116
 
117
117
  return [is, messagePath];
118
118
  }
119
+
120
+ function containsCorrect(value, correct) {
121
+ if (!value.includes(correct))
122
+ return false;
123
+
124
+ const nextIndex = value.indexOf(correct) + correct.length;
125
+
126
+ return value.charAt(nextIndex) !== ' ';
127
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "26.11.0",
3
+ "version": "26.13.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",