@putout/plugin-putout 12.0.1 β 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 +36 -1
- package/lib/create-test/index.js +62 -0
- package/lib/index.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ npm i @putout/plugin-putout -D
|
|
|
41
41
|
"putout/convert-dirname-to-url": "on",
|
|
42
42
|
"putout/convert-url-to-dirname": "on",
|
|
43
43
|
"putout/convert-report-to-function": "on",
|
|
44
|
+
"putout/create-test": "on",
|
|
44
45
|
"putout/shorten-imports": "on",
|
|
45
46
|
"putout/check-replace-code": "on",
|
|
46
47
|
"putout/declare": "on",
|
|
@@ -59,7 +60,6 @@ npm i @putout/plugin-putout -D
|
|
|
59
60
|
test('', async (t) => {
|
|
60
61
|
await t.process({});
|
|
61
62
|
});
|
|
62
|
-
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
### β
Example of correct code
|
|
@@ -158,6 +158,41 @@ const test = createTest({
|
|
|
158
158
|
});
|
|
159
159
|
```
|
|
160
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
|
+
|
|
161
196
|
## convert-number-to-numeric
|
|
162
197
|
|
|
163
198
|
Prevent `Babel` warning: `The node type NumberLiteral has been renamed to NumericLiteral`.
|
|
@@ -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
|
+
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "12.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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"c8": "^7.5.0",
|
|
41
41
|
"eslint": "^8.0.1",
|
|
42
42
|
"eslint-plugin-n": "^15.2.4",
|
|
43
|
-
"eslint-plugin-putout": "^
|
|
43
|
+
"eslint-plugin-putout": "^17.0.0",
|
|
44
44
|
"lerna": "^6.0.1",
|
|
45
45
|
"madrun": "^9.0.0",
|
|
46
46
|
"montag": "^1.2.1",
|