redput 1.13.0 → 1.15.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
+ 2023.11.28, v1.15.0
2
+
3
+ feature:
4
+ - ec9c667 redput: add ability to disable rules in index
5
+
6
+ 2023.11.28, v1.14.0
7
+
8
+ feature:
9
+ - daae14d redput: add ability to pass options
10
+
1
11
  2023.11.21, v1.13.0
2
12
 
3
13
  feature:
@@ -1,11 +1,30 @@
1
+ import tryCatch from 'try-catch';
2
+
3
+ const {parse} = JSON;
4
+
1
5
  export const parsePlugin = (raw) => {
2
6
  const [comment, ...lines] = raw.split('\n');
3
- const name = comment
4
- .replace('//', '')
5
- .trimStart();
7
+ const [options, name] = parseComment(comment);
6
8
 
7
9
  return {
8
10
  name,
9
11
  lines,
12
+ options,
10
13
  };
11
14
  };
15
+
16
+ function parseComment(comment) {
17
+ const raw = comment
18
+ .replace('//', '')
19
+ .trimStart();
20
+
21
+ const [error, data] = tryCatch(parse, raw);
22
+
23
+ if (error)
24
+ return ['', raw];
25
+
26
+ return [
27
+ data[0],
28
+ data[1],
29
+ ];
30
+ }
package/lib/redput.js CHANGED
@@ -21,17 +21,17 @@ export const redput = async (link, {token}) => {
21
21
  const raw = result.data.files['transform.js'].content;
22
22
  const fixture = result.data.files['source.js'].content;
23
23
 
24
- const {name, lines} = parsePlugin(raw);
25
-
26
- if (name.includes(':') || name.includes('{'))
27
- return [
28
- Error(`Bad name: ${name}`),
29
- ];
24
+ const {
25
+ name,
26
+ options,
27
+ lines,
28
+ } = parsePlugin(raw);
30
29
 
31
30
  const rule = lines.join('\n');
32
31
  const report = getReport(rule);
33
32
 
34
33
  const [errorWrite] = await tryToCatch(writePlugin, name, {
34
+ options,
35
35
  rule,
36
36
  fixture,
37
37
  report,
@@ -14,7 +14,7 @@ import {
14
14
  } from './simple.js';
15
15
  import tryToCatch from 'try-to-catch';
16
16
 
17
- export const writePlugin = async (name, {rule, fixture, report}) => {
17
+ export const writePlugin = async (name, {rule, fixture, report, options}) => {
18
18
  const [isNested] = await tryToCatch(access, './package.json');
19
19
 
20
20
  if (isNested)
@@ -22,6 +22,7 @@ export const writePlugin = async (name, {rule, fixture, report}) => {
22
22
  rule,
23
23
  fixture,
24
24
  report,
25
+ options,
25
26
  });
26
27
 
27
28
  await writeSimple(name, {
@@ -31,18 +32,19 @@ export const writePlugin = async (name, {rule, fixture, report}) => {
31
32
  });
32
33
  };
33
34
 
34
- export const writeNested = async (name, {rule, fixture, report}) => {
35
- await writeNestedRule(name, rule);
35
+ export const writeNested = async (name, {rule, fixture, report, options}) => {
36
+ await writeNestedRule(name, rule, options);
36
37
  await writeNestedFixtures(name, fixture);
37
38
  await writeNestedTests(name, report);
38
39
 
39
40
  await tryToCatch(writeNestedOptional, name, {
41
+ options,
40
42
  fixture,
41
43
  });
42
44
  };
43
45
 
44
- export const writeNestedOptional = async (name, {fixture}) => {
45
- await updateNestedIndex(name);
46
+ export const writeNestedOptional = async (name, {options, fixture}) => {
47
+ await updateNestedIndex(name, options);
46
48
  await updateOverallNestedFixtures(name, fixture);
47
49
  await updateOverallNestedTest(name);
48
50
  };
@@ -3,11 +3,15 @@ import * as insertGetRulePlugin from './plugin-insert-get-rule/index.js';
3
3
  import pluginPutout from '@putout/plugin-putout';
4
4
  import removeUnusedVariables from '@putout/plugin-remove-unused-variables';
5
5
 
6
- export const addRule = (name, source) => {
6
+ export const addRule = (name, source, ruleOptions) => {
7
7
  const {code} = putout(source, {
8
8
  rules: {
9
9
  'add-rule': ['on', {
10
10
  name,
11
+ ruleOptions,
12
+ }],
13
+ 'putout/declare': ['on', {
14
+ dismiss: 'getRule',
11
15
  }],
12
16
  },
13
17
  plugins: [
@@ -10,6 +10,7 @@ const {traverse} = operator;
10
10
  export const report = () => `Insert 'getRule()'`;
11
11
 
12
12
  const createRule = template('getRule(%%name%%)');
13
+ const createRuleWithOptions = template('getRule(%%name%%, "off")');
13
14
 
14
15
  export const match = ({options}) => ({
15
16
  'module.exports.rules = __object': ({__object}) => {
@@ -20,6 +21,9 @@ export const match = ({options}) => ({
20
21
  [`getRule('${name}')`]: () => {
21
22
  exists = true;
22
23
  },
24
+ [`getRule('${name}', 'off')`]: () => {
25
+ exists = true;
26
+ },
23
27
  });
24
28
 
25
29
  return !exists;
@@ -28,7 +32,17 @@ export const match = ({options}) => ({
28
32
 
29
33
  export const replace = ({options}) => ({
30
34
  'module.exports.rules = __object': ({__object}, path) => {
31
- const {name} = options;
35
+ const {name, ruleOptions} = options;
36
+
37
+ if (ruleOptions) {
38
+ const node = SpreadElement(createRuleWithOptions({
39
+ name: StringLiteral(name),
40
+ }));
41
+
42
+ __object.properties.push(node);
43
+ return path;
44
+ }
45
+
32
46
  const node = SpreadElement(createRule({
33
47
  name: StringLiteral(name),
34
48
  }));
@@ -47,9 +47,9 @@ export const writeNestedTests = async (name, report) => {
47
47
  }));
48
48
  };
49
49
 
50
- export const updateNestedIndex = async (name) => {
50
+ export const updateNestedIndex = async (name, options) => {
51
51
  const source = await readFile('./index.js', 'utf8');
52
- const code = addRule(name, source);
52
+ const code = addRule(name, source, options);
53
53
  await writeFile(`./index.js`, code);
54
54
  };
55
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redput",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "CLI tool to convert source from 🐊Putout Editor to files",
5
5
  "main": "lib/redput.js",
6
6
  "bin": {
@@ -65,6 +65,7 @@
65
65
  "octokit": "^3.1.0",
66
66
  "putout": "^33.9.1",
67
67
  "rendy": "^4.1.3",
68
+ "try-catch": "^3.0.1",
68
69
  "try-to-catch": "^3.0.1"
69
70
  },
70
71
  "devDependencies": {