Skip to content

Commit 3d179ac

Browse files
committed
feature: @putout/plugin-printer: declare: add
1 parent 8dacfdf commit 3d179ac

File tree

10 files changed

+67
-1
lines changed

10 files changed

+67
-1
lines changed

packages/plugin-printer/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ npm i @putout/plugin-printer -D
2020
"printer/apply-breakline": "on",
2121
"printer/apply-linebreak": "on",
2222
"printer/apply-computed-print": "on",
23+
"printer/declare": "on",
2324
"printer/remove-args": "on"
2425
}
2526
}
@@ -95,6 +96,23 @@ print.indent(is);
9596
print.indent();
9697
```
9798

99+
## declare
100+
101+
### ❌ Example of incorrect code
102+
103+
```js
104+
isIdentifier();
105+
```
106+
107+
### ✅ Example of correct code
108+
109+
```js
110+
const {types} = require('@putout/babel');
111+
const {isIdentifier} = types;
112+
113+
isIdentifier();
114+
```
115+
98116
## License
99117

100118
MIT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {types} from '@putout/babel';
2+
3+
const {isIdentifier} = types;
4+
isIdentifier(node);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
isIdentifier(node);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const types = require('@putout/plugin-putout/declare/types');
4+
5+
module.exports.declare = () => ({
6+
types: `import {types} from '@putout/babel'`,
7+
...types,
8+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const {createTest} = require('@putout/test');
4+
const plugin = require('.');
5+
6+
const test = createTest(__dirname, {
7+
printer: 'putout',
8+
plugins: [
9+
['declare', plugin],
10+
],
11+
});
12+
13+
test('printer: declare: report', (t) => {
14+
t.report('declare', `Declare 'isIdentifier', it referenced but not defined`);
15+
t.end();
16+
});
17+
18+
test('printer: declare: transform', (t) => {
19+
t.transform('declare');
20+
t.end();
21+
});

packages/plugin-printer/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ const applyBreakline = require('./apply-breakline');
55
const applyLinebreak = require('./apply-linebreak');
66
const applyComputedPrint = require('./apply-computed-print');
77
const addArgs = require('./add-args');
8+
const declare = require('./declare');
89

910
module.exports.rules = {
1011
'remove-args': removeArgs,
1112
'apply-breakline': applyBreakline,
1213
'apply-linebreak': applyLinebreak,
1314
'apply-computed-print': applyComputedPrint,
1415
'add-args': addArgs,
16+
declare,
1517
};

packages/plugin-printer/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"coverage": "madrun coverage",
2525
"report": "madrun report"
2626
},
27-
"dependencies": {},
27+
"dependencies": {
28+
"@putout/plugin-putout": "*"
29+
},
2830
"keywords": [
2931
"putout-plugin",
3032
"putout",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {types} from '@putout/babel';
2+
3+
const {isIdentifier} = types;
4+
isIdentifier(node);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
isIdentifier(node);

packages/plugin-printer/test/printer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ test('printer: apply-computed-print: transform: remove-args', (t) => {
3434
t.transform('remove-args');
3535
t.end();
3636
});
37+
38+
test('plugin-printer: transform: declare', (t) => {
39+
t.transform('declare');
40+
t.end();
41+
});

0 commit comments

Comments
 (0)