@putout/plugin-putout 29.23.0 → 29.25.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 +29 -1
- package/lib/add-traverse-args/index.js +1 -1
- package/lib/apply-fixture-name-to-message/index.js +13 -16
- package/lib/apply-fixture-name-to-message/test-checker.js +12 -0
- package/lib/apply-string-to-property-key/index.js +34 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ npm i @putout/plugin-putout -D
|
|
|
27
27
|
- ✅ [apply-async-formatter](#apply-async-formatter);
|
|
28
28
|
- ✅ [apply-get-binding](#apply-get-binding);
|
|
29
29
|
- ✅ [apply-create-test](#apply-create-test);
|
|
30
|
+
- ✅ [apply-string-to-property-key](#apply-string-to-property-key);
|
|
30
31
|
- ✅ [apply-create-nested-directory](#apply-create-nested-directory);
|
|
31
32
|
- ✅ [apply-declare](#apply-declare);
|
|
32
33
|
- ✅ [apply-destructuring](#apply-destructuring);
|
|
@@ -117,9 +118,9 @@ npm i @putout/plugin-putout -D
|
|
|
117
118
|
"putout/add-crawl-file": "on",
|
|
118
119
|
"putout/add-track-file": "on",
|
|
119
120
|
"putout/add-await-to-progress": "on",
|
|
121
|
+
"putout/apply-async-formatter": "on",
|
|
120
122
|
"putout/apply-create-test": "on",
|
|
121
123
|
"putout/apply-create-nested-directory": "on",
|
|
122
|
-
"putout/apply-async-formatter": "on",
|
|
123
124
|
"putout/apply-declare": "on",
|
|
124
125
|
"putout/apply-destructuring": "on",
|
|
125
126
|
"putout/apply-destructuring-to-options": "on",
|
|
@@ -134,6 +135,7 @@ npm i @putout/plugin-putout -D
|
|
|
134
135
|
"putout/apply-rename": "on",
|
|
135
136
|
"putout/apply-parens": "on",
|
|
136
137
|
"putout/apply-remove": "on",
|
|
138
|
+
"putout/apply-string-to-property-key": "on",
|
|
137
139
|
"putout/apply-transform-with-options": "on",
|
|
138
140
|
"putout/apply-insert-before": "on",
|
|
139
141
|
"putout/apply-traverser-to-ignore": "on",
|
|
@@ -260,6 +262,32 @@ t.report('a', 'Use b');
|
|
|
260
262
|
t.noReport('a');
|
|
261
263
|
```
|
|
262
264
|
|
|
265
|
+
## apply-string-to-property-key
|
|
266
|
+
|
|
267
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/46e3930cbdf32d316c0c6cb21eb59f5a/aecd754638d0bac8252048a4f4b3131c15ef6c6f).
|
|
268
|
+
|
|
269
|
+
### ❌ Example of incorrect code
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
export const replace = {
|
|
273
|
+
[`section('@select', select(__args))`]: ({__args}, path) => {
|
|
274
|
+
__args.unshift(identifier('id'));
|
|
275
|
+
return path;
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### ✅ Example of correct code
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
export const replace = {
|
|
284
|
+
'section("@select", select(__args))"': ({__args}, path) => {
|
|
285
|
+
__args.unshift(identifier('id'));
|
|
286
|
+
return path;
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
```
|
|
290
|
+
|
|
263
291
|
## apply-transform-with-options
|
|
264
292
|
|
|
265
293
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/92d40d40c75481816a5b5507e01d8315/bb54e932b4fff4bc0b453d723c72c7a9ed796b98).
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import {operator} from 'putout';
|
|
2
2
|
import regexpEscapePolifyll from 'regexp.escape';
|
|
3
|
+
import {
|
|
4
|
+
isTest,
|
|
5
|
+
isTestAsync,
|
|
6
|
+
isTestDestructuring,
|
|
7
|
+
isTestOnly,
|
|
8
|
+
} from './test-checker.js';
|
|
3
9
|
|
|
4
10
|
const {
|
|
5
11
|
escape = regexpEscapePolifyll,
|
|
6
12
|
} = RegExp;
|
|
7
13
|
|
|
8
|
-
const {
|
|
9
|
-
setLiteralValue,
|
|
10
|
-
compare,
|
|
11
|
-
} = operator;
|
|
14
|
+
const {setLiteralValue} = operator;
|
|
12
15
|
|
|
13
16
|
const FIXTURE = [
|
|
14
17
|
'report',
|
|
15
18
|
'transform',
|
|
19
|
+
'comparePlaces',
|
|
16
20
|
];
|
|
17
21
|
|
|
18
22
|
const NAMES = [
|
|
@@ -41,6 +45,7 @@ export const match = () => ({
|
|
|
41
45
|
't.noTransform(__a)': check,
|
|
42
46
|
't.noReportWithOptions(__a, __b)': check,
|
|
43
47
|
'transform(__a)': check,
|
|
48
|
+
'comparePlaces(__a, __b)': check,
|
|
44
49
|
'noReportAfterTransform(__a)': check,
|
|
45
50
|
});
|
|
46
51
|
|
|
@@ -58,18 +63,7 @@ export const replace = () => ({
|
|
|
58
63
|
't.noReportWithOptions(__a, __b)': transform,
|
|
59
64
|
'transform(__a)': transform,
|
|
60
65
|
'noReportAfterTransform(__a)': transform,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const isTest = (path) => compare(path, 'test(__a, (t) => __body)', {
|
|
64
|
-
findUp: false,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const isTestDestructuring = (path) => compare(path, 'test(__a, ({__b}) => __body)', {
|
|
68
|
-
findUp: false,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const isTestOnly = (path) => compare(path, 'test.only(__a, (t) => __body)', {
|
|
72
|
-
findUp: false,
|
|
66
|
+
'comparePlaces(__a, __b)': transform,
|
|
73
67
|
});
|
|
74
68
|
|
|
75
69
|
const check = ({__a}, path) => {
|
|
@@ -123,6 +117,9 @@ const getTestNodeArgument = (path) => {
|
|
|
123
117
|
if (!testPath)
|
|
124
118
|
testPath = path.find(isTestDestructuring);
|
|
125
119
|
|
|
120
|
+
if (!testPath)
|
|
121
|
+
testPath = path.find(isTestAsync);
|
|
122
|
+
|
|
126
123
|
if (!testPath)
|
|
127
124
|
return {
|
|
128
125
|
value: '',
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {compare} = operator;
|
|
4
|
+
|
|
5
|
+
const buildTestChecker = (a) => (b) => compare(b, a, {
|
|
6
|
+
findUp: false,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const isTest = buildTestChecker('test(__a, (t) => __body)');
|
|
10
|
+
export const isTestAsync = buildTestChecker('test(__a, async (__b) => __body)');
|
|
11
|
+
export const isTestDestructuring = buildTestChecker('test(__a, ({__b}) => __body)');
|
|
12
|
+
export const isTestOnly = buildTestChecker('test.only(__a, (t) => __body)');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isTemplateLiteral,
|
|
5
|
+
stringLiteral,
|
|
6
|
+
} = types;
|
|
7
|
+
|
|
8
|
+
const {replaceWith} = operator;
|
|
9
|
+
|
|
10
|
+
export const report = () => `Use 'string' instead of 'template' in property key`;
|
|
11
|
+
|
|
12
|
+
export const fix = (path) => {
|
|
13
|
+
const {quasis} = path.node;
|
|
14
|
+
const [first] = quasis;
|
|
15
|
+
const value = first.value.cooked.replaceAll(`'`, '"');
|
|
16
|
+
|
|
17
|
+
replaceWith(path, stringLiteral(value));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const traverse = ({push}) => ({
|
|
21
|
+
ObjectProperty(path) {
|
|
22
|
+
const keyPath = path.get('key');
|
|
23
|
+
|
|
24
|
+
if (!isTemplateLiteral(keyPath))
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
const {quasis} = keyPath.node;
|
|
28
|
+
|
|
29
|
+
if (quasis.length > 1)
|
|
30
|
+
return;
|
|
31
|
+
|
|
32
|
+
push(keyPath);
|
|
33
|
+
},
|
|
34
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyStringToPropertyKey from './apply-string-to-property-key/index.js';
|
|
1
2
|
import * as convertTraverseToSuperTraverse from './convert-traverse-to-super-traverse/index.js';
|
|
2
3
|
import * as applyDestructuringToOptions from './apply-destructuring-to-options/index.js';
|
|
3
4
|
import * as applyGetBinding from './apply-get-binding/index.js';
|
|
@@ -174,4 +175,5 @@ export const rules = {
|
|
|
174
175
|
'apply-get-binding': applyGetBinding,
|
|
175
176
|
'apply-destructuring-to-options': applyDestructuringToOptions,
|
|
176
177
|
'convert-traverse-to-super-traverse': convertTraverseToSuperTraverse,
|
|
178
|
+
'apply-string-to-property-key': applyStringToPropertyKey,
|
|
177
179
|
};
|
package/package.json
CHANGED