@putout/plugin-printer 8.16.2 → 8.17.1
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
|
@@ -31,6 +31,7 @@ npm i @putout/plugin-printer -D
|
|
|
31
31
|
- ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
32
32
|
- ✅ [remove-trailing-spaces-from-type-checker](#remove-trailing-spaces-from-type-checker);
|
|
33
33
|
- ✅ [remove-useless-spaces-from-type-checker](#remove-useless-spaces-from-type-checker);
|
|
34
|
+
- ✅ [remove-useless-arrow-from-type-checker](#remove-useless-arrow-from-type-checker);
|
|
34
35
|
- ✅ [remove-useless-colon-from-type-checker](#remove-useless-colon-from-type-checker);
|
|
35
36
|
- ✅ [remove-useless-tuples-from-type-checker](#remove-useless-tuples-from-type-checker);
|
|
36
37
|
- ✅ [remove-useless-not-from-type-checker](#remove-useless-not-from-type-checker);
|
|
@@ -59,6 +60,7 @@ npm i @putout/plugin-printer -D
|
|
|
59
60
|
"printer/remove-useless-maybe": "on",
|
|
60
61
|
"printer/remove-trailing-spaces-from-type-checker": "on",
|
|
61
62
|
"printer/remove-useless-spaces-from-type-checker": "on",
|
|
63
|
+
"printer/remove-useless-arrow-from-type-checker": "on",
|
|
62
64
|
"printer/remove-useless-colon-from-type-checker": "on",
|
|
63
65
|
"printer/remove-useless-not-from-type-checker": "on",
|
|
64
66
|
"printer/remove-useless-path-from-type-checker": "on",
|
|
@@ -278,6 +280,28 @@ export const beforeIf = createTypeChecker([
|
|
|
278
280
|
]);
|
|
279
281
|
```
|
|
280
282
|
|
|
283
|
+
## remove-useless-arrow-from-type-checker
|
|
284
|
+
|
|
285
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c12c37b793192eadb60fac332d95cc3b/3f4aa557c65897f4967712f30e51c29483feddc8).
|
|
286
|
+
|
|
287
|
+
### ❌ Example of incorrect code
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
const isTwoLongStringsInsideArray = createTypeChecker([
|
|
291
|
+
['-: -> !', isTwoLongStrings],
|
|
292
|
+
['+: parentPath -> -> ArrayExpression'],
|
|
293
|
+
]);
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### ✅ Example of correct code
|
|
297
|
+
|
|
298
|
+
```js
|
|
299
|
+
const isTwoLongStringsInsideArray = createTypeChecker([
|
|
300
|
+
['-: -> !', isTwoLongStrings],
|
|
301
|
+
['+: parentPath -> ArrayExpression'],
|
|
302
|
+
]);
|
|
303
|
+
```
|
|
304
|
+
|
|
281
305
|
## remove-useless-colon-from-type-checker
|
|
282
306
|
|
|
283
307
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/49a35399bd43d56bfd0221b3a0ace3b0/3ff3bdc8cb5f2a06786e9b616252d1b5f506dd73).
|
|
@@ -36,14 +36,19 @@ export const fix = (path) => {
|
|
|
36
36
|
const {node} = path;
|
|
37
37
|
|
|
38
38
|
if (isIdentifier(path) || isCallExpression(path)) {
|
|
39
|
-
replaceWith(path, arrayExpression([
|
|
39
|
+
replaceWith(path, arrayExpression([
|
|
40
|
+
stringLiteral('+'),
|
|
41
|
+
node,
|
|
42
|
+
]));
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
const {value} = node;
|
|
44
47
|
|
|
45
48
|
if (isStringLiteral(path) && !/^[+-]/.test(value)) {
|
|
46
|
-
replaceWith(path, arrayExpression([
|
|
49
|
+
replaceWith(path, arrayExpression([
|
|
50
|
+
stringLiteral(`+: -> ${value}`),
|
|
51
|
+
]));
|
|
47
52
|
return;
|
|
48
53
|
}
|
|
49
54
|
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeUselessArrowFromTypeChecker from './remove-useless-arrow-from-type-checker/index.js';
|
|
1
2
|
import * as removeUselessPathFromTypeChecker from './remove-useless-path-from-type-checker/index.js';
|
|
2
3
|
import * as reverseComparisonInTypeChecker from './reverse-comparison-in-type-checker/index.js';
|
|
3
4
|
import * as removeUselessNotFromTypeChecker from './remove-useless-not-from-type-checker/index.js';
|
|
@@ -46,4 +47,5 @@ export const rules = {
|
|
|
46
47
|
'remove-useless-not-from-type-checker': removeUselessNotFromTypeChecker,
|
|
47
48
|
'reverse-comparison-in-type-checker': reverseComparisonInTypeChecker,
|
|
48
49
|
'remove-useless-path-from-type-checker': removeUselessPathFromTypeChecker,
|
|
50
|
+
'remove-useless-arrow-from-type-checker': removeUselessArrowFromTypeChecker,
|
|
49
51
|
};
|
package/lib/remove-args/index.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {isImportSpecifier} = types;
|
|
4
|
+
const {getBindingPath} = operator;
|
|
5
|
+
|
|
6
|
+
const checkArgs = ({__args}, path) => {
|
|
7
|
+
if (!__args.length)
|
|
8
|
+
return false;
|
|
9
|
+
|
|
10
|
+
const {name} = path.node.callee;
|
|
11
|
+
|
|
12
|
+
const bindingPath = getBindingPath(path, name);
|
|
13
|
+
|
|
14
|
+
if (!bindingPath)
|
|
15
|
+
return true;
|
|
16
|
+
|
|
17
|
+
return !isImportSpecifier(bindingPath);
|
|
18
|
+
};
|
|
2
19
|
|
|
3
20
|
export const report = () => 'Remove useless argument';
|
|
4
21
|
|
|
@@ -0,0 +1,56 @@
|
|
|
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 = addColon(value, where);
|
|
13
|
+
|
|
14
|
+
return `Remove useless arrow: '${value}' -> '${withSpaces}'`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const fix = ({path, where}) => {
|
|
18
|
+
const {value} = path.node;
|
|
19
|
+
setLiteralValue(path, addColon(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
|
+
|
|
45
|
+
if (value.includes('-> ->'))
|
|
46
|
+
where.push('duplicate');
|
|
47
|
+
|
|
48
|
+
return where;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function addColon(value, where) {
|
|
52
|
+
if (where.includes('duplicate'))
|
|
53
|
+
value = value.replace('-> ->', '->');
|
|
54
|
+
|
|
55
|
+
return value;
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.17.1",
|
|
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",
|
|
@@ -43,13 +43,12 @@
|
|
|
43
43
|
"@putout/plugin-remove-nested-blocks": "*",
|
|
44
44
|
"@putout/test": "^15.0.0",
|
|
45
45
|
"eslint": "^10.0.0",
|
|
46
|
-
"eslint-plugin-n": "^17.0.0",
|
|
47
46
|
"eslint-plugin-putout": "^31.0.0",
|
|
48
47
|
"madrun": "^13.0.0",
|
|
49
|
-
"montag": "^
|
|
48
|
+
"montag": "^2.0.0",
|
|
50
49
|
"nodemon": "^3.0.1",
|
|
51
50
|
"superc8": "^12.0.0",
|
|
52
|
-
"supertape": "^
|
|
51
|
+
"supertape": "^13.0.0"
|
|
53
52
|
},
|
|
54
53
|
"peerDependencies": {
|
|
55
54
|
"putout": ">=42"
|