@kikiutils/eslint-config 12.0.3 → 12.0.5
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 +3 -3
- package/dist/_internals/rules/comment-indent.d.ts.map +1 -1
- package/dist/_internals/rules/comment-indent.js +36 -27
- package/dist/_internals/rules/comment-indent.js.map +1 -1
- package/dist/_internals/rules/compact-iteration-layout.js +1 -0
- package/dist/_internals/rules/compact-iteration-layout.js.map +1 -1
- package/dist/_internals/rules/consistent-parameter-layout.js +23 -36
- package/dist/_internals/rules/consistent-parameter-layout.js.map +1 -1
- package/dist/_internals/rules/no-composable-in-head-getter.d.ts.map +1 -1
- package/dist/_internals/rules/no-composable-in-head-getter.js +20 -27
- package/dist/_internals/rules/no-composable-in-head-getter.js.map +1 -1
- package/dist/_internals/rules/no-silent-catch.js +2 -2
- package/dist/_internals/rules/no-silent-catch.js.map +1 -1
- package/dist/_internals/rules/no-thenable-zod-refinement.d.ts.map +1 -1
- package/dist/_internals/rules/no-thenable-zod-refinement.js.map +1 -1
- package/dist/_internals/rules/prefer-enhanced-date.d.ts.map +1 -1
- package/dist/_internals/rules/prefer-enhanced-date.js +38 -42
- package/dist/_internals/rules/prefer-enhanced-date.js.map +1 -1
- package/dist/_internals/rules/statement-padding.js +1 -1
- package/dist/_internals/rules/statement-padding.js.map +1 -1
- package/dist/_internals/rules/utils.d.ts +1 -1
- package/dist/_internals/rules/utils.js.map +1 -1
- package/dist/base.js.map +1 -1
- package/dist/nuxt.js +1 -4
- package/dist/nuxt.js.map +1 -1
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +8 -2
- package/dist/vue.js.map +1 -1
- package/package.json +4 -4
- package/src/_internals/rules/comment-indent.ts +44 -52
- package/src/_internals/rules/compact-iteration-layout.ts +1 -0
- package/src/_internals/rules/consistent-parameter-layout.ts +41 -66
- package/src/_internals/rules/no-composable-in-head-getter.ts +23 -28
- package/src/_internals/rules/no-silent-catch.ts +2 -3
- package/src/_internals/rules/no-thenable-zod-refinement.ts +1 -2
- package/src/_internals/rules/prefer-enhanced-date.ts +58 -88
- package/src/_internals/rules/statement-padding.ts +1 -1
- package/src/_internals/rules/utils.ts +1 -1
- package/src/base.ts +0 -2
- package/src/nuxt.ts +2 -6
- package/src/vue.ts +9 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "12.0.
|
|
4
|
+
"version": "12.0.5",
|
|
5
5
|
"description": "Opinionated ESLint flat config presets layered on @antfu/eslint-config, with type-aware TypeScript and Vue checks and custom rules, built for the author's own repositories.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"bumplog": "changelogen --bump --hideAuthorEmail",
|
|
31
31
|
"knip:deps": "knip --dependencies",
|
|
32
32
|
"knip:exports": "knip --exports",
|
|
33
|
-
"lint": "eslint --cache --
|
|
34
|
-
"lint:fix": "eslint --cache --
|
|
33
|
+
"lint": "eslint --cache --max-warnings 0",
|
|
34
|
+
"lint:fix": "eslint --cache --fix --max-warnings 0",
|
|
35
35
|
"prepack": "pnpm run build",
|
|
36
36
|
"release": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build && changelogen --clean --hideAuthorEmail --push --release && npm publish",
|
|
37
37
|
"test": "vitest run --coverage",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"eslint-plugin-format": "^2.0.1",
|
|
64
64
|
"eslint-plugin-promise": "^7.3.0",
|
|
65
65
|
"eslint-plugin-typefest": "^1.7.1",
|
|
66
|
-
"tailwind-csstree": "^0.4.
|
|
66
|
+
"tailwind-csstree": "^0.4.3",
|
|
67
67
|
"vue-eslint-parser": "^10.4.2"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AST,
|
|
3
|
-
Rule,
|
|
4
|
-
} from 'eslint';
|
|
5
|
-
|
|
6
|
-
type Comment = ReturnType<Rule.RuleContext['sourceCode']['getAllComments']>[number];
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
7
2
|
|
|
8
3
|
const closingPunctuators = new Set([
|
|
9
4
|
')',
|
|
@@ -21,58 +16,55 @@ export const commentIndent: Rule.RuleModule = {
|
|
|
21
16
|
create(context) {
|
|
22
17
|
const { sourceCode } = context;
|
|
23
18
|
const getIndent = (line: number) => /^[\t ]*/.exec(sourceCode.lines[line - 1]!)![0];
|
|
24
|
-
const startsLine = (token: AST.Token | Comment) => {
|
|
25
|
-
const previous = sourceCode.getTokenBefore(token, { includeComments: true });
|
|
26
|
-
return !previous || previous.loc!.end.line < token.loc!.start.line;
|
|
27
|
-
};
|
|
28
19
|
|
|
29
20
|
return {
|
|
30
21
|
Program() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
const comments = sourceCode.getAllComments();
|
|
23
|
+
for (let index = 0; index < comments.length;) {
|
|
24
|
+
const firstIndex = index++;
|
|
25
|
+
const first = comments[firstIndex]!;
|
|
26
|
+
const opening = sourceCode.getTokenBefore(first, { includeComments: true });
|
|
27
|
+
if (opening?.type !== 'Punctuator' || !openingPunctuators.has(opening.value)) continue;
|
|
28
|
+
const next = sourceCode.getTokenAfter(first);
|
|
29
|
+
if (!next) break;
|
|
30
|
+
while (index < comments.length && comments[index]!.range![0] < next.range[0]) index++;
|
|
31
|
+
if (closingPunctuators.has(next.value) || comments[index - 1]!.loc!.end.line === next.loc.start.line) continue;
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const { end, start } = comment.loc!;
|
|
44
|
-
// style/indent only lets a comment follow the next code when no blank line separates them.
|
|
45
|
-
const gapLines = sourceCode.lines.slice(end.line, next.loc.start.line - 1);
|
|
46
|
-
if (gapLines.some((text) => !text.trim())) continue;
|
|
47
|
-
const indent = getIndent(start.line);
|
|
33
|
+
// Only comments after the last blank line can take the following code's indentation.
|
|
34
|
+
let lastBlank = next.loc.start.line - 1;
|
|
35
|
+
while (lastBlank > first.loc!.end.line && sourceCode.lines[lastBlank - 1]!.trim()) lastBlank--;
|
|
48
36
|
const expected = getIndent(next.loc.start.line);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
let previousEnd = opening.loc.end.line;
|
|
38
|
+
for (let position = firstIndex; position < index; position++) {
|
|
39
|
+
const comment = comments[position]!;
|
|
40
|
+
const { end, start } = comment.loc!;
|
|
41
|
+
if (start.line === previousEnd) break;
|
|
42
|
+
previousEnd = end.line;
|
|
43
|
+
if (end.line < lastBlank) continue;
|
|
44
|
+
const indent = getIndent(start.line);
|
|
45
|
+
if (indent === expected) continue;
|
|
46
|
+
context.report({
|
|
47
|
+
* fix(fixer) {
|
|
48
|
+
for (let line = start.line; line <= end.line; line++) {
|
|
49
|
+
if (!sourceCode.lines[line - 1]!.startsWith(indent)) continue;
|
|
50
|
+
const offset = sourceCode.getIndexFromLoc({
|
|
51
|
+
column: 0,
|
|
52
|
+
line,
|
|
53
|
+
});
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
offset + indent.length,
|
|
69
|
-
],
|
|
70
|
-
expected,
|
|
71
|
-
);
|
|
72
|
-
}),
|
|
73
|
-
loc: comment.loc!,
|
|
74
|
-
messageId: 'align',
|
|
75
|
-
});
|
|
55
|
+
yield fixer.replaceTextRange(
|
|
56
|
+
[
|
|
57
|
+
offset,
|
|
58
|
+
offset + indent.length,
|
|
59
|
+
],
|
|
60
|
+
expected,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
loc: comment.loc!,
|
|
65
|
+
messageId: 'align',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
76
68
|
}
|
|
77
69
|
},
|
|
78
70
|
};
|
|
@@ -7,6 +7,7 @@ export const compactIterationLayout: Rule.RuleModule = {
|
|
|
7
7
|
const { sourceCode } = context;
|
|
8
8
|
|
|
9
9
|
function checkParentheses(node: IterationNode): void {
|
|
10
|
+
if (node.loc!.start.line === node.body.loc!.start.line) return;
|
|
10
11
|
const openingParen = sourceCode.getFirstToken(node, (token) => token.value === '(')!;
|
|
11
12
|
const closingParen = sourceCode.getTokenBefore(node.body)!;
|
|
12
13
|
const next = sourceCode.getTokenAfter(openingParen)!;
|
|
@@ -43,66 +43,48 @@ export const consistentParameterLayout: Rule.RuleModule = {
|
|
|
43
43
|
function checkTestCallLayout(node: CallNode): void {
|
|
44
44
|
const items = node.arguments;
|
|
45
45
|
if (!items.length) return;
|
|
46
|
+
if (
|
|
47
|
+
node.loc!.start.line === items[0]!.loc!.start.line
|
|
48
|
+
&& items.every((item, index) => item.loc!.end.line === (items[index + 1]?.loc!.start.line ?? node.loc!.end.line))
|
|
49
|
+
) return;
|
|
50
|
+
|
|
46
51
|
const openingParen = getCallOpeningParen(node)!;
|
|
47
52
|
|
|
48
53
|
const closingParen = tokenStore.getLastToken(node)!;
|
|
49
54
|
const previous = tokenStore.getTokenBefore(closingParen)!;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
const fixes: Rule.Fix[] = [];
|
|
56
|
+
|
|
57
|
+
function collectGap(left: AST.Token, right: AST.Token, text: string): boolean {
|
|
58
|
+
// A boundary comment keeps the whole list in its original layout.
|
|
59
|
+
if (tokenStore.commentsExistBetween(left, right)) return false;
|
|
60
|
+
if (left.loc.end.line !== right.loc.start.line) {
|
|
61
|
+
fixes.push({
|
|
62
|
+
range: [
|
|
63
|
+
left.range[1],
|
|
64
|
+
right.range[0],
|
|
65
|
+
],
|
|
66
|
+
text,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
const comma = tokenStore.getTokensBetween(items[index - 1]!, items[index]!)
|
|
65
|
-
.find((token) => token.type === 'Punctuator' && token.value === ',')!;
|
|
66
|
-
|
|
67
|
-
gaps.push(
|
|
68
|
-
[
|
|
69
|
-
tokenStore.getTokenBefore(comma)!,
|
|
70
|
-
comma,
|
|
71
|
-
'',
|
|
72
|
-
],
|
|
73
|
-
[
|
|
74
|
-
comma,
|
|
75
|
-
tokenStore.getTokenAfter(comma)!,
|
|
76
|
-
' ',
|
|
77
|
-
],
|
|
78
|
-
);
|
|
70
|
+
return true;
|
|
79
71
|
}
|
|
80
72
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
if (!collectGap(openingParen, tokenStore.getTokenAfter(openingParen)!, '') || !collectGap(previous, closingParen, '')) return;
|
|
74
|
+
for (let index = 1; index < items.length; index++) {
|
|
75
|
+
const comma = tokenStore.getFirstTokenBetween(
|
|
76
|
+
items[index - 1]!,
|
|
77
|
+
items[index]!,
|
|
78
|
+
(token) => token.type === 'Punctuator' && token.value === ',',
|
|
79
|
+
)!;
|
|
88
80
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const multilineGaps = gaps.filter(([left, right]) => left.loc.end.line !== right.loc.start.line);
|
|
92
|
-
if (!multilineGaps.length) return;
|
|
81
|
+
if (!collectGap(tokenStore.getTokenBefore(comma)!, comma, '') || !collectGap(comma, tokenStore.getTokenAfter(comma)!, ' ')) return;
|
|
82
|
+
}
|
|
93
83
|
|
|
84
|
+
if (previous.value === ',' && !collectGap(tokenStore.getTokenBefore(previous)!, previous, '')) return;
|
|
85
|
+
if (!fixes.length) return;
|
|
94
86
|
context.report({
|
|
95
|
-
fix: (
|
|
96
|
-
left,
|
|
97
|
-
right,
|
|
98
|
-
text,
|
|
99
|
-
]) => fixer.replaceTextRange(
|
|
100
|
-
[
|
|
101
|
-
left.range[1],
|
|
102
|
-
right.range[0],
|
|
103
|
-
],
|
|
104
|
-
text,
|
|
105
|
-
)),
|
|
87
|
+
fix: () => fixes,
|
|
106
88
|
messageId: 'compactTestCall',
|
|
107
89
|
node,
|
|
108
90
|
});
|
|
@@ -113,7 +95,7 @@ export const consistentParameterLayout: Rule.RuleModule = {
|
|
|
113
95
|
items: readonly ListItem[],
|
|
114
96
|
): void {
|
|
115
97
|
const first = items[0];
|
|
116
|
-
if (!first) return;
|
|
98
|
+
if (!first || node.loc!.start.line === node.loc!.end.line) return;
|
|
117
99
|
const isSingleParameter = items.length === 1;
|
|
118
100
|
|
|
119
101
|
// JSX argument layout belongs to the JSX formatting rules.
|
|
@@ -133,23 +115,19 @@ export const consistentParameterLayout: Rule.RuleModule = {
|
|
|
133
115
|
? tokenStore.getLastToken(node)
|
|
134
116
|
: tokenStore.getTokenAfter(items.at(-1)!, (token) => token.value === ')');
|
|
135
117
|
|
|
118
|
+
if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;
|
|
136
119
|
const next = tokenStore.getTokenAfter(openingParen)!;
|
|
137
|
-
|
|
138
120
|
if (isSingleParameter) {
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
if (closingParen.value !== ')') return;
|
|
122
|
+
const previous = tokenStore.getTokenBefore(closingParen)!;
|
|
123
|
+
const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;
|
|
124
|
+
const hasClosingNewline = previous.loc.end.line !== closingParen.loc.start.line;
|
|
125
|
+
if (hasOpeningNewline === hasClosingNewline) return;
|
|
142
126
|
if (
|
|
143
127
|
tokenStore.commentsExistBetween(openingParen, next)
|
|
144
|
-
|| tokenStore.commentsExistBetween(previous, closingParen)
|
|
128
|
+
|| tokenStore.commentsExistBetween(previous.value === ',' ? tokenStore.getTokenBefore(previous)! : previous, closingParen)
|
|
145
129
|
) return;
|
|
146
130
|
|
|
147
|
-
const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;
|
|
148
|
-
const hasClosingNewline = tokenStore.getTokenBefore(closingParen)!.loc.end.line
|
|
149
|
-
!== closingParen.loc.start.line;
|
|
150
|
-
|
|
151
|
-
if (hasOpeningNewline === hasClosingNewline) return;
|
|
152
|
-
|
|
153
131
|
context.report({
|
|
154
132
|
fix: (fixer) => hasOpeningNewline
|
|
155
133
|
? fixer.insertTextBefore(closingParen, '\n')
|
|
@@ -161,16 +139,13 @@ export const consistentParameterLayout: Rule.RuleModule = {
|
|
|
161
139
|
return;
|
|
162
140
|
}
|
|
163
141
|
|
|
164
|
-
if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;
|
|
165
|
-
|
|
166
142
|
if (isTemplate) {
|
|
167
143
|
// Script list formatters do not traverse Vue template expressions.
|
|
168
144
|
const newlineOffsets: number[] = [];
|
|
169
145
|
if (openingParen.loc.end.line === next.loc.start.line) newlineOffsets.push(openingParen.range[1]);
|
|
170
146
|
for (let index = 1; index < items.length; index++) {
|
|
171
147
|
const item = items[index]!;
|
|
172
|
-
const comma = tokenStore.
|
|
173
|
-
.find((token) => token.value === ',');
|
|
148
|
+
const comma = tokenStore.getFirstTokenBetween(items[index - 1]!, item, (token) => token.value === ',');
|
|
174
149
|
|
|
175
150
|
if (comma && comma.loc.end.line === tokenStore.getTokenAfter(comma)!.loc.start.line) {
|
|
176
151
|
newlineOffsets.push(comma.range[1]);
|
|
@@ -17,22 +17,13 @@ const headComposables = new Set([
|
|
|
17
17
|
]);
|
|
18
18
|
|
|
19
19
|
// Functions nested in the body are skipped: calling the outer function does not run them.
|
|
20
|
-
function findCalledComposable(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && composablePattern.test(node.expression.text)) {
|
|
25
|
-
composable = node.expression.text;
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
ts.forEachChild(node, visit);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
for (const body of bodies) {
|
|
33
|
-
visit(body);
|
|
34
|
-
if (composable) return composable;
|
|
20
|
+
function findCalledComposable(node: ts.Node): string | undefined {
|
|
21
|
+
if (ts.isFunctionLike(node)) return;
|
|
22
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && composablePattern.test(node.expression.text)) {
|
|
23
|
+
return node.expression.text;
|
|
35
24
|
}
|
|
25
|
+
|
|
26
|
+
return ts.forEachChild(node, findCalledComposable);
|
|
36
27
|
}
|
|
37
28
|
|
|
38
29
|
function getBody(node: ts.Node | undefined): ts.Node | undefined {
|
|
@@ -52,7 +43,7 @@ function getImplementationBodies(checker: ts.TypeChecker, call: ts.CallExpressio
|
|
|
52
43
|
|
|
53
44
|
if (values.some(Boolean)) {
|
|
54
45
|
return values
|
|
55
|
-
.map(
|
|
46
|
+
.map(getBody)
|
|
56
47
|
.filter((body) => body !== undefined);
|
|
57
48
|
}
|
|
58
49
|
|
|
@@ -62,7 +53,7 @@ function getImplementationBodies(checker: ts.TypeChecker, call: ts.CallExpressio
|
|
|
62
53
|
const name = declaration && ts.isFunctionDeclaration(declaration) ? declaration.name : undefined;
|
|
63
54
|
const implementations = name ? checker.getSymbolAtLocation(name)?.declarations ?? [] : [declaration];
|
|
64
55
|
return implementations
|
|
65
|
-
.map(
|
|
56
|
+
.map(getBody)
|
|
66
57
|
.filter((body) => body !== undefined);
|
|
67
58
|
}
|
|
68
59
|
|
|
@@ -113,17 +104,21 @@ export const noComposableInHeadGetter: Rule.RuleModule = {
|
|
|
113
104
|
}
|
|
114
105
|
|
|
115
106
|
if (!checker || !nodeMap) return;
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
107
|
+
for (const body of getImplementationBodies(checker, nodeMap.get(node) as ts.CallExpression)) {
|
|
108
|
+
const composable = findCalledComposable(body);
|
|
109
|
+
if (!composable) continue;
|
|
110
|
+
context.report({
|
|
111
|
+
data: {
|
|
112
|
+
composable,
|
|
113
|
+
function: context.sourceCode.getText(callee),
|
|
114
|
+
head,
|
|
115
|
+
},
|
|
116
|
+
messageId: 'indirectGetter',
|
|
117
|
+
node,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
127
122
|
}
|
|
128
123
|
|
|
129
124
|
return {
|
|
@@ -16,8 +16,8 @@ function isSilent(callback: CallArgument): boolean {
|
|
|
16
16
|
if (callback.type !== 'ArrowFunctionExpression' && callback.type !== 'FunctionExpression') return false;
|
|
17
17
|
const { body } = callback;
|
|
18
18
|
if (body.type !== 'BlockStatement') return isNothing(body);
|
|
19
|
-
const [statement
|
|
20
|
-
return !statement || (
|
|
19
|
+
const [statement] = body.body;
|
|
20
|
+
return !statement || (body.body.length === 1 && statement.type === 'ReturnStatement' && isNothing(statement.argument));
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const noSilentCatch: Rule.RuleModule = {
|
|
@@ -32,7 +32,6 @@ export const noSilentCatch: Rule.RuleModule = {
|
|
|
32
32
|
|| !isSilent(callback)
|
|
33
33
|
) return;
|
|
34
34
|
|
|
35
|
-
// A comment right before or inside the callback is the reason the rejection can be ignored.
|
|
36
35
|
const { sourceCode } = context;
|
|
37
36
|
if (sourceCode.getCommentsBefore(callback).length || sourceCode.getCommentsInside(callback).length) return;
|
|
38
37
|
|
|
@@ -19,8 +19,7 @@ function isNonPromiseThenable(checker: TypeChecker, type: Type): boolean {
|
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// Zod
|
|
23
|
-
// intersections such as `SafePromise` count); any other thenable counts as a truthy result.
|
|
22
|
+
// Zod uses `instanceof Promise`, which also accepts subclasses and branded Promise values.
|
|
24
23
|
function isPromise(checker: TypeChecker, type: Type): boolean {
|
|
25
24
|
if (type.isIntersection()) return type.types.some((part) => isPromise(checker, part));
|
|
26
25
|
if (type.getSymbol()?.getName() === 'Promise') return true;
|