@putout/plugin-putout 29.24.0 → 29.26.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
|
@@ -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);
|
|
@@ -101,6 +102,10 @@ npm i @putout/plugin-putout -D
|
|
|
101
102
|
- ✅ [shorten-imports](#shorten-imports);
|
|
102
103
|
- ✅ [simplify-replace-template](#simplify-replace-template);
|
|
103
104
|
|
|
105
|
+
## File rules
|
|
106
|
+
|
|
107
|
+
- ✅ [sort-readme-file](#sort-readme-file);
|
|
108
|
+
|
|
104
109
|
## Config
|
|
105
110
|
|
|
106
111
|
```json
|
|
@@ -117,9 +122,9 @@ npm i @putout/plugin-putout -D
|
|
|
117
122
|
"putout/add-crawl-file": "on",
|
|
118
123
|
"putout/add-track-file": "on",
|
|
119
124
|
"putout/add-await-to-progress": "on",
|
|
125
|
+
"putout/apply-async-formatter": "on",
|
|
120
126
|
"putout/apply-create-test": "on",
|
|
121
127
|
"putout/apply-create-nested-directory": "on",
|
|
122
|
-
"putout/apply-async-formatter": "on",
|
|
123
128
|
"putout/apply-declare": "on",
|
|
124
129
|
"putout/apply-destructuring": "on",
|
|
125
130
|
"putout/apply-destructuring-to-options": "on",
|
|
@@ -134,6 +139,7 @@ npm i @putout/plugin-putout -D
|
|
|
134
139
|
"putout/apply-rename": "on",
|
|
135
140
|
"putout/apply-parens": "on",
|
|
136
141
|
"putout/apply-remove": "on",
|
|
142
|
+
"putout/apply-string-to-property-key": "on",
|
|
137
143
|
"putout/apply-transform-with-options": "on",
|
|
138
144
|
"putout/apply-insert-before": "on",
|
|
139
145
|
"putout/apply-traverser-to-ignore": "on",
|
|
@@ -178,7 +184,6 @@ npm i @putout/plugin-putout -D
|
|
|
178
184
|
"putout/convert-plugins-element-to-tuple": "on",
|
|
179
185
|
"putout/convert-push-object-to-push-path": "on",
|
|
180
186
|
"putout/create-test": "on",
|
|
181
|
-
"putout/shorten-imports": "on",
|
|
182
187
|
"putout/declare": "on",
|
|
183
188
|
"putout/declare-template-variables": "on",
|
|
184
189
|
"putout/declare-path-variable": "on",
|
|
@@ -191,7 +196,9 @@ npm i @putout/plugin-putout -D
|
|
|
191
196
|
"putout/remove-useless-printer-option": "on",
|
|
192
197
|
"putout/remove-useless-source-argument": "on",
|
|
193
198
|
"putout/remove-message-from-no-report-after-transform": "on",
|
|
194
|
-
"putout/simplify-replace-template": "on"
|
|
199
|
+
"putout/simplify-replace-template": "on",
|
|
200
|
+
"putout/shorten-imports": "on",
|
|
201
|
+
"putout/sort-readme-file": "on"
|
|
195
202
|
}
|
|
196
203
|
}
|
|
197
204
|
```
|
|
@@ -260,6 +267,32 @@ t.report('a', 'Use b');
|
|
|
260
267
|
t.noReport('a');
|
|
261
268
|
```
|
|
262
269
|
|
|
270
|
+
## apply-string-to-property-key
|
|
271
|
+
|
|
272
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/46e3930cbdf32d316c0c6cb21eb59f5a/aecd754638d0bac8252048a4f4b3131c15ef6c6f).
|
|
273
|
+
|
|
274
|
+
### ❌ Example of incorrect code
|
|
275
|
+
|
|
276
|
+
```js
|
|
277
|
+
export const replace = {
|
|
278
|
+
[`section('@select', select(__args))`]: ({__args}, path) => {
|
|
279
|
+
__args.unshift(identifier('id'));
|
|
280
|
+
return path;
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### ✅ Example of correct code
|
|
286
|
+
|
|
287
|
+
```js
|
|
288
|
+
export const replace = {
|
|
289
|
+
'section("@select", select(__args))"': ({__args}, path) => {
|
|
290
|
+
__args.unshift(identifier('id'));
|
|
291
|
+
return path;
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
```
|
|
295
|
+
|
|
263
296
|
## apply-transform-with-options
|
|
264
297
|
|
|
265
298
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/92d40d40c75481816a5b5507e01d8315/bb54e932b4fff4bc0b453d723c72c7a9ed796b98).
|
|
@@ -1189,6 +1222,23 @@ const parseOptions = require('putout/lib/parse-options');
|
|
|
1189
1222
|
const parseOptions = require('putout/parse-options');
|
|
1190
1223
|
```
|
|
1191
1224
|
|
|
1225
|
+
## sort-readme-file
|
|
1226
|
+
|
|
1227
|
+
Checkout in 🐊**Putout Editor**:
|
|
1228
|
+
|
|
1229
|
+
- ✅ [`sort-contents`](https://putout.cloudcmd.io/#/gist/647bcc98ba9eeaa619dfa90d129ee0ec/a19ba868e8c2f97292e763675de65cc1ec98ff66);
|
|
1230
|
+
- ✅ [`sort-readme-file`](https://putout.cloudcmd.io/#/gist/ac5f8b64383dabd025f38f177b18b5d2/09751fd2e6659445ed8d8d2102f1d23090a18f49);
|
|
1231
|
+
|
|
1232
|
+
### ❌ Example of incorrect code
|
|
1233
|
+
|
|
1234
|
+
```diff
|
|
1235
|
+
## Rules
|
|
1236
|
+
-- ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode);
|
|
1237
|
+
-- ✅ [add-node-prefix](#add-node-prefix);
|
|
1238
|
+
+- ✅ [add-node-prefix](#add-node-prefix);
|
|
1239
|
+
+- ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode);
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1192
1242
|
## convert-include-to-traverse
|
|
1193
1243
|
|
|
1194
1244
|
Checkout in 🐊[**Putout Editor*](https://putout.cloudcmd.io/#/gist/a41b5c943a74b59a6c18f31fc6d31937/d79c6084f49b6444536840bc2fc1fba725ba83f8).
|
|
@@ -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,5 @@
|
|
|
1
|
+
import * as sortReadmeFile from './sort-readme-file/index.js';
|
|
2
|
+
import * as applyStringToPropertyKey from './apply-string-to-property-key/index.js';
|
|
1
3
|
import * as convertTraverseToSuperTraverse from './convert-traverse-to-super-traverse/index.js';
|
|
2
4
|
import * as applyDestructuringToOptions from './apply-destructuring-to-options/index.js';
|
|
3
5
|
import * as applyGetBinding from './apply-get-binding/index.js';
|
|
@@ -174,4 +176,6 @@ export const rules = {
|
|
|
174
176
|
'apply-get-binding': applyGetBinding,
|
|
175
177
|
'apply-destructuring-to-options': applyDestructuringToOptions,
|
|
176
178
|
'convert-traverse-to-super-traverse': convertTraverseToSuperTraverse,
|
|
179
|
+
'apply-string-to-property-key': applyStringToPropertyKey,
|
|
180
|
+
'sort-readme-file': sortReadmeFile,
|
|
177
181
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
import * as sortContents from './sort-contents/index.js';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
matchFiles,
|
|
6
|
+
getFilename,
|
|
7
|
+
getParentDirectory,
|
|
8
|
+
} = operator;
|
|
9
|
+
|
|
10
|
+
export const {
|
|
11
|
+
report,
|
|
12
|
+
scan,
|
|
13
|
+
fix,
|
|
14
|
+
} = matchFiles({
|
|
15
|
+
files: {
|
|
16
|
+
'README.md': {
|
|
17
|
+
plugins: [
|
|
18
|
+
['sort-contents', sortContents],
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
exclude: (file) => {
|
|
23
|
+
const dir = getParentDirectory(file);
|
|
24
|
+
const dirname = getFilename(dir);
|
|
25
|
+
|
|
26
|
+
return !/plugin-.*$/.test(dirname);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {compareAny} = operator;
|
|
4
|
+
const {entries} = Object;
|
|
5
|
+
|
|
6
|
+
export const report = () => `Sort 'contents'`;
|
|
7
|
+
|
|
8
|
+
export const fix = ({path, list}) => {
|
|
9
|
+
path.node.arguments = list;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const traverse = ({listStore, push}) => ({
|
|
13
|
+
'li("✅ ", link(__b, __c), ";")': (path) => {
|
|
14
|
+
const {parentPath} = path;
|
|
15
|
+
const prev = parentPath.getPrevSibling();
|
|
16
|
+
|
|
17
|
+
if (!compareAny(prev, [
|
|
18
|
+
`heading(2, 'Rules')`,
|
|
19
|
+
`heading(2, 'File rules')`,
|
|
20
|
+
]))
|
|
21
|
+
return;
|
|
22
|
+
|
|
23
|
+
listStore(path);
|
|
24
|
+
},
|
|
25
|
+
'Program': {
|
|
26
|
+
exit() {
|
|
27
|
+
const list = {};
|
|
28
|
+
const ids = {};
|
|
29
|
+
|
|
30
|
+
for (const {node, parentPath} of listStore()) {
|
|
31
|
+
const {line} = parentPath.node.loc.start;
|
|
32
|
+
|
|
33
|
+
ids[line] = parentPath;
|
|
34
|
+
|
|
35
|
+
list[line] = list[line] || [];
|
|
36
|
+
list[line].push(node);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const sortedList = {};
|
|
40
|
+
const resultList = [];
|
|
41
|
+
|
|
42
|
+
for (const [ul, currentList] of entries(list)) {
|
|
43
|
+
sortedList[ul] = currentList.toSorted(asc);
|
|
44
|
+
|
|
45
|
+
for (const [i, current] of sortedList[ul].entries()) {
|
|
46
|
+
if (current !== currentList[i]) {
|
|
47
|
+
resultList[ul] = sortedList[ul];
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const [id, list] of entries(resultList)) {
|
|
54
|
+
push({
|
|
55
|
+
path: ids[id],
|
|
56
|
+
list,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
function asc(a, b) {
|
|
64
|
+
return getValue(a).charCodeAt(0) - getValue(b).charCodeAt(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getValue(node) {
|
|
68
|
+
return node.arguments[1].arguments[0].value;
|
|
69
|
+
}
|
package/package.json
CHANGED