@putout/plugin-printer 8.10.3 → 8.11.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
@@ -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-colon-from-type-checker](#remove-useless-colon-from-type-checker)
34
35
  - ✅ [remove-useless-tuples-from-type-checker](#remove-useless-tuples-from-type-checker)
35
36
 
36
37
  ## Config
@@ -55,6 +56,7 @@ npm i @putout/plugin-printer -D
55
56
  "printer/remove-useless-maybe": "on",
56
57
  "printer/remove-trailing-spaces-from-type-checker": "on",
57
58
  "printer/remove-useless-spaces-from-type-checker": "on",
59
+ "printer/remove-useless-colon-from-type-checker": "on",
58
60
  "printer/remove-useless-tuples-from-type-checker": "on"
59
61
  }
60
62
  }
@@ -270,6 +272,28 @@ export const beforeIf = createTypeChecker([
270
272
  ]);
271
273
  ```
272
274
 
275
+ ## remove-useless-colon-from-type-checker
276
+
277
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/49a35399bd43d56bfd0221b3a0ace3b0/3ff3bdc8cb5f2a06786e9b616252d1b5f506dd73).
278
+
279
+ ### ❌ Example of incorrect code
280
+
281
+ ```js
282
+ export const beforeIf = createTypeChecker([
283
+ ['+:', isInsideArray],
284
+ ['-:', isCoupleLines],
285
+ ]);
286
+ ```
287
+
288
+ ### ✅ Example of correct code
289
+
290
+ ```js
291
+ export const beforeIf = createTypeChecker([
292
+ ['+', isInsideArray],
293
+ ['-', isCoupleLines],
294
+ ]);
295
+ ```
296
+
273
297
  ## remove-useless-tuples-from-type-checker
274
298
 
275
299
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f53f386b607115e0a96f7e294e34761e/cefd72aba4fcade59bbf8faa59739bac5c2fe057).
@@ -61,6 +61,9 @@ export const traverse = ({push}) => ({
61
61
 
62
62
  const type = value.slice(typeNotIndex, value.length);
63
63
 
64
+ if (!type)
65
+ return;
66
+
64
67
  if (!isTypeExists(type))
65
68
  push({
66
69
  path,
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as removeUselessColonFromTypeChecker from './remove-useless-colon-from-type-checker/index.js';
1
2
  import * as addMissingColonToTypeChecker from './add-missing-colon-to-type-checker/index.js';
2
3
  import * as mergeTuplesOfTypeCheckers from './merge-tuples-of-type-checkers/index.js';
3
4
  import * as checkIfSuccessPossibleInTypeChecker from './check-if-success-possible-in-type-checker/index.js';
@@ -38,4 +39,5 @@ export const rules = {
38
39
  'check-if-success-possible-in-type-checker': checkIfSuccessPossibleInTypeChecker,
39
40
  'merge-tuples-of-type-checkers': mergeTuplesOfTypeCheckers,
40
41
  'add-missing-colon-to-type-checker': addMissingColonToTypeChecker,
42
+ 'remove-useless-colon-from-type-checker': removeUselessColonFromTypeChecker,
41
43
  };
@@ -63,6 +63,9 @@ export const traverse = ({push}) => ({
63
63
 
64
64
  const name = cutIS(checkerName);
65
65
 
66
+ if (!name)
67
+ continue;
68
+
66
69
  if (isTypeExists(name))
67
70
  push({
68
71
  path: element,
@@ -0,0 +1,65 @@
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 colon: '${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.length !== 2)
46
+ return where;
47
+
48
+ if (value === '+:')
49
+ where.push('after-plus');
50
+
51
+ if (value === '-:')
52
+ where.push('after-minus');
53
+
54
+ return where;
55
+ }
56
+
57
+ function addColon(value, where) {
58
+ if (where.includes('after-plus'))
59
+ value = value.replace('+:', '+');
60
+
61
+ if (where.includes('after-minus'))
62
+ value = value.replace('-:', '-');
63
+
64
+ return value;
65
+ }
package/lib/types.js CHANGED
@@ -4,9 +4,7 @@ const TYPES_EXISTS = new Set([
4
4
  'CommentBlock',
5
5
  ]);
6
6
 
7
- const TYPES_NOT_EXISTS = new Set([
8
- 'ExportDeclaration',
9
- ]);
7
+ const TYPES_NOT_EXISTS = new Set(['ExportDeclaration']);
10
8
 
11
9
  export function isTypeExists(type) {
12
10
  if (TYPES_NOT_EXISTS.has(type))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.10.3",
3
+ "version": "8.11.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",