@putout/plugin-printer 8.8.0 → 8.10.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
@@ -15,6 +15,7 @@ npm i @putout/plugin-printer -D
15
15
 
16
16
  - ✅ [add-args](#add-args);
17
17
  - ✅ [add-missing-spaces-to-type-checker](#add-missing-spaces-to-type-checker);
18
+ - ✅ [add-missing-colon-to-type-checker](#add-missing-spaces-to-type-checker);
18
19
  - ✅ [add-missing-tuples-to-type-checker](#add-missing-tuples-to-type-checker);
19
20
  - ✅ [apply-breakline](#apply-breakline);
20
21
  - ✅ [apply-computed-print](#apply-computed-print);
@@ -39,6 +40,8 @@ npm i @putout/plugin-printer -D
39
40
  "rules": {
40
41
  "printer/add-args": "on",
41
42
  "printer/add-missing-tuples-to-type-checker": "on",
43
+ "printer/add-missing-colon-to-type-checker": "on",
44
+ "printer/add-missing-spaces-to-type-checker": "on",
42
45
  "printer/apply-breakline": "on",
43
46
  "printer/apply-linebreak": "on",
44
47
  "printer/apply-computed-print": "on",
@@ -131,6 +134,28 @@ export const beforeIf = createTypeChecker([
131
134
  ]);
132
135
  ```
133
136
 
137
+ ## add-missing-colon-to-type-checker
138
+
139
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/97d38d9bee0586deb8c627c19e399a27/889646df2dcfcfe86f7eb0efb6e3ed5791701f58).
140
+
141
+ ### ❌ Example of incorrect code
142
+
143
+ ```js
144
+ export const beforeIf = createTypeChecker([
145
+ ['+ -> !', isInsideArray],
146
+ ['- parentPath ->', isCoupleLines],
147
+ ]);
148
+ ```
149
+
150
+ ### ✅ Example of correct code
151
+
152
+ ```js
153
+ export const beforeIf = createTypeChecker([
154
+ ['+: -> !', isInsideArray],
155
+ ['-: parentPath ->', isCoupleLines],
156
+ ]);
157
+ ```
158
+
134
159
  ## add-missing-tuple-to-type-checker
135
160
 
136
161
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fdfda423df3af9b0f08541710706299/0259bba117997861fe7573bad5477282f4df8554).
@@ -0,0 +1,62 @@
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 withColon = addColon(value, where);
13
+
14
+ return `Add missing colon: '${value}' -> '${withColon}'`;
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.startsWith('+') && !value.includes(':'))
46
+ where.push('after-plus');
47
+
48
+ if (value.startsWith('-') && !value.includes('-:'))
49
+ where.push('after-minus');
50
+
51
+ return where;
52
+ }
53
+
54
+ function addColon(value, where) {
55
+ if (where.includes('after-plus'))
56
+ value = value.replace('+', '+:');
57
+
58
+ if (where.includes('after-minus'))
59
+ value = value.replace('-', '-:');
60
+
61
+ return value;
62
+ }
@@ -1,5 +1,4 @@
1
1
  import {operator, types} from 'putout';
2
- import {createTypeChecker} from '@putout/printer/type-checker';
3
2
 
4
3
  const {
5
4
  isArrayExpression,
@@ -10,24 +9,24 @@ const {
10
9
  stringLiteral,
11
10
  } = types;
12
11
 
13
- const {replaceWith} = operator;
12
+ const {
13
+ replaceWith,
14
+ createTypeChecker,
15
+ } = operator;
14
16
 
15
17
  const hasResult = (value) => /^[+-]/.test(value);
16
- const typeOptions = {
17
- instrumentName: 'PUTOUT_INSTRUMENT',
18
- };
19
18
 
20
19
  const isDsl = createTypeChecker([
21
20
  ['-: -> !StringLiteral'],
22
21
  ['+: node.value ->', hasResult],
23
- ], typeOptions);
22
+ ]);
24
23
 
25
24
  const isSimple = createTypeChecker([
26
25
  ['+: -> Identifier'],
27
26
  ['+: -> CallExpression'],
28
27
  ['-: -> !StringLiteral'],
29
28
  ['+: node.value -> !', hasResult],
30
- ], typeOptions);
29
+ ]);
31
30
 
32
31
  export const report = (path) => {
33
32
  return `Add missing tuple around: ${path}`;
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as addMissingColonToTypeChecker from './add-missing-colon-to-type-checker/index.js';
1
2
  import * as mergeTuplesOfTypeCheckers from './merge-tuples-of-type-checkers/index.js';
2
3
  import * as checkIfSuccessPossibleInTypeChecker from './check-if-success-possible-in-type-checker/index.js';
3
4
  import * as removeUselessTuplesFromTypeChecker from './remove-useless-tuples-from-type-checker/index.js';
@@ -36,4 +37,5 @@ export const rules = {
36
37
  'remove-useless-tuples-from-type-checker': removeUselessTuplesFromTypeChecker,
37
38
  'check-if-success-possible-in-type-checker': checkIfSuccessPossibleInTypeChecker,
38
39
  'merge-tuples-of-type-checkers': mergeTuplesOfTypeCheckers,
40
+ 'add-missing-colon-to-type-checker': addMissingColonToTypeChecker,
39
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.8.0",
3
+ "version": "8.10.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",