@putout/plugin-putout 13.0.0 → 13.2.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
@@ -19,8 +19,10 @@ npm i @putout/plugin-putout -D
19
19
  "putout/apply-create-test": "on",
20
20
  "putout/apply-processors-destructuring": "on",
21
21
  "putout/apply-async-formatter": "on",
22
- "putout/apply-remove": "on",
23
22
  "putout/apply-declare": "on",
23
+ "putout/apply-remove": "on",
24
+ "putout/apply-insert-before": "on",
25
+ "putout/apply-insert-after": "on",
24
26
  "putout/add-args": "on",
25
27
  "putout/add-push": "on",
26
28
  "putout/check-match": "on",
@@ -96,6 +98,55 @@ export const fix = (path) => {
96
98
  };
97
99
  ```
98
100
 
101
+ ## apply-insert-before
102
+
103
+ Better to use [`insertBefore(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-before) method of `operator`.
104
+
105
+ ### ❌ Example of incorrect code
106
+
107
+ ```js
108
+ export const fix = (path) => {
109
+ path.insertBefore(path.get('init'));
110
+ };
111
+ ```
112
+
113
+ ### ✅ Example of correct code
114
+
115
+ ```js
116
+ import {operator} from 'putout';
117
+
118
+ const {insertBefore} = operator;
119
+
120
+ export const fix = (path) => {
121
+ insertBefore(path, path.get('init'));
122
+ };
123
+ ```
124
+
125
+ ## apply-insert-after
126
+
127
+ Better to use [`insertAfter(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-after) method of `operator`.
128
+ It helps to avoid duplication of comments.
129
+
130
+ ### ❌ Example of incorrect code
131
+
132
+ ```js
133
+ export const fix = (path) => {
134
+ path.insertAfter(path.get('init'));
135
+ };
136
+ ```
137
+
138
+ ### ✅ Example of correct code
139
+
140
+ ```js
141
+ import {operator} from 'putout';
142
+
143
+ const {insertAfter} = operator;
144
+
145
+ export const fix = (path) => {
146
+ insertAfter(path, path.get('init'));
147
+ };
148
+ ```
149
+
99
150
  ## apply-declare
100
151
 
101
152
  Better to use [`Declareator`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) instead of `operator.declare()`.
@@ -218,7 +269,7 @@ isNumericLiteral(node);
218
269
 
219
270
  ## convert-putout-test-to-create-test
220
271
 
221
- Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm) work.
272
+ Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm#readme) work.
222
273
 
223
274
  ### ❌ Example of incorrect code
224
275
 
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `Use 'insertAfter(a, b)' instead of 'a.insertAfter(b)'`;
4
+
5
+ module.exports.replace = () => ({
6
+ '__a.insertAfter(__b)': 'insertAfter(__a, __b)',
7
+ });
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `Use 'insertBefore(a, b)' instead of 'a.insertBefore(b)'`;
4
+
5
+ module.exports.replace = () => ({
6
+ '__a.insertBefore(__b)': 'insertBefore(__a, __b)',
7
+ });
@@ -3,5 +3,5 @@
3
3
  module.exports.report = () => `Use 'remove(path)' instead of 'path.remove()'`;
4
4
 
5
5
  module.exports.replace = () => ({
6
- 'path.remove()': 'remove(path)',
6
+ '__a.remove()': 'remove(__a)',
7
7
  });
@@ -9,7 +9,11 @@ const {
9
9
  const fullstore = require('fullstore');
10
10
 
11
11
  const {Identifier, ObjectProperty} = types;
12
- const {replaceWith, insertAfter} = operator;
12
+ const {
13
+ replaceWith,
14
+ insertAfter,
15
+ insertBefore,
16
+ } = operator;
13
17
 
14
18
  const isRecast = (program) => program.get('body.0.expression').isStringLiteral({
15
19
  value: 'use strict',
@@ -42,7 +46,7 @@ module.exports.fix = ({path, calleePath, property, object, program, isInserted})
42
46
  else if (types)
43
47
  insertAfter(pathToInsert, replaceWithAST);
44
48
  else
45
- pathToInsert.insertBefore(replaceWithAST);
49
+ insertBefore(pathToInsert, replaceWithAST);
46
50
 
47
51
  isInserted(true);
48
52
 
@@ -6,7 +6,12 @@ const {
6
6
  types,
7
7
  } = require('putout');
8
8
 
9
- const {insertAfter, replaceWith} = operator;
9
+ const {
10
+ insertAfter,
11
+ replaceWith,
12
+ insertBefore,
13
+ } = operator;
14
+
10
15
  const {Identifier, ObjectProperty} = types;
11
16
 
12
17
  const isRecast = (program) => program.get('body.0').get('expression')
@@ -36,7 +41,7 @@ module.exports.fix = ({path, calleePath, property, object, program}) => {
36
41
  if (isRecast(program))
37
42
  return insertAfter(first, replaceWithAST);
38
43
 
39
- return first.insertBefore(replaceWithAST);
44
+ return insertBefore(first, replaceWithAST);
40
45
  }
41
46
 
42
47
  const id = Identifier('replaceWithMultiple');
@@ -7,7 +7,7 @@ const {
7
7
  } = require('putout');
8
8
 
9
9
  const {StringLiteral} = types;
10
- const {compare} = operator;
10
+ const {compare, remove} = operator;
11
11
 
12
12
  const isPush = (path) => path.get('value').isIdentifier({
13
13
  name: 'push',
@@ -42,7 +42,7 @@ module.exports.replace = () => ({
42
42
 
43
43
  if (isPush(propertyPath) || isBlock(propertyPath)) {
44
44
  node.right.body.elements.push(StringLiteral(name));
45
- propertyPath.remove();
45
+ remove(propertyPath);
46
46
  }
47
47
  }
48
48
 
@@ -0,0 +1,27 @@
1
+ {
2
+ "operator": "import {operator} from 'putout'",
3
+ "compare": "const {compare} = operator",
4
+ "compareAll": "const {compareAll} = operator",
5
+ "compareAny": "const {compareAny} = operator",
6
+ "compute": "const {compute} = operator",
7
+ "contains": "const {contains} = operator",
8
+ "declare": "const {declare} = operator",
9
+ "rename": "const {rename} = operator",
10
+ "renameProperty": "const {renameProperty} = operator",
11
+ "extract": "const {extract} = operator",
12
+ "getPathAfterImports": "const {getPathAfterImports} = operator",
13
+ "traverse": "const {traverse} = operator",
14
+ "isSimpleRegExp": "const {isSimpleRegExp} = operator",
15
+ "getTemplateValues": "const {getTemplateValues} = operator",
16
+ "addArgs": "const {addArgs} = operator",
17
+ "insertBefore": "const {insertBefore} = operator",
18
+ "insertAfter": "const {insertAfter} = operator",
19
+ "replaceWith": "const {replaceWith} = operator",
20
+ "replaceWithMultiple": "const {replaceWithMultiple} = operator",
21
+ "remove": "const {remove} = operator",
22
+ "isESM": "const {isESM} = operator",
23
+ "getProperty": "const {getProperty} = operator",
24
+ "getProperties": "const {getProperties} = operator",
25
+ "isSimple": "const {isSimple} = operator",
26
+ "setLiteralValue": "const {setLiteralValue} = operator"
27
+ }
package/lib/index.js CHANGED
@@ -9,6 +9,8 @@ module.exports.rules = {
9
9
  ...getRule('apply-async-formatter'),
10
10
  ...getRule('apply-create-test'),
11
11
  ...getRule('apply-remove'),
12
+ ...getRule('apply-insert-before'),
13
+ ...getRule('apply-insert-after'),
12
14
  ...getRule('apply-declare'),
13
15
  ...getRule('check-replace-code'),
14
16
  ...getRule('check-match'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "13.0.0",
3
+ "version": "13.2.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",
@@ -44,7 +44,7 @@
44
44
  "lerna": "^6.0.1",
45
45
  "madrun": "^9.0.0",
46
46
  "montag": "^1.2.1",
47
- "nodemon": "^2.0.1"
47
+ "nodemon": "^3.0.1"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "putout": ">=30"
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- operator: `import {operator} from 'putout'`,
5
- compare: `const {compare} = operator`,
6
- compareAll: `const {compareAll} = operator`,
7
- compareAny: `const {compareAny} = operator`,
8
- compute: `const {compute} = operator`,
9
- contains: `const {contains} = operator`,
10
- declare: `const {declare} = operator`,
11
- rename: `const {rename} = operator`,
12
- renameProperty: `const {renameProperty} = operator`,
13
- extract: `const {extract} = operator`,
14
- getPathAfterImports: `const {getPathAfterImports} = operator`,
15
- traverse: `const {traverse} = operator`,
16
- isSimpleRegExp: `const {isSimpleRegExp} = operator`,
17
- getTemplateValues: `const {getTemplateValues} = operator`,
18
- addArgs: `const {addArgs} = operator`,
19
- replaceWith: `const {replaceWith} = operator`,
20
- replaceWithMultiple: `const {replaceWithMultiple} = operator`,
21
- remove: 'const {remove} = operator',
22
- isESM: `const {isESM} = operator`,
23
- getProperty: `const {getProperty} = operator`,
24
- getProperties: `const {getProperties} = operator`,
25
- isSimple: `const {isSimple} = operator`,
26
- };