Skip to content

Commit 2821594

Browse files
committed
feature: @putout/plugin-printer: add
1 parent d38a24f commit 2821594

40 files changed

Lines changed: 521 additions & 0 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ Next packages not bundled with 🐊**Putout** but can be installed separately.
20042004
| [`@putout/plugin-jest`](/packages/plugin-jest#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-jest.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-jest) |
20052005
| [`@putout/plugin-travis`](/packages/plugin-travis#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-travis.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-travis) |
20062006
| [`@putout/plugin-convert-throw`](/packages/plugin-convert-throw#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-throw.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-throw) |
2007+
| [`@putout/plugin-printer`](/packages/plugin-printer#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-printer.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-printer) |
20072008

20082009
## 🦚 Formatters
20092010

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"plugin:n/recommended",
4+
"plugin:putout/safe+align"
5+
],
6+
"plugins": [
7+
"putout",
8+
"n"
9+
]
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'wisdom': () => run(['lint', 'coverage']),
5+
'test': () => `tape 'lib/**/*.spec.js' test/*.js 'rules/**/*.spec.js'`,
6+
'watch:test': async () => `nodemon -w lib -w test -x ${await run('test')}`,
7+
'lint': () => `putout .`,
8+
'fresh:lint': () => run('lint', '--fresh'),
9+
'lint:fresh': () => run('lint', '--fresh'),
10+
'fix:lint': () => run('lint', '--fix'),
11+
'coverage': async () => `c8 ${await run('test')}`,
12+
'coverage:html': async () => `c8 --reporter=lcov ${await run('test')}`,
13+
'report': () => 'c8 report --reporter=lcov',
14+
};

packages/plugin-printer/.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.*
2+
*.spec.js
3+
test
4+
yarn-error.log
5+
6+
coverage
7+
fixture
8+
fixture.js
9+
rules
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*"
9+
],
10+
"branches": 100,
11+
"lines": 100,
12+
"functions": 100,
13+
"statements": 100
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printer": "putout",
3+
"rules": {
4+
"putout": "on"
5+
}
6+
}

packages/plugin-printer/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
TSPropertySignature(path, {print, maybe}) {
3+
const {optional} = path.node;
4+
print('__key');
5+
maybe.print(optional, '?');
6+
},
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
TSPropertySignature(path, {print}) {
3+
const {optional} = path.node;
4+
print('__key');
5+
maybe.print(optional, '?');
6+
},
7+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const CallExpression = {
2+
print(path, {indent, print, maybe, traverse}) {
3+
traverse(path.get('callee'));
4+
},
5+
};

0 commit comments

Comments
 (0)