@putout/plugin-printer 4.2.0 → 5.0.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 +25 -0
- package/lib/add-args/index.js +12 -4
- package/lib/apply-breakline/index.js +5 -7
- package/lib/apply-computed-print/index.js +2 -4
- package/lib/apply-linebreak/index.js +5 -7
- package/lib/apply-types/index.js +4 -5
- package/lib/declare/index.js +5 -4
- package/lib/index.js +10 -10
- package/lib/remove-args/index.js +3 -5
- package/lib/remove-legacy-test-declaration/index.js +37 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ npm i @putout/plugin-printer -D
|
|
|
20
20
|
- ✅ [apply-types](#apply-types);
|
|
21
21
|
- ✅ [declare](#declare);
|
|
22
22
|
- ✅ [remove-args](#remove-args);
|
|
23
|
+
- ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
23
24
|
|
|
24
25
|
## Config
|
|
25
26
|
|
|
@@ -123,15 +124,39 @@ print.indent();
|
|
|
123
124
|
|
|
124
125
|
```js
|
|
125
126
|
isIdentifier();
|
|
127
|
+
|
|
128
|
+
test('', (t) => {
|
|
129
|
+
t.print(fixture.returnStatement);
|
|
130
|
+
});
|
|
126
131
|
```
|
|
127
132
|
|
|
128
133
|
### ✅ Example of correct code
|
|
129
134
|
|
|
130
135
|
```js
|
|
131
136
|
const {types} = require('@putout/babel');
|
|
137
|
+
const {createTest} = require('#test');
|
|
138
|
+
|
|
139
|
+
const {test, fixture} = createTest(__dirname);
|
|
132
140
|
const {isIdentifier} = types;
|
|
133
141
|
|
|
134
142
|
isIdentifier();
|
|
143
|
+
|
|
144
|
+
test('', (t) => {
|
|
145
|
+
t.print(fixture.returnStatement);
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## remove-legacy-test-declaration
|
|
150
|
+
|
|
151
|
+
```diff
|
|
152
|
+
-const {printExtension} = require('../../../test/printer');
|
|
153
|
+
-const {readFixtures} = require('../../../test/fixture');
|
|
154
|
+
-
|
|
155
|
+
-const fixture = readFixtures(__dirname);
|
|
156
|
+
-
|
|
157
|
+
-const test = extend({
|
|
158
|
+
- print: printExtension,
|
|
159
|
+
-});
|
|
135
160
|
```
|
|
136
161
|
|
|
137
162
|
## License
|
package/lib/add-args/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {operator} = require('putout');
|
|
4
3
|
const {addArgs} = operator;
|
|
5
|
-
|
|
6
4
|
const parents = [
|
|
7
5
|
'__ = __',
|
|
8
6
|
'const __ = __',
|
|
@@ -13,7 +11,11 @@ const parents = [
|
|
|
13
11
|
'function __(path, __object) {}',
|
|
14
12
|
];
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
const {
|
|
15
|
+
report,
|
|
16
|
+
fix,
|
|
17
|
+
traverse,
|
|
18
|
+
} = addArgs({
|
|
17
19
|
path: ['path', 'module.exports.__a = () => __body'],
|
|
18
20
|
maybe: ['{maybe}', parents],
|
|
19
21
|
write: ['{write}', parents],
|
|
@@ -23,3 +25,9 @@ module.exports = addArgs({
|
|
|
23
25
|
traverse: ['{traverse}', parents],
|
|
24
26
|
store: ['{store}', parents],
|
|
25
27
|
});
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
report,
|
|
31
|
+
fix,
|
|
32
|
+
traverse,
|
|
33
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {operator, template} = require('putout');
|
|
1
|
+
import {operator, template} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {
|
|
6
4
|
compare,
|
|
@@ -9,11 +7,11 @@ const {
|
|
|
9
7
|
remove,
|
|
10
8
|
} = operator;
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
export const report = () => `breakline = newline + indent`;
|
|
13
11
|
|
|
14
12
|
const next = (path) => path.parentPath.getNextSibling();
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const fix = (path) => {
|
|
17
15
|
const sibling = next(path);
|
|
18
16
|
const newNode = choose(path);
|
|
19
17
|
|
|
@@ -21,11 +19,11 @@ module.exports.fix = (path) => {
|
|
|
21
19
|
replaceWith(path, newNode);
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
export const filter = (path) => {
|
|
25
23
|
return compareAny(next(path), ['indent()', 'print.indent()', 'write.indent()']);
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
export const include = () => [
|
|
29
27
|
'print.newline()',
|
|
30
28
|
'write.newline()',
|
|
31
29
|
];
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const {assign} = Object;
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
export const report = () => `Use print('__path') instead of path.get(__path)`;
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
export const replace = () => ({
|
|
8
6
|
'print(path.get(__a))': ({__a}) => {
|
|
9
7
|
const {raw, value} = __a;
|
|
10
8
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {operator, template} = require('putout');
|
|
1
|
+
import {operator, template} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {
|
|
6
4
|
compare,
|
|
@@ -9,11 +7,11 @@ const {
|
|
|
9
7
|
remove,
|
|
10
8
|
} = operator;
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
export const report = () => `linebreak = indent + newline`;
|
|
13
11
|
|
|
14
12
|
const prev = (path) => path.parentPath.getPrevSibling();
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const fix = (path) => {
|
|
17
15
|
const sibling = prev(path);
|
|
18
16
|
const newNode = choose(path);
|
|
19
17
|
|
|
@@ -21,12 +19,12 @@ module.exports.fix = (path) => {
|
|
|
21
19
|
replaceWith(path, newNode);
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
export const include = () => [
|
|
25
23
|
'print.newline()',
|
|
26
24
|
'write.newline()',
|
|
27
25
|
];
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
export const filter = (path) => {
|
|
30
28
|
return compareAny(prev(path), ['indent()', 'print.indent()', 'write.indent()']);
|
|
31
29
|
};
|
|
32
30
|
|
package/lib/apply-types/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {types} = require('putout');
|
|
4
3
|
const {isObjectPattern} = types;
|
|
5
4
|
|
|
6
5
|
const {keys} = Object;
|
|
7
6
|
const TYPES = keys(types);
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export const report = () => `require: ('@putout/babel') -> ('putout/babel').types`;
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
export const match = () => ({
|
|
12
11
|
'const __a = require("@putout/babel")': ({__a}) => {
|
|
13
12
|
if (!isObjectPattern(__a))
|
|
14
13
|
return false;
|
|
@@ -30,7 +29,7 @@ module.exports.match = () => ({
|
|
|
30
29
|
},
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
export const replace = () => ({
|
|
34
33
|
'const {types, __a} = require("@putout/babel")': `{
|
|
35
34
|
const {types} = require("@putout/babel");
|
|
36
35
|
const {__a} = types;
|
package/lib/declare/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import types from '@putout/plugin-putout/declare/types';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export const declare = () => ({
|
|
4
|
+
createTest: `const {createTest} = require('#test')`,
|
|
5
|
+
test: 'const {test} = createTest(__dirname)',
|
|
6
|
+
fixture: 'const {fixture} = createTest(__dirname)',
|
|
6
7
|
types: `import {types} from '@putout/babel'`,
|
|
7
8
|
...types,
|
|
8
9
|
});
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import * as removeArgs from './remove-args/index.js';
|
|
2
|
+
import * as applyBreakline from './apply-breakline/index.js';
|
|
3
|
+
import * as applyLinebreak from './apply-linebreak/index.js';
|
|
4
|
+
import * as applyComputedPrint from './apply-computed-print/index.js';
|
|
5
|
+
import * as addArgs from './add-args/index.js';
|
|
6
|
+
import * as declare from './declare/index.js';
|
|
7
|
+
import * as applyTypes from './apply-types/index.js';
|
|
8
|
+
import * as removeLegacyTestDeclaration from './remove-legacy-test-declaration/index.js';
|
|
2
9
|
|
|
3
|
-
const
|
|
4
|
-
const applyBreakline = require('./apply-breakline');
|
|
5
|
-
const applyLinebreak = require('./apply-linebreak');
|
|
6
|
-
const applyComputedPrint = require('./apply-computed-print');
|
|
7
|
-
const addArgs = require('./add-args');
|
|
8
|
-
const declare = require('./declare');
|
|
9
|
-
const applyTypes = require('./apply-types');
|
|
10
|
-
|
|
11
|
-
module.exports.rules = {
|
|
10
|
+
export const rules = {
|
|
12
11
|
'remove-args': removeArgs,
|
|
13
12
|
'apply-breakline': applyBreakline,
|
|
14
13
|
'apply-linebreak': applyLinebreak,
|
|
@@ -16,4 +15,5 @@ module.exports.rules = {
|
|
|
16
15
|
'add-args': addArgs,
|
|
17
16
|
declare,
|
|
18
17
|
'apply-types': applyTypes,
|
|
18
|
+
'remove-legacy-test-declaration': removeLegacyTestDeclaration,
|
|
19
19
|
};
|
package/lib/remove-args/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const checkArgs = ({__args}) => __args.length;
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
export const report = () => 'Remove useless argument';
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
export const match = () => ({
|
|
8
6
|
'print.newline(__args)': checkArgs,
|
|
9
7
|
'print.space(__args)': checkArgs,
|
|
10
8
|
|
|
@@ -25,7 +23,7 @@ module.exports.match = () => ({
|
|
|
25
23
|
'print.indent.dec(__args)': checkArgs,
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
export const replace = () => ({
|
|
29
27
|
'print.newline(__args)': 'print.newline()',
|
|
30
28
|
'print.breakline(__a)': 'print.breakline()',
|
|
31
29
|
'print.linebreak(__a)': 'print.linebreak()',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {traverse} = operator;
|
|
4
|
+
|
|
5
|
+
const EXTEND = `
|
|
6
|
+
const test = extend({
|
|
7
|
+
print: printExtension,
|
|
8
|
+
})
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export const report = () => `Remove legacy test declaration`;
|
|
12
|
+
|
|
13
|
+
export const match = () => ({
|
|
14
|
+
'const fixture = __': check,
|
|
15
|
+
'const {printExtension} = __': check,
|
|
16
|
+
'const {readFixtures} = __': check,
|
|
17
|
+
[EXTEND]: check,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const replace = () => ({
|
|
21
|
+
'const fixture = __': '',
|
|
22
|
+
'const {printExtension} = __': '',
|
|
23
|
+
'const {readFixtures} = __': '',
|
|
24
|
+
[EXTEND]: '',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function check(vars, path) {
|
|
28
|
+
let is = true;
|
|
29
|
+
const programPath = path.scope.getProgramParent().path;
|
|
30
|
+
|
|
31
|
+
traverse(programPath, {
|
|
32
|
+
'module.exports.createTest = (__args) => __body': () => {
|
|
33
|
+
is = false;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return is;
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds support of transformations for @putout/printer",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-printer#readme",
|
|
@@ -34,25 +34,25 @@
|
|
|
34
34
|
"printer"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
+
"@putout/eslint-flat": "^3.0.0",
|
|
37
38
|
"@putout/plugin-declare-before-reference": "*",
|
|
38
39
|
"@putout/plugin-for-of": "*",
|
|
39
40
|
"@putout/plugin-remove-nested-blocks": "*",
|
|
40
|
-
"@putout/test": "^
|
|
41
|
+
"@putout/test": "^12.0.0",
|
|
41
42
|
"c8": "^10.0.0",
|
|
42
43
|
"eslint": "^9.0.0",
|
|
43
44
|
"eslint-plugin-n": "^17.0.0",
|
|
44
|
-
"eslint-plugin-putout": "^
|
|
45
|
-
"lerna": "^6.0.1",
|
|
45
|
+
"eslint-plugin-putout": "^26.0.0",
|
|
46
46
|
"madrun": "^10.0.0",
|
|
47
47
|
"montag": "^1.2.1",
|
|
48
48
|
"nodemon": "^3.0.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"putout": ">=
|
|
51
|
+
"putout": ">=39"
|
|
52
52
|
},
|
|
53
53
|
"license": "MIT",
|
|
54
54
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
55
|
+
"node": ">=20"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|