@jupyter/eslint-plugin 1.0.1 → 1.1.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/lib/index.d.ts +68 -0
- package/lib/index.js +42 -11
- package/lib/rules/galata-prefer-filebrowser-helper.d.ts +5 -0
- package/lib/rules/galata-prefer-filebrowser-helper.js +105 -0
- package/lib/rules/incorrect-translator-usage.d.ts +4 -0
- package/lib/rules/incorrect-translator-usage.js +208 -0
- package/lib/rules/no-dynamic-translation.d.ts +4 -0
- package/lib/rules/no-dynamic-translation.js +92 -0
- package/lib/rules/no-pageconfig-base-url.d.ts +4 -0
- package/lib/rules/no-pageconfig-base-url.js +37 -0
- package/lib/rules/no-translation-concatenation.js +46 -84
- package/lib/rules/no-untranslated-string.js +7 -4
- package/lib/rules/plugin-activation-args.js +1 -2
- package/lib/rules/prefer-signal-this-arg.d.ts +7 -0
- package/lib/rules/prefer-signal-this-arg.js +196 -0
- package/lib/rules/require-disposable-ownership.d.ts +5 -0
- package/lib/rules/require-disposable-ownership.js +120 -0
- package/lib/rules/require-disposable-transfer.d.ts +5 -0
- package/lib/rules/require-disposable-transfer.js +223 -0
- package/lib/rules/require-signal-cleanup.d.ts +8 -0
- package/lib/rules/require-signal-cleanup.js +164 -0
- package/lib/rules/require-signal-this-arg.d.ts +5 -0
- package/lib/rules/require-signal-this-arg.js +74 -0
- package/lib/rules/token-format.js +1 -2
- package/lib/utils/disposables.d.ts +64 -0
- package/lib/utils/disposables.js +1723 -0
- package/lib/utils/playwright-selectors.d.ts +66 -0
- package/lib/utils/playwright-selectors.js +193 -0
- package/lib/utils/signal-lifetime.d.ts +158 -0
- package/lib/utils/signal-lifetime.js +755 -0
- package/lib/utils/signals.d.ts +143 -0
- package/lib/utils/signals.js +601 -0
- package/lib/utils/translation.d.ts +45 -0
- package/lib/utils/translation.js +122 -0
- package/package.json +9 -2
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.walkFrom = walkFrom;
|
|
41
|
+
exports.isConnectCall = isConnectCall;
|
|
42
|
+
exports.isDisconnectCall = isDisconnectCall;
|
|
43
|
+
exports.isDisposedSignalWiring = isDisposedSignalWiring;
|
|
44
|
+
exports.collectSignalNamespaceLocalNames = collectSignalNamespaceLocalNames;
|
|
45
|
+
exports.isSignalNamespaceCleanupCall = isSignalNamespaceCleanupCall;
|
|
46
|
+
exports.getEnclosingClass = getEnclosingClass;
|
|
47
|
+
exports.getThisBinding = getThisBinding;
|
|
48
|
+
exports.resolveClassMember = resolveClassMember;
|
|
49
|
+
exports.resolveUnboundThisMethodConnect = resolveUnboundThisMethodConnect;
|
|
50
|
+
exports.classHasCleanupEvidence = classHasCleanupEvidence;
|
|
51
|
+
exports.classUsesReceiverBasedCleanup = classUsesReceiverBasedCleanup;
|
|
52
|
+
exports.classExtendsLuminoWidget = classExtendsLuminoWidget;
|
|
53
|
+
exports.typeExtendsLuminoWidget = typeExtendsLuminoWidget;
|
|
54
|
+
exports.methodUsesThis = methodUsesThis;
|
|
55
|
+
exports.looksLikeSignalByName = looksLikeSignalByName;
|
|
56
|
+
exports.classifySignalReceiver = classifySignalReceiver;
|
|
57
|
+
const visitor_keys_1 = require("@typescript-eslint/visitor-keys");
|
|
58
|
+
const ts = __importStar(require("typescript"));
|
|
59
|
+
/**
|
|
60
|
+
* Iterative AST walk from `root`, visiting every node. The visitor may return
|
|
61
|
+
* 'skip-children' to avoid descending into a node, or 'stop' to abort the
|
|
62
|
+
* whole walk.
|
|
63
|
+
*/
|
|
64
|
+
function walkFrom(root, visit) {
|
|
65
|
+
const stack = [root];
|
|
66
|
+
while (stack.length > 0) {
|
|
67
|
+
const node = stack.pop();
|
|
68
|
+
const action = visit(node);
|
|
69
|
+
if (action === 'stop') {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (action === 'skip-children') {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const keys = visitor_keys_1.visitorKeys[node.type] ?? (0, visitor_keys_1.getKeys)(node);
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
const child = node[key];
|
|
78
|
+
if (Array.isArray(child)) {
|
|
79
|
+
for (const item of child) {
|
|
80
|
+
if (isNode(item)) {
|
|
81
|
+
stack.push(item);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (isNode(child)) {
|
|
86
|
+
stack.push(child);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function isNode(value) {
|
|
92
|
+
return (typeof value === 'object' &&
|
|
93
|
+
value !== null &&
|
|
94
|
+
typeof value.type === 'string');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Checks if a call expression is a non-computed `<expr>.<name>(...)` call.
|
|
98
|
+
*/
|
|
99
|
+
function isMemberCallNamed(node, names) {
|
|
100
|
+
return (node.callee.type === 'MemberExpression' &&
|
|
101
|
+
!node.callee.computed &&
|
|
102
|
+
node.callee.property.type === 'Identifier' &&
|
|
103
|
+
names.includes(node.callee.property.name));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Checks if a node represents `<expr>.connect(...)`.
|
|
107
|
+
*/
|
|
108
|
+
function isConnectCall(node) {
|
|
109
|
+
return isMemberCallNamed(node, ['connect']);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Checks if a node represents `<expr>.disconnect(...)` or a call to one of
|
|
113
|
+
* the additional cleanup method names.
|
|
114
|
+
*/
|
|
115
|
+
function isDisconnectCall(node, extraMethodNames = []) {
|
|
116
|
+
return isMemberCallNamed(node, ['disconnect', ...extraMethodNames]);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Checks if a node represents `<expr>.disposed.connect(...)` — disposal
|
|
120
|
+
* cleanup wired through a `disposed`-style signal.
|
|
121
|
+
*/
|
|
122
|
+
function isDisposedSignalWiring(node) {
|
|
123
|
+
if (!isConnectCall(node)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const object = node.callee.object;
|
|
127
|
+
return (object.type === 'MemberExpression' &&
|
|
128
|
+
!object.computed &&
|
|
129
|
+
object.property.type === 'Identifier' &&
|
|
130
|
+
object.property.name === 'disposed');
|
|
131
|
+
}
|
|
132
|
+
const SIGNAL_CLEANUP_STATICS = [
|
|
133
|
+
'clearData',
|
|
134
|
+
'disconnectAll',
|
|
135
|
+
'disconnectReceiver',
|
|
136
|
+
'disconnectSender',
|
|
137
|
+
'disconnectBetween'
|
|
138
|
+
];
|
|
139
|
+
/**
|
|
140
|
+
* Collects the names under which the Lumino `Signal` namespace is reachable in
|
|
141
|
+
* this file. Always includes 'Signal' (ambient/global usage), plus local
|
|
142
|
+
* aliases from `import { Signal as X } from '@lumino/signaling'` and the
|
|
143
|
+
* qualified `ns.Signal` form of `import * as ns from '@lumino/signaling'`.
|
|
144
|
+
*/
|
|
145
|
+
function collectSignalNamespaceLocalNames(program) {
|
|
146
|
+
const names = new Set(['Signal']);
|
|
147
|
+
for (const statement of program.body) {
|
|
148
|
+
if (statement.type === 'ImportDeclaration' &&
|
|
149
|
+
statement.source.value === '@lumino/signaling') {
|
|
150
|
+
for (const specifier of statement.specifiers) {
|
|
151
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
152
|
+
specifier.imported.type === 'Identifier' &&
|
|
153
|
+
specifier.imported.name === 'Signal') {
|
|
154
|
+
names.add(specifier.local.name);
|
|
155
|
+
}
|
|
156
|
+
else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
157
|
+
names.add(`${specifier.local.name}.Signal`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return names;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Dotted source name of an identifier or of a single-level `a.b` member
|
|
166
|
+
* expression; null for anything deeper or computed.
|
|
167
|
+
*/
|
|
168
|
+
function qualifiedName(node) {
|
|
169
|
+
if (node.type === 'Identifier') {
|
|
170
|
+
return node.name;
|
|
171
|
+
}
|
|
172
|
+
if (node.type === 'MemberExpression' &&
|
|
173
|
+
!node.computed &&
|
|
174
|
+
node.object.type === 'Identifier' &&
|
|
175
|
+
node.property.type === 'Identifier') {
|
|
176
|
+
return `${node.object.name}.${node.property.name}`;
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Checks if a node represents `Signal.clearData(...)` or one of the other
|
|
182
|
+
* static disconnect helpers on the `Signal` namespace (under any local name).
|
|
183
|
+
*/
|
|
184
|
+
function isSignalNamespaceCleanupCall(node, signalLocalNames) {
|
|
185
|
+
if (!isMemberCallNamed(node, SIGNAL_CLEANUP_STATICS)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
const name = qualifiedName(node.callee.object);
|
|
189
|
+
return name !== null && signalLocalNames.has(name);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Returns the innermost class enclosing `node`, or null if the node is not
|
|
193
|
+
* inside a class body.
|
|
194
|
+
*/
|
|
195
|
+
function getEnclosingClass(node) {
|
|
196
|
+
let current = node.parent;
|
|
197
|
+
while (current) {
|
|
198
|
+
if (current.type === 'ClassDeclaration' ||
|
|
199
|
+
current.type === 'ClassExpression') {
|
|
200
|
+
return current;
|
|
201
|
+
}
|
|
202
|
+
current = current.parent;
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* What does `this` denote at `node`?
|
|
208
|
+
*
|
|
209
|
+
* - `'instance'`: an instance of the enclosing class.
|
|
210
|
+
* - `'constructor'`: the class object itself — `static` members and static
|
|
211
|
+
* blocks.
|
|
212
|
+
* - `'none'`: neither, because `this` is rebound on the way up: a nested
|
|
213
|
+
* regular function, an object-literal method, or module scope. Whatever
|
|
214
|
+
* `this` is there, it is not decided by the enclosing class.
|
|
215
|
+
*
|
|
216
|
+
* Arrow functions are transparent. Regular functions are not, unless they are
|
|
217
|
+
* the value of a class member — that is the method itself, not a nested one.
|
|
218
|
+
*/
|
|
219
|
+
function getThisBinding(node) {
|
|
220
|
+
let current = node.parent;
|
|
221
|
+
while (current) {
|
|
222
|
+
if (current.type === 'StaticBlock') {
|
|
223
|
+
return 'constructor';
|
|
224
|
+
}
|
|
225
|
+
if (current.type === 'FunctionExpression' ||
|
|
226
|
+
current.type === 'FunctionDeclaration' ||
|
|
227
|
+
current.type === 'TSDeclareFunction') {
|
|
228
|
+
const parent = current.parent;
|
|
229
|
+
const isClassMemberValue = (parent?.type === 'MethodDefinition' ||
|
|
230
|
+
parent?.type === 'PropertyDefinition') &&
|
|
231
|
+
parent.value === current;
|
|
232
|
+
if (!isClassMemberValue) {
|
|
233
|
+
return 'none';
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (current.type === 'MethodDefinition' ||
|
|
237
|
+
current.type === 'PropertyDefinition') {
|
|
238
|
+
return current.static ? 'constructor' : 'instance';
|
|
239
|
+
}
|
|
240
|
+
if (current.type === 'ClassDeclaration' ||
|
|
241
|
+
current.type === 'ClassExpression') {
|
|
242
|
+
// Reached the class without crossing one of its members — a decorator or
|
|
243
|
+
// a heritage expression, where `this` is not the instance.
|
|
244
|
+
return 'none';
|
|
245
|
+
}
|
|
246
|
+
current = current.parent;
|
|
247
|
+
}
|
|
248
|
+
return 'none';
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Finds the class member named `name` in the class body, matching privacy
|
|
252
|
+
* (`this.#name` vs `this.name`) and staticness. Names are compared without
|
|
253
|
+
* the `#` prefix.
|
|
254
|
+
*/
|
|
255
|
+
function resolveClassMember(classNode, name, opts) {
|
|
256
|
+
for (const member of classNode.body.body) {
|
|
257
|
+
if (member.type !== 'MethodDefinition' &&
|
|
258
|
+
member.type !== 'PropertyDefinition') {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (member.static !== opts.isStatic || member.computed) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const key = member.key;
|
|
265
|
+
if (opts.isPrivate) {
|
|
266
|
+
if (key.type === 'PrivateIdentifier' && key.name === name) {
|
|
267
|
+
return member;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else if ((key.type === 'Identifier' && key.name === name) ||
|
|
271
|
+
(key.type === 'Literal' && key.value === name)) {
|
|
272
|
+
return member;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Detects the "unbound method" connect shape: a single-argument
|
|
279
|
+
* `signal.connect(this.X)` where `X` resolves in the enclosing class to a
|
|
280
|
+
* regular method (or function-expression property) whose body actually uses
|
|
281
|
+
* `this` — the case where the callback breaks at runtime without a thisArg.
|
|
282
|
+
* Returns null for every other callback shape (arrow properties, methods not
|
|
283
|
+
* using `this`, unresolved members, inline callbacks, free variables, ...).
|
|
284
|
+
*
|
|
285
|
+
* Shared by `require-signal-this-arg` (reports exactly this case) and
|
|
286
|
+
* `prefer-signal-this-arg` (reports everything but this case), so the two
|
|
287
|
+
* rules always partition cleanly.
|
|
288
|
+
*/
|
|
289
|
+
function resolveUnboundThisMethodConnect(node) {
|
|
290
|
+
if (node.arguments.length !== 1) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
const arg = node.arguments[0];
|
|
294
|
+
if (arg.type !== 'MemberExpression' ||
|
|
295
|
+
arg.object.type !== 'ThisExpression' ||
|
|
296
|
+
arg.computed) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
const property = arg.property;
|
|
300
|
+
if (property.type !== 'Identifier' && property.type !== 'PrivateIdentifier') {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
const isPrivate = property.type === 'PrivateIdentifier';
|
|
304
|
+
const name = property.name;
|
|
305
|
+
const enclosingClass = getEnclosingClass(node);
|
|
306
|
+
if (!enclosingClass) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
const thisBinding = getThisBinding(node);
|
|
310
|
+
if (thisBinding === 'none') {
|
|
311
|
+
// Inside a nested regular function `this` is not the enclosing class, so
|
|
312
|
+
// `this.X` does not refer to a member of it and must not be resolved
|
|
313
|
+
// against its body.
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
const member = resolveClassMember(enclosingClass, name, {
|
|
317
|
+
isPrivate,
|
|
318
|
+
isStatic: thisBinding === 'constructor'
|
|
319
|
+
});
|
|
320
|
+
if (!member) {
|
|
321
|
+
// Not found in this class (possibly inherited).
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
let fn;
|
|
325
|
+
if (member.type === 'PropertyDefinition') {
|
|
326
|
+
if (!member.value || member.value.type !== 'FunctionExpression') {
|
|
327
|
+
// Arrow-function properties are lexically bound and safe; other
|
|
328
|
+
// values are not resolvable callbacks.
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
fn = member.value;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
if (member.kind !== 'method') {
|
|
335
|
+
// Getters/setters are evaluated, not referenced.
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
if (member.value.type !== 'FunctionExpression') {
|
|
339
|
+
// Abstract or overload signature — no body to inspect.
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
fn = member.value;
|
|
343
|
+
}
|
|
344
|
+
if (!methodUsesThis(fn)) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
return { arg, name, isPrivate };
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Scans an entire class body for any evidence that signal connections are
|
|
351
|
+
* cleaned up somewhere: `Signal.clearData(...)`-style static cleanup calls or
|
|
352
|
+
* `.disconnect(...)` calls (or configured additional cleanup methods). Nested
|
|
353
|
+
* classes are opaque — their cleanup does not count for the outer class.
|
|
354
|
+
*/
|
|
355
|
+
function classHasCleanupEvidence(classNode, signalLocalNames, extraMethodNames = []) {
|
|
356
|
+
let found = false;
|
|
357
|
+
walkFrom(classNode.body, node => {
|
|
358
|
+
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
|
|
359
|
+
return 'skip-children';
|
|
360
|
+
}
|
|
361
|
+
if (node.type === 'CallExpression') {
|
|
362
|
+
if (isSignalNamespaceCleanupCall(node, signalLocalNames) ||
|
|
363
|
+
isDisconnectCall(node, extraMethodNames)) {
|
|
364
|
+
found = true;
|
|
365
|
+
return 'stop';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return undefined;
|
|
369
|
+
});
|
|
370
|
+
return found;
|
|
371
|
+
}
|
|
372
|
+
const RECEIVER_CLEANUP_STATICS = [
|
|
373
|
+
'clearData',
|
|
374
|
+
'disconnectReceiver',
|
|
375
|
+
'disconnectAll'
|
|
376
|
+
];
|
|
377
|
+
/**
|
|
378
|
+
* Scans a class body for cleanup calls that match connections **by
|
|
379
|
+
* receiver**: `Signal.clearData(this)` / `Signal.disconnectReceiver(this)` /
|
|
380
|
+
* `Signal.disconnectAll(this)` / `Signal.disconnectBetween(sender, this)`
|
|
381
|
+
* (under any local `Signal` alias), or a two-argument
|
|
382
|
+
* `.disconnect(callback, this)` call. A class using these relies on its
|
|
383
|
+
* connections having been registered with `this` as the thisArg. Nested
|
|
384
|
+
* classes are opaque.
|
|
385
|
+
*/
|
|
386
|
+
function classUsesReceiverBasedCleanup(classNode, signalLocalNames) {
|
|
387
|
+
let found = false;
|
|
388
|
+
walkFrom(classNode.body, node => {
|
|
389
|
+
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
|
|
390
|
+
return 'skip-children';
|
|
391
|
+
}
|
|
392
|
+
if (node.type === 'CallExpression') {
|
|
393
|
+
const receiverIndex = isSignalNamespaceCleanupCall(node, signalLocalNames)
|
|
394
|
+
? isMemberCallNamed(node, RECEIVER_CLEANUP_STATICS)
|
|
395
|
+
? 0
|
|
396
|
+
: isMemberCallNamed(node, ['disconnectBetween'])
|
|
397
|
+
? 1
|
|
398
|
+
: -1
|
|
399
|
+
: isDisconnectCall(node) && node.arguments.length === 2
|
|
400
|
+
? 1
|
|
401
|
+
: -1;
|
|
402
|
+
if (receiverIndex >= 0 &&
|
|
403
|
+
node.arguments[receiverIndex]?.type === 'ThisExpression') {
|
|
404
|
+
found = true;
|
|
405
|
+
return 'stop';
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return undefined;
|
|
409
|
+
});
|
|
410
|
+
return found;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Type-aware check: does this class (transitively) extend Lumino's `Widget`
|
|
414
|
+
* (any class declared in `@lumino/widgets`)? Those base classes call
|
|
415
|
+
* `Signal.clearData(this)` from `dispose()`, so subclasses rely on
|
|
416
|
+
* receiver-based cleanup. Returns false when type information is
|
|
417
|
+
* unavailable or resolution fails.
|
|
418
|
+
*/
|
|
419
|
+
function classExtendsLuminoWidget(classNode, checker, services) {
|
|
420
|
+
if (!classNode.superClass ||
|
|
421
|
+
!checker ||
|
|
422
|
+
!services ||
|
|
423
|
+
!services.esTreeNodeToTSNodeMap) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(classNode);
|
|
428
|
+
if (!tsNode) {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
return typeExtendsLuminoWidget(checker.getTypeAtLocation(tsNode), checker);
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
// Fall through: treat resolution failures as "not a Widget".
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Type-aware check: does `type` (transitively) extend a class declared in
|
|
440
|
+
* `@lumino/widgets`? Used both for "does the receiver class inherit
|
|
441
|
+
* `Widget.dispose()`'s `Signal.clearData(this)`" and for rejecting widget-typed
|
|
442
|
+
* hops when walking a sender expression (a widget reached through a long-lived
|
|
443
|
+
* service is not itself long-lived).
|
|
444
|
+
*/
|
|
445
|
+
function typeExtendsLuminoWidget(type, checker) {
|
|
446
|
+
const seen = new Set();
|
|
447
|
+
const queue = [type];
|
|
448
|
+
while (queue.length > 0) {
|
|
449
|
+
const current = queue.pop();
|
|
450
|
+
if (seen.has(current)) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
seen.add(current);
|
|
454
|
+
if (current.isUnion() || current.isIntersection()) {
|
|
455
|
+
queue.push(...current.types);
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const symbol = current.getSymbol();
|
|
459
|
+
if (symbol && isDeclaredInLuminoPackage(symbol, 'widgets')) {
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
const objectFlags = current.objectFlags ?? 0;
|
|
463
|
+
if (objectFlags & ts.ObjectFlags.Reference) {
|
|
464
|
+
// `class StaticNotebook extends WindowedList<NotebookViewModel>` gives a
|
|
465
|
+
// type *reference*, which is not `isClassOrInterface()`. Descend into
|
|
466
|
+
// the generic target so the base chain stays walkable.
|
|
467
|
+
const target = current.target;
|
|
468
|
+
if (target && target !== current) {
|
|
469
|
+
queue.push(target);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (current.isClassOrInterface()) {
|
|
473
|
+
try {
|
|
474
|
+
queue.push(...checker.getBaseTypes(current));
|
|
475
|
+
}
|
|
476
|
+
catch {
|
|
477
|
+
// Unresolvable base list — stop descending this branch.
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Checks whether a function body references `this` in its own binding.
|
|
485
|
+
* Descends into arrow functions (lexically transparent) but not into nested
|
|
486
|
+
* regular functions, static blocks, or nested classes (own `this` binding).
|
|
487
|
+
*/
|
|
488
|
+
function methodUsesThis(fn) {
|
|
489
|
+
let found = false;
|
|
490
|
+
walkFrom(fn.body, node => {
|
|
491
|
+
if (node.type === 'FunctionExpression' ||
|
|
492
|
+
node.type === 'FunctionDeclaration' ||
|
|
493
|
+
node.type === 'TSDeclareFunction' ||
|
|
494
|
+
node.type === 'StaticBlock' ||
|
|
495
|
+
node.type === 'ClassDeclaration' ||
|
|
496
|
+
node.type === 'ClassExpression') {
|
|
497
|
+
return 'skip-children';
|
|
498
|
+
}
|
|
499
|
+
if (node.type === 'ThisExpression') {
|
|
500
|
+
found = true;
|
|
501
|
+
return 'stop';
|
|
502
|
+
}
|
|
503
|
+
return undefined;
|
|
504
|
+
});
|
|
505
|
+
return found;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Syntactic hint that an expression is likely a Lumino signal, based on
|
|
509
|
+
* conventional signal naming (`stateChanged`, `disposed`, `somethingSignal`).
|
|
510
|
+
*/
|
|
511
|
+
function looksLikeSignalByName(objectNode) {
|
|
512
|
+
let name = null;
|
|
513
|
+
if (objectNode.type === 'Identifier') {
|
|
514
|
+
name = objectNode.name;
|
|
515
|
+
}
|
|
516
|
+
else if (objectNode.type === 'MemberExpression' &&
|
|
517
|
+
!objectNode.computed &&
|
|
518
|
+
objectNode.property.type === 'Identifier') {
|
|
519
|
+
name = objectNode.property.name;
|
|
520
|
+
}
|
|
521
|
+
return name !== null && /(signal|changed|disposed)$/i.test(name);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Classifies the static type of a `.connect()` receiver expression:
|
|
525
|
+
* - 'signal': resolves to Lumino `ISignal`/`Signal` (by symbol name or a
|
|
526
|
+
* declaration living in `@lumino/signaling`)
|
|
527
|
+
* - 'not-signal': resolves to some other concrete type
|
|
528
|
+
* - 'unknown': no type information, `any`/`unknown`, or resolution failure
|
|
529
|
+
*/
|
|
530
|
+
function classifySignalReceiver(objectNode, checker, services) {
|
|
531
|
+
if (!checker || !services || !services.esTreeNodeToTSNodeMap) {
|
|
532
|
+
return 'unknown';
|
|
533
|
+
}
|
|
534
|
+
try {
|
|
535
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(objectNode);
|
|
536
|
+
if (!tsNode) {
|
|
537
|
+
return 'unknown';
|
|
538
|
+
}
|
|
539
|
+
return classifyTsType(checker.getTypeAtLocation(tsNode), checker);
|
|
540
|
+
}
|
|
541
|
+
catch {
|
|
542
|
+
return 'unknown';
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
function classifyTsType(type, checker) {
|
|
546
|
+
if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
|
|
547
|
+
return 'unknown';
|
|
548
|
+
}
|
|
549
|
+
if (type.isUnion()) {
|
|
550
|
+
const results = type.types
|
|
551
|
+
.filter(t => !(t.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)))
|
|
552
|
+
.map(t => classifyTsType(t, checker));
|
|
553
|
+
if (results.includes('signal')) {
|
|
554
|
+
return 'signal';
|
|
555
|
+
}
|
|
556
|
+
if (results.length > 0 && results.every(r => r === 'not-signal')) {
|
|
557
|
+
return 'not-signal';
|
|
558
|
+
}
|
|
559
|
+
return 'unknown';
|
|
560
|
+
}
|
|
561
|
+
const rawSymbol = type.aliasSymbol ?? type.getSymbol();
|
|
562
|
+
if (!rawSymbol) {
|
|
563
|
+
return 'unknown';
|
|
564
|
+
}
|
|
565
|
+
// Follow import/re-export aliases so we classify the original declaration.
|
|
566
|
+
let symbol = rawSymbol;
|
|
567
|
+
if (rawSymbol.flags & ts.SymbolFlags.Alias) {
|
|
568
|
+
try {
|
|
569
|
+
symbol = checker.getAliasedSymbol(rawSymbol);
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
symbol = rawSymbol;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const name = symbol.getName();
|
|
576
|
+
if (name === 'ISignal' || name === 'Signal') {
|
|
577
|
+
// Unrelated libraries also export types named Signal; require either a
|
|
578
|
+
// @lumino/signaling declaration or the Lumino signal surface
|
|
579
|
+
// (connect + disconnect members) before classifying as a signal.
|
|
580
|
+
if (isDeclaredInLuminoPackage(symbol, 'signaling') ||
|
|
581
|
+
(type.getProperty('connect') !== undefined &&
|
|
582
|
+
type.getProperty('disconnect') !== undefined)) {
|
|
583
|
+
return 'signal';
|
|
584
|
+
}
|
|
585
|
+
return 'not-signal';
|
|
586
|
+
}
|
|
587
|
+
if (isDeclaredInLuminoPackage(symbol, 'signaling')) {
|
|
588
|
+
return 'signal';
|
|
589
|
+
}
|
|
590
|
+
return 'not-signal';
|
|
591
|
+
}
|
|
592
|
+
function isDeclaredInLuminoPackage(symbol, packageName) {
|
|
593
|
+
for (const declaration of symbol.getDeclarations() ?? []) {
|
|
594
|
+
const fileName = declaration.getSourceFile().fileName;
|
|
595
|
+
if (fileName.includes(`lumino/${packageName}`) ||
|
|
596
|
+
fileName.includes(`lumino\\${packageName}`)) {
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
+
/**
|
|
3
|
+
* Methods of the TranslationBundle interface from `@jupyterlab/translation`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const BUNDLE_METHODS: Set<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Property names under which a translation bundle may be stored so that the
|
|
8
|
+
* string extractor recognizes its usages (this.trans, this._trans,
|
|
9
|
+
* this.props.trans, props.trans).
|
|
10
|
+
* See jupyterlab.readthedocs.io/en/stable/extension/internationalization.html#rules
|
|
11
|
+
*/
|
|
12
|
+
export declare const BUNDLE_PROPERTY_NAMES: Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* The only accepted name for a local variable holding a translation bundle.
|
|
15
|
+
*/
|
|
16
|
+
export declare const BUNDLE_VARIABLE_NAME = "trans";
|
|
17
|
+
/**
|
|
18
|
+
* For each bundle method, the argument indices the string extractor reads
|
|
19
|
+
* straight from the source and must therefore be static text.
|
|
20
|
+
*
|
|
21
|
+
* The `domain` argument of `dcnpgettext` is deliberately left out: it selects a
|
|
22
|
+
* catalog at runtime, it is not extracted message text.
|
|
23
|
+
*/
|
|
24
|
+
export declare const STATIC_ARGUMENT_INDICES: Record<string, readonly number[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Skips TypeScript-only and optional-chaining wrapper nodes so the underlying
|
|
27
|
+
* expression can be inspected.
|
|
28
|
+
*/
|
|
29
|
+
export declare function unwrapExpression(node: TSESTree.Node): TSESTree.Node;
|
|
30
|
+
/**
|
|
31
|
+
* Returns true when a member expression names one of the exact targets the
|
|
32
|
+
* string extractor recognizes as a translation bundle:
|
|
33
|
+
* this.trans, this._trans, props.trans, this.props.trans.
|
|
34
|
+
* See jupyterlab.readthedocs.io/en/stable/extension/internationalization.html#rules
|
|
35
|
+
*/
|
|
36
|
+
export declare function isRecognizedBundleMember(node: TSESTree.MemberExpression): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Returns true if the node is a recognized JupyterLab translation bundle:
|
|
39
|
+
* trans | this.trans | this._trans | props.trans | this.props.trans
|
|
40
|
+
*
|
|
41
|
+
* TypeScript-only wrappers are seen through, so `this.trans!` and
|
|
42
|
+
* `(trans as any)` are recognized too — they still name the same bundle.
|
|
43
|
+
* See jupyterlab.readthedocs.io/en/stable/extension/internationalization.html#rules
|
|
44
|
+
*/
|
|
45
|
+
export declare function isTransBundle(node: TSESTree.Node): boolean;
|