@putout/plugin-printer 7.1.1 → 8.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 +21 -1
- package/lib/index.js +2 -0
- package/lib/remove-useless-maybe/index.js +34 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ npm i @putout/plugin-printer -D
|
|
|
21
21
|
- ✅ [apply-types](#apply-types);
|
|
22
22
|
- ✅ [declare](#declare);
|
|
23
23
|
- ✅ [remove-args](#remove-args);
|
|
24
|
+
- ✅ [remove-useless-maybe](#remove-useless-maybe);
|
|
24
25
|
- ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
25
26
|
|
|
26
27
|
## Config
|
|
@@ -35,7 +36,8 @@ npm i @putout/plugin-printer -D
|
|
|
35
36
|
"printer/apply-create-test-url": "on",
|
|
36
37
|
"printer/apply-types": "on",
|
|
37
38
|
"printer/declare": "on",
|
|
38
|
-
"printer/remove-args": "on"
|
|
39
|
+
"printer/remove-args": "on",
|
|
40
|
+
"printer/remove-useless-maybe": "on"
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
```
|
|
@@ -140,6 +142,24 @@ print.indent(is);
|
|
|
140
142
|
print.indent();
|
|
141
143
|
```
|
|
142
144
|
|
|
145
|
+
## remove-useless-maybe
|
|
146
|
+
|
|
147
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d448a928400ff37043ae03510ce7c85c/db1a758809e8759f591533f9ef92bef1188d32b0).
|
|
148
|
+
|
|
149
|
+
### ❌ Example of incorrect code
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
maybe.print.linebreak(wasNewline);
|
|
153
|
+
maybe.print.newline(!wasNewline);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### ✅ Example of correct code
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
maybe.indent(wasNewline);
|
|
160
|
+
print.newline();
|
|
161
|
+
```
|
|
162
|
+
|
|
143
163
|
## declare
|
|
144
164
|
|
|
145
165
|
### ❌ Example of incorrect code
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeUselessMaybe from './remove-useless-maybe/index.js';
|
|
1
2
|
import * as applyCreateTestUrl from './apply-create-test-url/index.js';
|
|
2
3
|
import * as removeArgs from './remove-args/index.js';
|
|
3
4
|
import * as applyBreakline from './apply-breakline/index.js';
|
|
@@ -18,4 +19,5 @@ export const rules = {
|
|
|
18
19
|
'apply-types': applyTypes,
|
|
19
20
|
'remove-legacy-test-declaration': removeLegacyTestDeclaration,
|
|
20
21
|
'apply-create-test-url': applyCreateTestUrl,
|
|
22
|
+
'remove-useless-maybe': removeUselessMaybe,
|
|
21
23
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
remove,
|
|
5
|
+
getTemplateValues,
|
|
6
|
+
compare,
|
|
7
|
+
} = operator;
|
|
8
|
+
|
|
9
|
+
export const report = () => `Use 'if condition' instead of 'ternary expression'`;
|
|
10
|
+
|
|
11
|
+
export const match = () => ({
|
|
12
|
+
'maybe.print.linebreak(__a)': (vars, path) => {
|
|
13
|
+
const next = path.parentPath.getNextSibling();
|
|
14
|
+
const {expression} = next.node;
|
|
15
|
+
|
|
16
|
+
if (!compare(expression, 'maybe.print.newline(!__a)'))
|
|
17
|
+
return false;
|
|
18
|
+
|
|
19
|
+
const {__a} = getTemplateValues(next.node.expression, 'maybe.print.newline(!__a)');
|
|
20
|
+
|
|
21
|
+
return compare(__a, vars.__a);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
export const replace = () => ({
|
|
25
|
+
'maybe.print.linebreak(__a)': (vars, path) => {
|
|
26
|
+
const next = path.parentPath.getNextSibling();
|
|
27
|
+
remove(next);
|
|
28
|
+
|
|
29
|
+
return `{
|
|
30
|
+
maybe.indent(__a);
|
|
31
|
+
print.newline();
|
|
32
|
+
}`;
|
|
33
|
+
},
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
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",
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"@putout/plugin-for-of": "*",
|
|
40
40
|
"@putout/plugin-remove-nested-blocks": "*",
|
|
41
41
|
"@putout/test": "^15.0.0",
|
|
42
|
-
"
|
|
43
|
-
"eslint": "^10.0.0-alpha.0",
|
|
42
|
+
"eslint": "^10.0.0",
|
|
44
43
|
"eslint-plugin-n": "^17.0.0",
|
|
45
|
-
"eslint-plugin-putout": "^
|
|
46
|
-
"madrun": "^
|
|
44
|
+
"eslint-plugin-putout": "^31.0.0",
|
|
45
|
+
"madrun": "^13.0.0",
|
|
47
46
|
"montag": "^1.2.1",
|
|
48
|
-
"nodemon": "^3.0.1"
|
|
47
|
+
"nodemon": "^3.0.1",
|
|
48
|
+
"superc8": "^12.0.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"putout": ">=
|
|
51
|
+
"putout": ">=42"
|
|
52
52
|
},
|
|
53
53
|
"license": "MIT",
|
|
54
54
|
"engines": {
|