@putout/plugin-printer 8.22.0 → 8.23.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.
@@ -3,20 +3,21 @@ import {operator, types} from 'putout';
3
3
  const {
4
4
  isIdentifier,
5
5
  isCallExpression,
6
+ isArrayExpression,
6
7
  } = types;
7
8
 
8
9
  const {setLiteralValue} = operator;
9
10
 
10
11
  export const report = ({path, where}) => {
11
12
  const {value} = path.node;
12
- const withSpaces = addColon(value, where);
13
+ const withSpaces = removeArrow(value, where);
13
14
 
14
15
  return `Remove useless arrow: '${value}' -> '${withSpaces}'`;
15
16
  };
16
17
 
17
18
  export const fix = ({path, where}) => {
18
19
  const {value} = path.node;
19
- setLiteralValue(path, addColon(value, where));
20
+ setLiteralValue(path, removeArrow(value, where));
20
21
  };
21
22
  export const traverse = ({push}) => ({
22
23
  StringLiteral(path) {
@@ -28,8 +29,7 @@ export const traverse = ({push}) => ({
28
29
  if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
29
30
  return;
30
31
 
31
- const {value} = path.node;
32
- const where = createWhere(value);
32
+ const where = createWhere(path);
33
33
 
34
34
  if (where.length)
35
35
  push({
@@ -39,18 +39,32 @@ export const traverse = ({push}) => ({
39
39
  },
40
40
  });
41
41
 
42
- function createWhere(value) {
42
+ function createWhere(path) {
43
+ const {value} = path.node;
43
44
  const where = [];
44
45
 
45
46
  if (value.includes('-> ->'))
46
47
  where.push('duplicate');
47
48
 
49
+ if (isInsideCompareTuple(path) && value.includes(' -> '))
50
+ where.push('useless');
51
+
48
52
  return where;
49
53
  }
50
54
 
51
- function addColon(value, where) {
55
+ function removeArrow(value, where) {
52
56
  if (where.includes('duplicate'))
53
57
  value = value.replace('-> ->', '->');
54
58
 
59
+ if (where.includes('useless'))
60
+ value = value.replace(' -> ', '');
61
+
55
62
  return value;
56
63
  }
64
+
65
+ function isInsideCompareTuple({parentPath}) {
66
+ if (!isArrayExpression(parentPath))
67
+ return false;
68
+
69
+ return parentPath.node.elements.length === 3;
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.22.0",
3
+ "version": "8.23.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",