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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2026.08.30, v4.8.0
2
+
3
+ feature:
4
+ - c2c4c2a redput: write-readme: insert-rule-config
5
+
6
+ 2026.08.30, v4.7.0
7
+
8
+ feature:
9
+ - 8748c6b redput: insert-rule-link: add
10
+
1
11
  2026.08.29, v4.6.0
2
12
 
3
13
  fix:
@@ -14,7 +14,7 @@ export const runRule = (ruleSource, source) => {
14
14
  },
15
15
  });
16
16
 
17
- plugin.report = plugin.report ?? noop;
17
+ plugin.report = plugin.report || noop;
18
18
 
19
19
  const {code} = putout(source, {
20
20
  cache: false,
@@ -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 ?? data);
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 ?? data);
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 [{source}] = list;
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(1)
49
+ .slice(2)
42
50
  .map(getSource),
43
51
  incorrect,
44
52
  correct,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redput",
3
- "version": "4.6.0",
3
+ "version": "4.8.0",
4
4
  "description": "CLI tool to convert source from 🐊Putout Editor to files",
5
5
  "main": "lib/redput.js",
6
6
  "bin": {