@inflexa-ai/typecheck 0.6.0 → 0.7.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.
|
@@ -2,6 +2,9 @@ import { isCallExpression, isIdentifier, isSignatureDeclaration, SyntaxKind } fr
|
|
|
2
2
|
import { isUnionType, SignatureKind, SymbolFlags, TypeFlags } from '@typescript/native/unstable/sync';
|
|
3
3
|
import { indirectionOf } from '../helpers/reflective-calls.js';
|
|
4
4
|
import { stringArraysOnly } from '../rule-options.js';
|
|
5
|
+
const missingSignalMessage = (combineAdvice) => 'This call cannot be cancelled: {{problem}}. Pass a `signal` typed `AbortSignal`, not `AbortSignal | undefined`. Inside a query function it is the `signal` of the context the library hands you. Where nothing can cancel the call, a mutation among them, it is a deadline: `AbortSignal.timeout(ms)`. ' +
|
|
6
|
+
combineAdvice +
|
|
7
|
+
' A wrapper declares `signal: AbortSignal` in its own options and the compiler asks its callers.';
|
|
5
8
|
const DECLARATION_FILE = /\.d\.[cm]?ts$/i;
|
|
6
9
|
function declarationName(declaration) {
|
|
7
10
|
if (!isSignatureDeclaration(declaration) || !('name' in declaration))
|
|
@@ -15,16 +18,17 @@ export const requireAbortSignal = {
|
|
|
15
18
|
description: 'Require an AbortSignal on every call into the API client and on every fetch',
|
|
16
19
|
url: 'https://github.com/inflexa-ai/lint/blob/main/docs/rules/require-abort-signal.md',
|
|
17
20
|
},
|
|
18
|
-
defaultOptions: { declaredIn: [] },
|
|
21
|
+
defaultOptions: { declaredIn: [], hint: '' },
|
|
19
22
|
messages: {
|
|
20
23
|
indirectCall: 'This call goes through `{{through}}`, where the options cannot be read, so nothing here can tell whether the request carries a `signal`. Call the method directly, `api.get(path, { signal })`: app code has no need for the indirection, and reaching for it is how a request ends up with nothing to cancel it.',
|
|
21
|
-
missingSignal: '
|
|
24
|
+
missingSignal: missingSignalMessage('Where both exist, combine them with `AbortSignal.any([signal, AbortSignal.timeout(ms)])`. `AbortSignal.any` first shipped in Chrome 116, Edge 116, Firefox 124 and Safari 17.4, and the document of this rule gives a form for an older browser.'),
|
|
25
|
+
missingSignalWithHint: missingSignalMessage('{{hint}}'),
|
|
22
26
|
},
|
|
23
27
|
},
|
|
24
28
|
checkOptions: stringArraysOnly,
|
|
25
29
|
create(context) {
|
|
26
30
|
const { checker } = context;
|
|
27
|
-
const { declaredIn } = context.options;
|
|
31
|
+
const { declaredIn, hint } = context.options;
|
|
28
32
|
if (declaredIn.length === 0)
|
|
29
33
|
return {};
|
|
30
34
|
const clientFiles = declaredIn.map((pattern) => new RegExp(pattern));
|
|
@@ -95,8 +99,9 @@ export const requireAbortSignal = {
|
|
|
95
99
|
if (!signatureIsTarget(signature))
|
|
96
100
|
return;
|
|
97
101
|
const problem = problemWith(call, signature);
|
|
98
|
-
if (problem
|
|
99
|
-
|
|
102
|
+
if (problem === undefined)
|
|
103
|
+
return;
|
|
104
|
+
context.report(hint ? { node: call, messageId: 'missingSignalWithHint', data: { problem, hint } } : { node: call, messageId: 'missingSignal', data: { problem } });
|
|
100
105
|
},
|
|
101
106
|
};
|
|
102
107
|
},
|
package/package.json
CHANGED