@putout/plugin-putout 26.10.0 → 26.12.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 +24 -0
- package/lib/apply-report/index.js +11 -1
- package/lib/apply-transform-with-options/index.js +26 -0
- package/lib/index.js +2 -0
- package/package.json +1 -2
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
|
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
isTemplateLiteral,
|
|
9
9
|
stringLiteral,
|
|
10
10
|
isArrayExpression,
|
|
11
|
+
isIdentifier,
|
|
11
12
|
} = types;
|
|
12
13
|
|
|
13
14
|
const {compare} = operator;
|
|
@@ -44,6 +45,14 @@ export const match = () => ({
|
|
|
44
45
|
|
|
45
46
|
return isObjectExpression(__b);
|
|
46
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
|
+
},
|
|
47
56
|
});
|
|
48
57
|
export const replace = () => ({
|
|
49
58
|
't.noReport(__a, "__b")': 't.noReport(__a)',
|
|
@@ -53,7 +62,7 @@ export const replace = () => ({
|
|
|
53
62
|
|
|
54
63
|
const {value} = __b.properties[0];
|
|
55
64
|
|
|
56
|
-
if (isArrayExpression(value))
|
|
65
|
+
if (isArrayExpression(value) || !isIdentifier(value))
|
|
57
66
|
return 't.noReportWithOptions(__a, __b)';
|
|
58
67
|
|
|
59
68
|
const name = toKebabCase(value.name);
|
|
@@ -65,6 +74,7 @@ export const replace = () => ({
|
|
|
65
74
|
return path;
|
|
66
75
|
},
|
|
67
76
|
't.report(__a)': 't.noReport(__a)',
|
|
77
|
+
't.report(__a, __b, __c)': 't.reportWithOptions(__a, __b, __c)',
|
|
68
78
|
't.noReportWithOptions(__a)': 't.noReport(__a)',
|
|
69
79
|
't.noReportWithOptions(__a, __b, __c)': 't.noReportWithOptions(__a, __c)',
|
|
70
80
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
});
|
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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.12.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",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"@putout/plugin-tape": "*",
|
|
50
50
|
"@putout/test": "^14.0.0",
|
|
51
51
|
"c8": "^10.0.0",
|
|
52
|
-
"chalk": "^5.3.0",
|
|
53
52
|
"eslint": "^9.0.0",
|
|
54
53
|
"eslint-plugin-n": "^17.0.0",
|
|
55
54
|
"eslint-plugin-putout": "^28.0.0",
|