@putout/plugin-printer 8.3.2 → 8.4.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
|
@@ -25,6 +25,7 @@ npm i @putout/plugin-printer -D
|
|
|
25
25
|
- ✅ [remove-useless-maybe](#remove-useless-maybe);
|
|
26
26
|
- ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
27
27
|
- ✅ [remove-trailing-spaces-from-type-checker](#remove-trailing-spaces-from-type-checker)
|
|
28
|
+
- ✅ [remove-useless-spaces-from-type-checker](#remove-useless-spaces-from-type-checker)
|
|
28
29
|
|
|
29
30
|
## Config
|
|
30
31
|
|
|
@@ -41,7 +42,8 @@ npm i @putout/plugin-printer -D
|
|
|
41
42
|
"printer/declare": "on",
|
|
42
43
|
"printer/remove-args": "on",
|
|
43
44
|
"printer/remove-useless-maybe": "on",
|
|
44
|
-
"printer/remove-trailing-spaces-from-type-checker": "on"
|
|
45
|
+
"printer/remove-trailing-spaces-from-type-checker": "on",
|
|
46
|
+
"printer/remove-useless-spaces-from-type-checker": "on"
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
```
|
|
@@ -186,6 +188,26 @@ maybe.indent(wasNewline);
|
|
|
186
188
|
print.newline();
|
|
187
189
|
```
|
|
188
190
|
|
|
191
|
+
## remove-useless-spaces-from-type-checker
|
|
192
|
+
|
|
193
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2e90aa74898a496b488f9c369801b47a/fbd700d965952e80588ec61054b3ed7aee4d17a2).
|
|
194
|
+
|
|
195
|
+
### ❌ Example of incorrect code
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
export const beforeIf = createTypeChecker([
|
|
199
|
+
['- : -> !', isInsideArray],
|
|
200
|
+
]);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### ✅ Example of correct code
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
export const beforeIf = createTypeChecker([
|
|
207
|
+
['-: -> !', isInsideArray],
|
|
208
|
+
]);
|
|
209
|
+
```
|
|
210
|
+
|
|
189
211
|
## remove-trailing-spaces-from-type-checker
|
|
190
212
|
|
|
191
213
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/91d33e39485c31e76b534ad8447ba4db/abca8d21ad6edc1f6fed23edb05fa166677f11d6).
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeUselessSpacesFromTypeChecker from './remove-useless-spaces-from-type-checker/index.js';
|
|
1
2
|
import * as addMissingSpacesToTypeChecker from './add-missing-spaces-to-type-checker/index.js';
|
|
2
3
|
import * as removeTrailingSpacesFromTypeChecker from './remove-trailing-spaces-from-type-checker/index.js';
|
|
3
4
|
import * as removeUselessMaybe from './remove-useless-maybe/index.js';
|
|
@@ -24,4 +25,5 @@ export const rules = {
|
|
|
24
25
|
'remove-useless-maybe': removeUselessMaybe,
|
|
25
26
|
'remove-trailing-spaces-from-type-checker': removeTrailingSpacesFromTypeChecker,
|
|
26
27
|
'add-missing-spaces-to-type-checker': addMissingSpacesToTypeChecker,
|
|
28
|
+
'remove-useless-spaces-from-type-checker': removeUselessSpacesFromTypeChecker,
|
|
27
29
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
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, where}) => {
|
|
11
|
+
const {value} = path.node;
|
|
12
|
+
const withSpaces = removeSpaces(value, where);
|
|
13
|
+
|
|
14
|
+
return `Remove useless spaces: '${value}' -> '${withSpaces}'`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const fix = ({path, where}) => {
|
|
18
|
+
const {value} = path.node;
|
|
19
|
+
setLiteralValue(path, removeSpaces(value, where));
|
|
20
|
+
};
|
|
21
|
+
export const traverse = ({push}) => ({
|
|
22
|
+
StringLiteral(path) {
|
|
23
|
+
const call = path.find(isCallExpression);
|
|
24
|
+
|
|
25
|
+
if (!call)
|
|
26
|
+
return;
|
|
27
|
+
|
|
28
|
+
if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
const {value} = path.node;
|
|
32
|
+
const where = createWhere(value);
|
|
33
|
+
|
|
34
|
+
if (where.length)
|
|
35
|
+
push({
|
|
36
|
+
path,
|
|
37
|
+
where,
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function createWhere(value) {
|
|
43
|
+
const where = [];
|
|
44
|
+
const includes = value.includes.bind(value);
|
|
45
|
+
const endsWith = value.endsWith.bind(value);
|
|
46
|
+
const push = where.push.bind(where);
|
|
47
|
+
|
|
48
|
+
const tools = {
|
|
49
|
+
push,
|
|
50
|
+
includes,
|
|
51
|
+
endsWith,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (includes(' :'))
|
|
55
|
+
traceColon(tools);
|
|
56
|
+
|
|
57
|
+
return where;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function traceColon({push, includes}) {
|
|
61
|
+
if (includes(' :'))
|
|
62
|
+
push('before-colon');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function removeSpaces(value, where) {
|
|
66
|
+
if (where.includes('before-colon'))
|
|
67
|
+
value = value.replace(' :', ':');
|
|
68
|
+
|
|
69
|
+
return value;
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.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",
|