@putout/plugin-printer 8.0.2 → 8.2.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
CHANGED
|
@@ -23,6 +23,7 @@ npm i @putout/plugin-printer -D
|
|
|
23
23
|
- ✅ [remove-args](#remove-args);
|
|
24
24
|
- ✅ [remove-useless-maybe](#remove-useless-maybe);
|
|
25
25
|
- ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
26
|
+
- ✅ [remove-trailing-spaces-from-type-checker](#remove-trailing-spaces-from-type-checker)
|
|
26
27
|
|
|
27
28
|
## Config
|
|
28
29
|
|
|
@@ -37,7 +38,8 @@ npm i @putout/plugin-printer -D
|
|
|
37
38
|
"printer/apply-types": "on",
|
|
38
39
|
"printer/declare": "on",
|
|
39
40
|
"printer/remove-args": "on",
|
|
40
|
-
"printer/remove-useless-maybe": "on"
|
|
41
|
+
"printer/remove-useless-maybe": "on",
|
|
42
|
+
"printer/remove-trailing-spaces-from-type-checker": "on"
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
```
|
|
@@ -160,6 +162,26 @@ maybe.indent(wasNewline);
|
|
|
160
162
|
print.newline();
|
|
161
163
|
```
|
|
162
164
|
|
|
165
|
+
## remove-trailing-spaces-from-type-checker
|
|
166
|
+
|
|
167
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d448a928400ff37043ae03510ce7c85c/db1a758809e8759f591533f9ef92bef1188d32b0).
|
|
168
|
+
|
|
169
|
+
### ❌ Example of incorrect code
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
export const beforeIf = createTypeChecker([
|
|
173
|
+
['-: parentPath -> ', isCoupleLines],
|
|
174
|
+
]);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### ✅ Example of correct code
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
export const beforeIf = createTypeChecker([
|
|
181
|
+
['-: parentPath ->', isCoupleLines],
|
|
182
|
+
]);
|
|
183
|
+
```
|
|
184
|
+
|
|
163
185
|
## declare
|
|
164
186
|
|
|
165
187
|
### ❌ Example of incorrect code
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeTrailingSpacesFromTypeChecker from './remove-trailing-spaces-from-type-checker/index.js';
|
|
1
2
|
import * as removeUselessMaybe from './remove-useless-maybe/index.js';
|
|
2
3
|
import * as applyCreateTestUrl from './apply-create-test-url/index.js';
|
|
3
4
|
import * as removeArgs from './remove-args/index.js';
|
|
@@ -20,4 +21,5 @@ export const rules = {
|
|
|
20
21
|
'remove-legacy-test-declaration': removeLegacyTestDeclaration,
|
|
21
22
|
'apply-create-test-url': applyCreateTestUrl,
|
|
22
23
|
'remove-useless-maybe': removeUselessMaybe,
|
|
24
|
+
'remove-trailing-spaces-from-type-checker': removeTrailingSpacesFromTypeChecker,
|
|
23
25
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isIdentifier,
|
|
5
|
+
isCallExpression,
|
|
6
|
+
} = types;
|
|
7
|
+
|
|
8
|
+
const {setLiteralValue} = operator;
|
|
9
|
+
|
|
10
|
+
export const report = (path) => {
|
|
11
|
+
const {value} = path.node;
|
|
12
|
+
const trimmed = value.trim();
|
|
13
|
+
|
|
14
|
+
return `Avoid trailing spaces: '${value}' -> '${trimmed}'`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const fix = (path) => {
|
|
18
|
+
setLiteralValue(path, path.node.value.trim());
|
|
19
|
+
};
|
|
20
|
+
export const traverse = ({push}) => ({
|
|
21
|
+
StringLiteral(path) {
|
|
22
|
+
const call = path.find(isCallExpression);
|
|
23
|
+
|
|
24
|
+
if (!call)
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
|
|
28
|
+
return;
|
|
29
|
+
|
|
30
|
+
const {value} = path.node;
|
|
31
|
+
|
|
32
|
+
if (value.endsWith(' '))
|
|
33
|
+
push(path);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -9,18 +9,37 @@ const {
|
|
|
9
9
|
export const report = () => `Avoid useless 'maybe'`;
|
|
10
10
|
|
|
11
11
|
export const match = () => ({
|
|
12
|
+
'maybe.indent.__a(!__b)': (vars, path) => {
|
|
13
|
+
const next = path.parentPath.getNextSibling();
|
|
14
|
+
|
|
15
|
+
if (!compare(next, 'maybe.indent.__a(__b)'))
|
|
16
|
+
return false;
|
|
17
|
+
|
|
18
|
+
const {__a, __b} = getTemplateValues(next, 'maybe.indent.__a(__b)');
|
|
19
|
+
|
|
20
|
+
if (!compare(__a, vars.__a))
|
|
21
|
+
return false;
|
|
22
|
+
|
|
23
|
+
return compare(__b, vars.__b);
|
|
24
|
+
},
|
|
12
25
|
'maybe.print.linebreak(__a)': (vars, path) => {
|
|
13
26
|
const next = path.parentPath.getNextSibling();
|
|
14
27
|
|
|
15
28
|
if (!compare(next, 'maybe.print.newline(!__a)'))
|
|
16
29
|
return false;
|
|
17
30
|
|
|
18
|
-
const {__a} = getTemplateValues(
|
|
31
|
+
const {__a} = getTemplateValues(next, 'maybe.print.newline(!__a)');
|
|
19
32
|
|
|
20
33
|
return compare(__a, vars.__a);
|
|
21
34
|
},
|
|
22
35
|
});
|
|
23
36
|
export const replace = () => ({
|
|
37
|
+
'maybe.indent.__a(!__b)': (vars, path) => {
|
|
38
|
+
const next = path.parentPath.getNextSibling();
|
|
39
|
+
remove(next);
|
|
40
|
+
|
|
41
|
+
return 'indent.__a()';
|
|
42
|
+
},
|
|
24
43
|
'maybe.print.linebreak(__a)': (vars, path) => {
|
|
25
44
|
const next = path.parentPath.getNextSibling();
|
|
26
45
|
remove(next);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.2.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",
|