redput 3.0.1 → 3.1.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,9 @@
1
+ 2025.03.23, v3.1.0
2
+
3
+ feature:
4
+ - 803ea39 redput: @putout/plugin-nodejs v15.0.0
5
+ - f913157 redput: add-rule: esm
6
+
1
7
  2025.03.22, v3.0.1
2
8
 
3
9
  fix:
@@ -1,7 +1,7 @@
1
1
  import putout from 'putout';
2
2
  import * as pluginPutout from '@putout/plugin-putout';
3
- import nodejs from '@putout/plugin-nodejs';
4
- import removeUnusedVariables from '@putout/plugin-remove-unused-variables';
3
+ import * as nodejs from '@putout/plugin-nodejs';
4
+ import * as removeUnusedVariables from '@putout/plugin-remove-unused-variables';
5
5
  import * as insertGetRulePlugin from './plugin-insert-get-rule/index.js';
6
6
 
7
7
  export const addRule = (name, source, ruleOptions) => {
@@ -4,7 +4,11 @@ import {
4
4
  template,
5
5
  } from 'putout';
6
6
 
7
- const {spreadElement, stringLiteral} = types;
7
+ const {
8
+ spreadElement,
9
+ stringLiteral,
10
+ isSpreadElement,
11
+ } = types;
8
12
  const {traverse} = operator;
9
13
 
10
14
  export const report = () => `Insert 'getRule()'`;
@@ -12,43 +16,66 @@ export const report = () => `Insert 'getRule()'`;
12
16
  const createRule = template('getRule(%%name%%)');
13
17
  const createRuleWithOptions = template('getRule(%%name%%, "off")');
14
18
 
15
- export const match = ({options}) => ({
16
- 'module.exports.rules = __object': ({__object}) => {
17
- let exists = false;
18
- const {name} = options;
19
-
20
- traverse(__object, {
21
- [`getRule('${name}')`]: () => {
22
- exists = true;
23
- },
24
- [`getRule('${name}', 'off')`]: () => {
25
- exists = true;
26
- },
27
- });
28
-
29
- return !exists;
30
- },
31
- });
19
+ export const match = ({options}) => {
20
+ const check = createCheck(options);
21
+
22
+ return {
23
+ 'module.exports.rules = __object': check,
24
+ 'export const rules = __object': check,
25
+ };
26
+ };
32
27
 
33
- export const replace = ({options}) => ({
34
- 'module.exports.rules = __object': ({__object}, path) => {
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
-
46
- const node = spreadElement(createRule({
28
+ export const replace = ({options}) => {
29
+ const addRule = createAddRule(options);
30
+
31
+ return {
32
+ 'module.exports.rules = __object': addRule,
33
+ 'export const rules = __object': addRule,
34
+ };
35
+ };
36
+
37
+ const createAddRule = (options) => ({__object}, path) => {
38
+ const {name, ruleOptions} = options;
39
+
40
+ if (ruleOptions) {
41
+ const node = spreadElement(createRuleWithOptions({
47
42
  name: stringLiteral(name),
48
43
  }));
49
44
 
50
45
  __object.properties.push(node);
51
-
52
46
  return path;
53
- },
54
- });
47
+ }
48
+
49
+ const node = spreadElement(createRule({
50
+ name: stringLiteral(name),
51
+ }));
52
+
53
+ __object.properties.push(node);
54
+
55
+ return path;
56
+ };
57
+
58
+ const createCheck = (options) => ({__object}) => {
59
+ let exists = false;
60
+ const {name} = options;
61
+
62
+ for (const prop of __object.properties) {
63
+ if (isSpreadElement(prop))
64
+ continue;
65
+
66
+ if (prop.key.value === name)
67
+ return false;
68
+ }
69
+
70
+ traverse(__object, {
71
+ [`getRule('${name}')`]: () => {
72
+ exists = true;
73
+ },
74
+ [`getRule('${name}', 'off')`]: () => {
75
+ exists = true;
76
+ },
77
+ });
78
+
79
+ return !exists;
80
+ };
81
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redput",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "CLI tool to convert source from 🐊Putout Editor to files",
5
5
  "main": "lib/redput.js",
6
6
  "bin": {
@@ -57,7 +57,7 @@
57
57
  "dependencies": {
58
58
  "@putout/plugin-declare": "^5.0.0",
59
59
  "@putout/plugin-declare-before-reference": "^6.2.0",
60
- "@putout/plugin-nodejs": "^14.0.1",
60
+ "@putout/plugin-nodejs": "^15.0.0",
61
61
  "@putout/plugin-putout": "^24.0.0",
62
62
  "@putout/plugin-remove-unused-variables": "^12.0.0",
63
63
  "node-fetch": "^3.3.2",