@putout/plugin-putout 12.0.0 β†’ 12.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/README.md CHANGED
@@ -20,6 +20,7 @@ npm i @putout/plugin-putout -D
20
20
  "putout/apply-processors-destructuring": "on",
21
21
  "putout/apply-async-formatter": "on",
22
22
  "putout/apply-remove": "on",
23
+ "putout/apply-declare": "on",
23
24
  "putout/add-args": "on",
24
25
  "putout/add-push": "on",
25
26
  "putout/convert-putout-test-to-create-test": "on",
@@ -40,6 +41,7 @@ npm i @putout/plugin-putout -D
40
41
  "putout/convert-dirname-to-url": "on",
41
42
  "putout/convert-url-to-dirname": "on",
42
43
  "putout/convert-report-to-function": "on",
44
+ "putout/create-test": "on",
43
45
  "putout/shorten-imports": "on",
44
46
  "putout/check-replace-code": "on",
45
47
  "putout/declare": "on",
@@ -58,7 +60,6 @@ npm i @putout/plugin-putout -D
58
60
  test('', async (t) => {
59
61
  await t.process({});
60
62
  });
61
-
62
63
  ```
63
64
 
64
65
  ### βœ… Example of correct code
@@ -93,6 +94,32 @@ export const fix = (path) => {
93
94
  };
94
95
  ```
95
96
 
97
+ ## apply-declare
98
+
99
+ Better to use [`Declareator`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) instead of `operator.declare()`.
100
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cf35de5e80e8f7aad866358a50c5eded/0af6142fc9c9e71ac2a2aa96cb85613dd95c9fbf).
101
+
102
+ ### ❌ Example of incorrect code
103
+
104
+ ```js
105
+ const {operator} = require('putout');
106
+ const {declare} = operator;
107
+
108
+ module.exports = declare({
109
+ tryCatch: `import tryCatch from 'try-catch'`,
110
+ tryToCatch: `import tryToCatch from 'try-to-catch'`,
111
+ });
112
+ ```
113
+
114
+ ### βœ… Example of correct code
115
+
116
+ ```js
117
+ module.exports.declare = () => ({
118
+ tryCatch: `import tryCatch from 'try-catch'`,
119
+ tryToCatch: `import tryToCatch from 'try-to-catch'`,
120
+ });
121
+ ```
122
+
96
123
  ## apply-async-formatter
97
124
 
98
125
  ### ❌ Example of incorrect code
@@ -131,6 +158,41 @@ const test = createTest({
131
158
  });
132
159
  ```
133
160
 
161
+ ## create-test
162
+
163
+ Add properties to `createTest` options, here is exmample of `.putout.json`:
164
+
165
+ ```json
166
+ {
167
+ "rules": {
168
+ "putout/create-test": ["on", {
169
+ "add": ["printer", "putout"]
170
+ }]
171
+ }
172
+ }
173
+ ```
174
+
175
+ Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e2a9f02d352c064ac9a11688feadc923/2a525f0a8a2794c9d26c23914801c512f347abef).
176
+
177
+ ### ❌ Example of incorrect code
178
+
179
+ ```js
180
+ createTest(__dirname, {
181
+ 'putout/create-test': plugin,
182
+ });
183
+ ```
184
+
185
+ ### βœ… Example of correct code
186
+
187
+ ```js
188
+ createTest(__dirname, {
189
+ printer: 'putout',
190
+ plugins: [
191
+ ['putout/create-test', plugin],
192
+ ],
193
+ });
194
+ ```
195
+
134
196
  ## convert-number-to-numeric
135
197
 
136
198
  Prevent `Babel` warning: `The node type NumberLiteral has been renamed to NumericLiteral`.
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `Use 'Declarator' instead of 'operator.declare()'`;
4
+
5
+ module.exports.replace = () => ({
6
+ 'module.exports = declare(__a)': 'module.exports.declare = () => __a',
7
+ });
8
+
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ operator,
5
+ types,
6
+ } = require('putout');
7
+
8
+ const {
9
+ StringLiteral,
10
+ ArrayExpression,
11
+ Identifier,
12
+ ObjectProperty,
13
+ ObjectExpression,
14
+ } = types;
15
+
16
+ const {
17
+ replaceWith,
18
+ getProperty,
19
+ } = operator;
20
+
21
+ const selector = 'createTest(__dirname, __object)';
22
+
23
+ module.exports.report = () => `Apply modifications to 'createTest()' options`;
24
+
25
+ module.exports.include = () => [
26
+ selector,
27
+ ];
28
+
29
+ module.exports.fix = (path, {options}) => {
30
+ const [name, value] = options.add;
31
+ const objectPath = path.get('arguments.1');
32
+
33
+ if (!getProperty(objectPath, 'plugins'))
34
+ convert(objectPath);
35
+
36
+ const property = ObjectProperty(Identifier(name), StringLiteral(value));
37
+ objectPath.node.properties.unshift(property);
38
+ };
39
+
40
+ module.exports.filter = (path, {options}) => {
41
+ if (!options.add)
42
+ return false;
43
+
44
+ const [name] = options.add;
45
+ const objectPath = path.get('arguments.1');
46
+
47
+ return !getProperty(objectPath, name);
48
+ };
49
+
50
+ function convert(objectPath) {
51
+ const {key, value} = objectPath.node.properties[0];
52
+
53
+ replaceWith(objectPath, ObjectExpression([
54
+ ObjectProperty(Identifier('plugins'), ArrayExpression([
55
+ ArrayExpression([
56
+ key,
57
+ value,
58
+ ]),
59
+ ])),
60
+ ]));
61
+ }
62
+
@@ -1,8 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const {operator} = require('putout');
4
- const declarations = require('./declarations');
5
- const {declare} = operator;
3
+ const types = require('./types');
4
+ const operator = require('./operator');
6
5
 
7
- module.exports = declare(declarations);
6
+ module.exports.declare = () => ({
7
+ template: `import {template} from 'putout'`,
8
+ createTest: `import {createTest} from '@putout/test'`,
9
+ ...operator,
10
+ ...types,
11
+ });
8
12
 
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ module.exports.rules = {
9
9
  ...getRule('apply-async-formatter'),
10
10
  ...getRule('apply-create-test'),
11
11
  ...getRule('apply-remove'),
12
+ ...getRule('apply-declare'),
12
13
  ...getRule('convert-putout-test-to-create-test'),
13
14
  ...getRule('convert-to-no-transform-code'),
14
15
  ...getRule('convert-find-to-traverse'),
@@ -38,5 +39,6 @@ module.exports.rules = {
38
39
  ...getRule('add-push'),
39
40
  ...getRule('move-require-on-top-level'),
40
41
  ...getRule('includer'),
42
+ ...getRule('create-test'),
41
43
  };
42
44
 
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "12.0.0",
3
+ "version": "12.1.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",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout#readme",
8
8
  "main": "lib/index.js",
9
- "commitType": "colon",
10
9
  "release": false,
11
10
  "tag": false,
12
11
  "changelog": false,
@@ -37,11 +36,11 @@
37
36
  "putout"
38
37
  ],
39
38
  "devDependencies": {
40
- "@putout/test": "^5.0.0",
39
+ "@putout/test": "^6.0.0",
41
40
  "c8": "^7.5.0",
42
41
  "eslint": "^8.0.1",
43
42
  "eslint-plugin-n": "^15.2.4",
44
- "eslint-plugin-putout": "^16.0.0",
43
+ "eslint-plugin-putout": "^17.0.0",
45
44
  "lerna": "^6.0.1",
46
45
  "madrun": "^9.0.0",
47
46
  "montag": "^1.2.1",
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- const types = require('./types');
4
- const operator = require('./operator');
5
-
6
- module.exports = {
7
- template: `import {template} from 'putout'`,
8
- createTest: `import {createTest} from '@putout/test'`,
9
- ...operator,
10
- ...types,
11
- };
12
-