@putout/plugin-printer 8.6.8 → 8.7.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
@@ -22,6 +22,7 @@ npm i @putout/plugin-printer -D
22
22
  - ✅ [apply-linebreak](#apply-linebreak);
23
23
  - ✅ [apply-types](#apply-types);
24
24
  - ✅ [check-type-passed-to-type-checker](#check-type-passed-to-type-checker);
25
+ - ✅ [check-if-success-possible-in-type-checker](#check-if-success-possible-in-type-checker);
25
26
  - ✅ [declare](#declare);
26
27
  - ✅ [remove-args](#remove-args);
27
28
  - ✅ [remove-useless-maybe](#remove-useless-maybe);
@@ -43,6 +44,7 @@ npm i @putout/plugin-printer -D
43
44
  "printer/apply-create-test-url": "on",
44
45
  "printer/apply-types": "on",
45
46
  "printer/check-type-passed-to-type-checker": "on",
47
+ "printer/check-if-success-possible-in-type-checker": "on",
46
48
  "printer/declare": "on",
47
49
  "printer/remove-args": "on",
48
50
  "printer/remove-useless-maybe": "on",
@@ -283,10 +285,59 @@ export const beforeIf = createTypeChecker([
283
285
  ]);
284
286
  ```
285
287
 
288
+ ## check-if-success-possible-in-type-checker
289
+
290
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4164addec1e1b2bb93ad7caf3ed13ad8/b04dc172f4094ea6b6902ec54deee779aba6b944).
291
+ When you have only negative branch defined in type checker it never never succeeds (`+`), and always returns false.
292
+
293
+ Consider adding success branch, or remove type checker.
294
+
295
+ ☝️ *This rule has no autofix, because most likely tests will fail after auto fix,
296
+ and instead of observing code with a problem, you will first see failed tests,
297
+ and then after some searches determine that there is a wrong auto fix.*
298
+
299
+ ### ❌ Example of incorrect code
300
+
301
+ ```js
302
+ const isSimple = createTypeChecker([
303
+ '-: -> SpreadElement',
304
+ '-: -> Identifier',
305
+ '-: -> !CallExpression',
306
+ ]);
307
+
308
+ const isSimpleAfterObject = createTypeChecker([
309
+ ['-', isSimple],
310
+ ['-', callWithNext(isObjectExpression)],
311
+ ['-', callWithPrev(isObjectExpression)],
312
+ ]);
313
+ ```
314
+
315
+ ### ✅ Example of correct code
316
+
317
+ Possible fix:
318
+
319
+ ```js
320
+ const isSimple = createTypeChecker([
321
+ '-: -> SpreadElement',
322
+ '-: -> Identifier',
323
+ '+: -> !CallExpression',
324
+ ]);
325
+
326
+ const isSimpleAfterObject = createTypeChecker([
327
+ ['-', isSimple],
328
+ ['-', callWithNext(isObjectExpression)],
329
+ ['+', callWithPrev(isObjectExpression)],
330
+ ]);
331
+ ```
332
+
286
333
  ## check-type-passed-to-type-checker
287
334
 
288
335
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9b35f5f2f23bece832f0f87c929d30e2/b08df8ef8ce6c2a03bceebe6119846c45a78a119).
289
336
 
337
+ ☝️ *This rule has no autofix, because most likely tests will fail after auto fix,
338
+ and instead of observing code with a problem, you will first see failed tests,
339
+ and then after some searches determine that there is a wrong auto fix.*
340
+
290
341
  ### ❌ Example of incorrect code
291
342
 
292
343
  ```js
@@ -297,9 +348,11 @@ export const beforeIf = createTypeChecker([
297
348
 
298
349
  ### ✅ Example of correct code
299
350
 
351
+ Here is possible correct code:
352
+
300
353
  ```js
301
354
  export const beforeIf = createTypeChecker([
302
- ['- : -> 🧨 WrongType'],
355
+ ['- : -> Identifier'],
303
356
  ]);
304
357
  ```
305
358
 
@@ -1,4 +1,3 @@
1
- import process from 'node:process';
2
1
  import {operator, types} from 'putout';
3
2
  import {createTypeChecker} from '@putout/printer/type-checker';
4
3
 
@@ -15,7 +14,7 @@ const {replaceWith} = operator;
15
14
 
16
15
  const hasResult = (value) => /^[+-]/.test(value);
17
16
  const typeOptions = {
18
- instrument: Boolean(process.env.PUTOUT_INSTRUMENT),
17
+ instrumentName: 'PUTOUT_INSTRUMENT',
19
18
  };
20
19
 
21
20
  const isDsl = createTypeChecker([
@@ -0,0 +1,51 @@
1
+ import {types} from 'putout';
2
+
3
+ const {
4
+ isArrayExpression,
5
+ isStringLiteral,
6
+ isIdentifier,
7
+ isCallExpression,
8
+ } = types;
9
+
10
+ export const report = () => `Success path ('+') is absent in Type Checker, all branches routes to fail ('-')`;
11
+
12
+ export const fix = () => {};
13
+
14
+ export const traverse = ({push}) => ({
15
+ ArrayExpression(path) {
16
+ const {parentPath} = path;
17
+
18
+ if (!isCallExpression(parentPath))
19
+ return;
20
+
21
+ const {callee} = parentPath.node;
22
+
23
+ if (!isIdentifier(callee, {name: 'createTypeChecker'}))
24
+ return;
25
+
26
+ const {elements} = path.node;
27
+ const results = elements.map(getResult);
28
+ const successes = results.filter(Boolean);
29
+
30
+ if (!successes.length)
31
+ push(path);
32
+ },
33
+ });
34
+
35
+ const getResult = (a) => {
36
+ if (isStringLiteral(a)) {
37
+ const {value} = a;
38
+
39
+ if (value.startsWith('-'))
40
+ return false;
41
+ }
42
+
43
+ if (isArrayExpression(a)) {
44
+ const {value} = a.elements[0];
45
+
46
+ if (value.startsWith('-'))
47
+ return false;
48
+ }
49
+
50
+ return true;
51
+ };
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as checkIfSuccessPossibleInTypeChecker from './check-if-success-possible-in-type-checker/index.js';
1
2
  import * as removeUselessTuplesFromTypeChecker from './remove-useless-tuples-from-type-checker/index.js';
2
3
  import * as addMissingTuplesToTypeChecker from './add-missing-tuples-to-type-checker/index.js';
3
4
  import * as checkTypePassedToTypeChecker from './check-type-passed-to-type-checker/index.js';
@@ -32,4 +33,5 @@ export const rules = {
32
33
  'check-type-passed-to-type-checker': checkTypePassedToTypeChecker,
33
34
  'add-missing-tuples-to-type-checker': addMissingTuplesToTypeChecker,
34
35
  'remove-useless-tuples-from-type-checker': removeUselessTuplesFromTypeChecker,
36
+ 'check-if-success-possible-in-type-checker': checkIfSuccessPossibleInTypeChecker,
35
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.6.8",
3
+ "version": "8.7.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",
@@ -45,7 +45,8 @@
45
45
  "madrun": "^13.0.0",
46
46
  "montag": "^1.2.1",
47
47
  "nodemon": "^3.0.1",
48
- "superc8": "^12.0.0"
48
+ "superc8": "^12.0.0",
49
+ "supertape": "^12.7.0"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "putout": ">=42",