@putout/plugin-printer 1.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 ADDED
@@ -0,0 +1,85 @@
1
+ # @putout/plugin-printer [![NPM version][NPMIMGURL]][NPMURL]
2
+
3
+ [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-printer.svg?style=flat&longCache=true
4
+ [NPMURL]: https://npmjs.org/package/@putout/plugin-printer "npm"
5
+
6
+ 🐊[**Putout**](https://github.com/coderaiser/putout) adds support of transformations for [`@putout/printer`](https://github.com/putoutjs/printer).
7
+
8
+ ## Install
9
+
10
+ ```
11
+ npm i @putout/plugin-printer -D
12
+ ```
13
+
14
+ ## Rules
15
+
16
+ ```json
17
+ {
18
+ "rules": {
19
+ "printer/add-args": "on",
20
+ "printer/apply-breakline": "on",
21
+ "printer/apply-linebreak": "on",
22
+ "printer/apply-computed-print": "on"
23
+ }
24
+ }
25
+ ```
26
+
27
+ ## apply-breakline
28
+
29
+ ```diff
30
+ -print.newline();
31
+ -indent();
32
+ print.breakline();
33
+ ```
34
+
35
+ ## apply-linebreak;
36
+
37
+ ```diff
38
+ -indent();
39
+ -print.newline();
40
+ print.linebreak();
41
+ ```
42
+
43
+ ## add-args
44
+
45
+ ### ❌ Example of incorrect code
46
+
47
+ ```js
48
+ module.exports = {
49
+ TSPropertySignature(path) {
50
+ const {optional} = path.node;
51
+ print('__key');
52
+ maybe.print(optional, '?');
53
+ },
54
+ };
55
+ ```
56
+
57
+ ### βœ… Example of correct code
58
+
59
+ ```js
60
+ module.exports = {
61
+ TSPropertySignature(path, {print, maybe}) {
62
+ const {optional} = path.node;
63
+ print('__key');
64
+ maybe.print(optional, '?');
65
+ },
66
+ };
67
+ ```
68
+
69
+ ## apply-computed-print
70
+
71
+ ### ❌ Example of incorrect code
72
+
73
+ ```js
74
+ print(path.get('block'));
75
+ ```
76
+
77
+ ### βœ… Example of correct code
78
+
79
+ ```js
80
+ print('__block');
81
+ ```
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {addArgs} = operator;
5
+
6
+ const parents = [
7
+ '__ = __',
8
+ 'const __ = __',
9
+ 'module.exports.__a = (path, __object) => __body',
10
+ 'module.exports.__a = (path) => __body',
11
+ 'function __(path) {}',
12
+ 'function __(path, __object) {}',
13
+ ];
14
+
15
+ module.exports = addArgs({
16
+ path: ['path', 'module.exports.__a = () => __body'],
17
+ maybe: ['{maybe}', parents],
18
+ write: ['{write}', parents],
19
+ print: ['{print}', parents],
20
+ indent: ['{indent}', parents],
21
+ compute: ['{compute}', parents],
22
+ traverse: ['{traverse}', parents],
23
+ store: ['{store}', parents],
24
+ });
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ operator,
5
+ template,
6
+ } = require('putout');
7
+
8
+ const {
9
+ compare,
10
+ replaceWith,
11
+ remove,
12
+ } = operator;
13
+
14
+ module.exports.report = () => `breakline = newline + indent`;
15
+
16
+ const next = (path) => path.parentPath.getNextSibling();
17
+
18
+ module.exports.fix = (path) => {
19
+ remove(next(path));
20
+ replaceWith(path, template.ast('print.breakline()'));
21
+ };
22
+
23
+ module.exports.filter = (path) => {
24
+ return compare(next(path), 'print.indent()');
25
+ };
26
+
27
+ module.exports.include = () => [
28
+ 'print.newline()',
29
+ ];
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const {assign} = Object;
4
+
5
+ module.exports.report = () => `Use print('__path') instead of path.get(__path)`;
6
+
7
+ module.exports.replace = () => ({
8
+ 'print(path.get(__a))': ({__a}) => {
9
+ const {
10
+ raw,
11
+ value,
12
+ } = __a;
13
+
14
+ assign(__a, {
15
+ value: `__${value}`,
16
+ raw: raw.replace(value, `__${value}`),
17
+ });
18
+
19
+ return 'print(__a)';
20
+ },
21
+ });
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ operator,
5
+ template,
6
+ } = require('putout');
7
+
8
+ const {
9
+ compare,
10
+ replaceWith,
11
+ remove,
12
+ } = operator;
13
+
14
+ module.exports.report = () => `linebreak = indent + newline`;
15
+
16
+ const prev = (path) => path.parentPath.getPrevSibling();
17
+
18
+ module.exports.fix = (path) => {
19
+ remove(prev(path));
20
+ replaceWith(path, template.ast('print.linebreak()'));
21
+ };
22
+
23
+ module.exports.include = () => [
24
+ 'print.newline()',
25
+ ];
26
+
27
+ module.exports.filter = (path) => {
28
+ return compare(prev(path), 'print.indent()');
29
+ };
package/lib/index.js ADDED
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const getRule = (a) => ({
4
+ [a]: require(`./${a}`),
5
+ });
6
+
7
+ module.exports.rules = {
8
+ ...getRule('apply-breakline'),
9
+ ...getRule('apply-linebreak'),
10
+ ...getRule('apply-computed-print'),
11
+ ...getRule('add-args'),
12
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@putout/plugin-printer",
3
+ "version": "1.0.0",
4
+ "type": "commonjs",
5
+ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
+ "description": "🐊Putout plugin adds support of transformations for @putout/printer",
7
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-printer#readme",
8
+ "main": "lib/index.js",
9
+ "release": false,
10
+ "tag": false,
11
+ "changelog": false,
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git://github.com/coderaiser/printer.git"
15
+ },
16
+ "scripts": {
17
+ "wisdom": "madrun wisdom",
18
+ "test": "madrun test",
19
+ "watch:test": "madrun watch:test",
20
+ "lint": "madrun lint",
21
+ "fresh:lint": "madrun fresh:lint",
22
+ "lint:fresh": "madrun lint:fresh",
23
+ "fix:lint": "madrun fix:lint",
24
+ "coverage": "madrun coverage",
25
+ "report": "madrun report"
26
+ },
27
+ "dependencies": {},
28
+ "keywords": [
29
+ "putout-plugin",
30
+ "putout",
31
+ "plugin",
32
+ "printer"
33
+ ],
34
+ "devDependencies": {
35
+ "@putout/plugin-for-of": "*",
36
+ "@putout/test": "^6.0.0",
37
+ "c8": "^7.5.0",
38
+ "eslint": "^8.0.1",
39
+ "eslint-plugin-n": "^15.2.4",
40
+ "eslint-plugin-putout": "^17.0.0",
41
+ "lerna": "^6.0.1",
42
+ "madrun": "^9.0.0",
43
+ "montag": "^1.2.1",
44
+ "nodemon": "^2.0.1"
45
+ },
46
+ "peerDependencies": {
47
+ "putout": ">=29"
48
+ },
49
+ "license": "MIT",
50
+ "engines": {
51
+ "node": ">=16"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }