Skip to content

Commit 3e70022

Browse files
committed
feature: @putout/plugin-printer: add-missing-tuples-to-type-checker: exclude dsl
1 parent 8cedb22 commit 3e70022

7 files changed

Lines changed: 55 additions & 13 deletions

File tree

packages/plugin-printer/lib/add-missing-tuples-to-type-checker/fixture/add-missing-tuples-to-type-checker-fix.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export const allTuples = createTypeChecker([
1111
['-', isBlockStatement],
1212
]);
1313

14+
export const allIdentifiers = createTypeChecker([
15+
isExpressionStatement,
16+
]);
17+
1418
export const allStrings = createTypeChecker([
1519
'- : -> BlockStatement',
1620
'- : -> WrongType',
1721
]);
18-
19-
export const allIdentifiers = createTypeChecker([
20-
isExpressionStatement,
21-
]);

packages/plugin-printer/lib/add-missing-tuples-to-type-checker/fixture/add-missing-tuples-to-type-checker.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ export const allTuples = createTypeChecker([
1111
['-', isBlockStatement],
1212
]);
1313

14+
export const allIdentifiers = createTypeChecker([
15+
isExpressionStatement,
16+
]);
17+
1418
export const allStrings = createTypeChecker([
1519
'- : -> BlockStatement',
1620
'- : -> WrongType',
1721
]);
1822

19-
export const allIdentifiers = createTypeChecker([
20-
isExpressionStatement,
21-
]);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const isBreakline = createTypeChecker([
2+
isNewlineBetweenSiblings,
3+
callWithNext(isIfStatement)
4+
]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const isInsideParentLike = callWithParent(createTypeChecker([
2+
'Program',
3+
'BlockStatement',
4+
'ExportNamedDeclaration',
5+
'LabeledStatement',
6+
]));

packages/plugin-printer/lib/add-missing-tuples-to-type-checker/index.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import process from 'node:process';
12
import {operator, types} from 'putout';
3+
import {createTypeChecker} from '@putout/printer/type-checker';
24

35
const {
4-
isStringLiteral,
56
isArrayExpression,
67
isIdentifier,
78
isCallExpression,
@@ -10,6 +11,7 @@ const {
1011
} = types;
1112

1213
const {replaceWith} = operator;
14+
const instrument = process.env.PUTOUT_INSTRUMENT;
1315

1416
export const report = (path) => {
1517
return `Add missing tuple around: ${path}`;
@@ -48,18 +50,36 @@ export const traverse = ({push}) => ({
4850
},
4951
});
5052

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+
5171
function isConsistent(elements) {
5272
const arraysCount = elements.filter(isArrayExpression).length;
5373

5474
if (elements.length === arraysCount)
5575
return true;
5676

57-
const stringsCount = elements.filter(isStringLiteral).length;
77+
const simplesCount = elements.filter(isSimple).length;
5878

59-
if (elements.length === stringsCount)
79+
if (elements.length === simplesCount)
6080
return true;
6181

62-
const identifiersCount = elements.filter(isIdentifier).length;
82+
const dslCount = elements.filter(isDsl).length;
6383

64-
return elements.length === identifiersCount;
84+
return elements.length === dslCount;
6585
}

packages/plugin-printer/lib/add-missing-tuples-to-type-checker/index.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ test('printer: add-missing-tuples-to-type-checker: no report: not-type-checker',
3131
t.noReport('not-type-checker');
3232
t.end();
3333
});
34+
35+
test('printer: add-missing-tuples-to-type-checker: no report: mixed', (t) => {
36+
t.noReport('mixed');
37+
t.end();
38+
});
39+
40+
test('printer: add-missing-tuples-to-type-checker: no report: strings', (t) => {
41+
t.noReport('strings');
42+
t.end();
43+
});

packages/plugin-printer/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"superc8": "^12.0.0"
4949
},
5050
"peerDependencies": {
51-
"putout": ">=42"
51+
"putout": ">=42",
52+
"@putout/printer": ">=18"
5253
},
5354
"license": "MIT",
5455
"engines": {

0 commit comments

Comments
 (0)