@putout/plugin-putout 29.25.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
|
@@ -102,6 +102,10 @@ npm i @putout/plugin-putout -D
|
|
|
102
102
|
- ✅ [shorten-imports](#shorten-imports);
|
|
103
103
|
- ✅ [simplify-replace-template](#simplify-replace-template);
|
|
104
104
|
|
|
105
|
+
## File rules
|
|
106
|
+
|
|
107
|
+
- ✅ [sort-readme-file](#sort-readme-file);
|
|
108
|
+
|
|
105
109
|
## Config
|
|
106
110
|
|
|
107
111
|
```json
|
|
@@ -180,7 +184,6 @@ npm i @putout/plugin-putout -D
|
|
|
180
184
|
"putout/convert-plugins-element-to-tuple": "on",
|
|
181
185
|
"putout/convert-push-object-to-push-path": "on",
|
|
182
186
|
"putout/create-test": "on",
|
|
183
|
-
"putout/shorten-imports": "on",
|
|
184
187
|
"putout/declare": "on",
|
|
185
188
|
"putout/declare-template-variables": "on",
|
|
186
189
|
"putout/declare-path-variable": "on",
|
|
@@ -193,7 +196,9 @@ npm i @putout/plugin-putout -D
|
|
|
193
196
|
"putout/remove-useless-printer-option": "on",
|
|
194
197
|
"putout/remove-useless-source-argument": "on",
|
|
195
198
|
"putout/remove-message-from-no-report-after-transform": "on",
|
|
196
|
-
"putout/simplify-replace-template": "on"
|
|
199
|
+
"putout/simplify-replace-template": "on",
|
|
200
|
+
"putout/shorten-imports": "on",
|
|
201
|
+
"putout/sort-readme-file": "on"
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
```
|
|
@@ -1217,6 +1222,23 @@ const parseOptions = require('putout/lib/parse-options');
|
|
|
1217
1222
|
const parseOptions = require('putout/parse-options');
|
|
1218
1223
|
```
|
|
1219
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
|
+
|
|
1220
1242
|
## convert-include-to-traverse
|
|
1221
1243
|
|
|
1222
1244
|
Checkout in 🐊[**Putout Editor*](https://putout.cloudcmd.io/#/gist/a41b5c943a74b59a6c18f31fc6d31937/d79c6084f49b6444536840bc2fc1fba725ba83f8).
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as sortReadmeFile from './sort-readme-file/index.js';
|
|
1
2
|
import * as applyStringToPropertyKey from './apply-string-to-property-key/index.js';
|
|
2
3
|
import * as convertTraverseToSuperTraverse from './convert-traverse-to-super-traverse/index.js';
|
|
3
4
|
import * as applyDestructuringToOptions from './apply-destructuring-to-options/index.js';
|
|
@@ -176,4 +177,5 @@ export const rules = {
|
|
|
176
177
|
'apply-destructuring-to-options': applyDestructuringToOptions,
|
|
177
178
|
'convert-traverse-to-super-traverse': convertTraverseToSuperTraverse,
|
|
178
179
|
'apply-string-to-property-key': applyStringToPropertyKey,
|
|
180
|
+
'sort-readme-file': sortReadmeFile,
|
|
179
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