@putout/plugin-printer 8.6.1 → 8.6.3

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.
@@ -1,7 +1,8 @@
1
+ import process from 'node:process';
1
2
  import {operator, types} from 'putout';
3
+ import {createTypeChecker} from '@putout/printer/type-checker';
2
4
 
3
5
  const {
4
- isStringLiteral,
5
6
  isArrayExpression,
6
7
  isIdentifier,
7
8
  isCallExpression,
@@ -10,6 +11,7 @@ const {
10
11
  } = types;
11
12
 
12
13
  const {replaceWith} = operator;
14
+ const instrument = process.env.PUTOUT_INSTRUMENT;
13
15
 
14
16
  export const report = (path) => {
15
17
  return `Add missing tuple around: ${path}`;
@@ -48,18 +50,36 @@ export const traverse = ({push}) => ({
48
50
  },
49
51
  });
50
52
 
53
+ const hasResult = (value) => /^[+-]/.test(value);
54
+
55
+ const isDsl = createTypeChecker([
56
+ ['-: -> !StringLiteral'],
57
+ ['+: node.value ->', hasResult],
58
+ ], {
59
+ instrument,
60
+ });
61
+
62
+ const isSimple = createTypeChecker([
63
+ 'Identifier',
64
+ 'CallExpression',
65
+ ['-: -> !StringLiteral'],
66
+ ['+: node.value ->!', hasResult],
67
+ ], {
68
+ instrument,
69
+ });
70
+
51
71
  function isConsistent(elements) {
52
72
  const arraysCount = elements.filter(isArrayExpression).length;
53
73
 
54
74
  if (elements.length === arraysCount)
55
75
  return true;
56
76
 
57
- const stringsCount = elements.filter(isStringLiteral).length;
77
+ const simplesCount = elements.filter(isSimple).length;
58
78
 
59
- if (elements.length === stringsCount)
79
+ if (elements.length === simplesCount)
60
80
  return true;
61
81
 
62
- const identifiersCount = elements.filter(isIdentifier).length;
82
+ const dslCount = elements.filter(isDsl).length;
63
83
 
64
- return elements.length === identifiersCount;
84
+ return elements.length === dslCount;
65
85
  }
@@ -13,13 +13,17 @@ const ARROW_NOT_LENGTH = ARROW_NOT.length;
13
13
  const MARK = '🧨';
14
14
  const NOT = '!';
15
15
 
16
+ const TYPES = new Set([
17
+ 'CommentBlock',
18
+ ]);
19
+
16
20
  export const report = ({type}) => {
17
21
  return `Unknown type detected: '${type}'`;
18
22
  };
19
23
 
20
24
  export const fix = ({path, type}) => {
21
25
  const {value} = path.node;
22
- setLiteralValue(path, value.replace(type, `${MARK} ${type}`));
26
+ setLiteralValue(path, value.replace(type, `${MARK}${type}`));
23
27
  };
24
28
 
25
29
  export const traverse = ({push}) => ({
@@ -46,7 +50,7 @@ export const traverse = ({push}) => ({
46
50
 
47
51
  const type = value.slice(typeNotIndex, value.length);
48
52
 
49
- if (!types[`is${type}`])
53
+ if (!isExists(type))
50
54
  push({
51
55
  path,
52
56
  type,
@@ -60,10 +64,17 @@ export const traverse = ({push}) => ({
60
64
 
61
65
  const type = value.slice(typeIndex, value.length);
62
66
 
63
- if (!types[`is${type}`])
67
+ if (!isExists(type))
64
68
  push({
65
69
  path,
66
70
  type,
67
71
  });
68
72
  },
69
73
  });
74
+
75
+ function isExists(type) {
76
+ if (types[`is${type}`])
77
+ return true;
78
+
79
+ return TYPES.has(type);
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.6.1",
3
+ "version": "8.6.3",
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",
@@ -48,7 +48,8 @@
48
48
  "superc8": "^12.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "putout": ">=42"
51
+ "putout": ">=42",
52
+ "@putout/printer": ">=18"
52
53
  },
53
54
  "license": "MIT",
54
55
  "engines": {