redput 4.6.0 → 4.8.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/ChangeLog +10 -0
- package/lib/run-rule/run-rule.js +1 -1
- package/lib/write/nested/nested.js +2 -2
- package/lib/write/nested/write-readme/README.md +4 -0
- package/lib/write/nested/write-readme/insert-rule-config/insert-rule-config.js +28 -0
- package/lib/write/nested/write-readme/insert-rule-link/index.js +57 -0
- package/lib/write/nested/write-readme/write-readme.js +10 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/run-rule/run-rule.js
CHANGED
|
@@ -37,7 +37,7 @@ export const writeNestedFixtures = async (name, data, ext, correct, overrides =
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
await write(`./${name}/fixture/${name}.${ext}`, data);
|
|
40
|
-
await write(`./${name}/fixture/${name}-fix.${ext}`, correct
|
|
40
|
+
await write(`./${name}/fixture/${name}-fix.${ext}`, correct || data);
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export const writeNestedTests = async (name, report) => {
|
|
@@ -95,5 +95,5 @@ export const updateOverallNestedFixtures = async (name, data, ext, correct, over
|
|
|
95
95
|
const {write = writeFile} = overrides;
|
|
96
96
|
|
|
97
97
|
await write(`../test/fixture/${name}.${ext}`, data);
|
|
98
|
-
await write(`../test/fixture/${name}-fix.${ext}`, correct
|
|
98
|
+
await write(`../test/fixture/${name}-fix.${ext}`, correct || data);
|
|
99
99
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Rules
|
|
2
|
+
|
|
3
|
+
- ✅ [insert-rule-link](https://putout.cloudcmd.io/#/gist/8626a1a61f46226f315eac8d6e08e61c/2898e049b8b2664e10eca1ddc2373feb45b67c85);
|
|
4
|
+
- ✅ [insert-rule-section](https://putout.cloudcmd.io/#/gist/4a0650e6b06735128cc2eaf4ad060c33/7ad2a3a767918b3a7d6bac77113b1ce2e3ff72c2);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {stringify} = JSON;
|
|
4
|
+
const {assign, keys} = Object;
|
|
5
|
+
const {fromJS, toJS} = operator;
|
|
6
|
+
|
|
7
|
+
export function maybeInsertRuleToJson(name, json) {
|
|
8
|
+
if (!json)
|
|
9
|
+
return [];
|
|
10
|
+
|
|
11
|
+
if (json.extension !== 'json')
|
|
12
|
+
return [];
|
|
13
|
+
|
|
14
|
+
const result = toJS(insertRuleToJson(name, fromJS(json.source)));
|
|
15
|
+
|
|
16
|
+
return [result];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function insertRuleToJson(name, json) {
|
|
20
|
+
const object = JSON.parse(json);
|
|
21
|
+
const [plugin] = keys(object.rules)[0].split('/');
|
|
22
|
+
|
|
23
|
+
assign(object.rules, {
|
|
24
|
+
[`${plugin}/${name}`]: 'on',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return stringify(object, null, 4);
|
|
28
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {template, operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
compare,
|
|
5
|
+
__markdown,
|
|
6
|
+
insertAfter,
|
|
7
|
+
} = operator;
|
|
8
|
+
|
|
9
|
+
export const report = ({name}) => `insert '#${name}' link to Rules`;
|
|
10
|
+
|
|
11
|
+
export const fix = ({name, rules}) => {
|
|
12
|
+
const nodeLink = template.ast(`ul(li('✅ ', link('${name}', '#${name}')))`);
|
|
13
|
+
insertAfter(rules, nodeLink);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const traverse = ({options, push}) => {
|
|
17
|
+
const {name = 'hello'} = options;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
[__markdown]: (path) => {
|
|
21
|
+
const elements = path.get('arguments.0.elements');
|
|
22
|
+
const {rules, link} = parseElements(elements, name);
|
|
23
|
+
|
|
24
|
+
if (link)
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
if (!rules)
|
|
28
|
+
return;
|
|
29
|
+
|
|
30
|
+
push({
|
|
31
|
+
path,
|
|
32
|
+
name,
|
|
33
|
+
rules,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function parseElements(elements, name) {
|
|
40
|
+
let link;
|
|
41
|
+
let rules;
|
|
42
|
+
|
|
43
|
+
for (const element of elements) {
|
|
44
|
+
if (compare(element, `ul(li('✅ ', link('${name}', '#${name}')))`)) {
|
|
45
|
+
link = element;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (compare(element, `heading(2, 'Rules')`))
|
|
50
|
+
rules = element;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
link,
|
|
55
|
+
rules,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -4,6 +4,8 @@ import process from 'node:process';
|
|
|
4
4
|
import {putout} from 'putout';
|
|
5
5
|
import {branch, merge} from '@putout/processor-markdown';
|
|
6
6
|
import * as insertRuleSection from './insert-rule-section/index.js';
|
|
7
|
+
import * as insertRuleLink from './insert-rule-link/index.js';
|
|
8
|
+
import {maybeInsertRuleToJson} from './insert-rule-config/insert-rule-config.js';
|
|
7
9
|
|
|
8
10
|
const README = 'README.md';
|
|
9
11
|
const getSource = (a) => a.source;
|
|
@@ -19,7 +21,8 @@ export const writeReadme = async (name, link, correct, incorrect, overrides = {}
|
|
|
19
21
|
const readme = await read(readmePath, 'utf8');
|
|
20
22
|
|
|
21
23
|
const list = await branch(readme);
|
|
22
|
-
const [
|
|
24
|
+
const [markdown, json] = list;
|
|
25
|
+
const {source} = markdown;
|
|
23
26
|
|
|
24
27
|
const {code} = putout(source, {
|
|
25
28
|
rules: {
|
|
@@ -29,16 +32,21 @@ export const writeReadme = async (name, link, correct, incorrect, overrides = {}
|
|
|
29
32
|
correct,
|
|
30
33
|
incorrect,
|
|
31
34
|
}],
|
|
35
|
+
'insert-rule-link': ['on', {
|
|
36
|
+
name,
|
|
37
|
+
}],
|
|
32
38
|
},
|
|
33
39
|
plugins: [
|
|
34
40
|
['insert-rule-section', insertRuleSection],
|
|
41
|
+
['insert-rule-link', insertRuleLink],
|
|
35
42
|
],
|
|
36
43
|
});
|
|
37
44
|
|
|
38
45
|
const newList = [
|
|
39
46
|
code,
|
|
47
|
+
...maybeInsertRuleToJson(name, json),
|
|
40
48
|
...list
|
|
41
|
-
.slice(
|
|
49
|
+
.slice(2)
|
|
42
50
|
.map(getSource),
|
|
43
51
|
incorrect,
|
|
44
52
|
correct,
|