@jupyter/eslint-plugin 1.2.0 → 1.3.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.
@@ -100,3 +100,18 @@ export declare function extractStaticSelectorText(node: TSESTree.Expression, opt
100
100
  * is static.
101
101
  */
102
102
  export declare function combineStaticSelectorText(match: SelectorInteractionMatch): string | null;
103
+ /**
104
+ * Whether `node` bounds the statements a rule may read as "what ran before".
105
+ *
106
+ * A rule that reasons about UI state — which menu is open, what was selected —
107
+ * reads the statements preceding a gesture. That reading has to stop somewhere,
108
+ * and the boundary is the unit that runs as one: a test callback or a named
109
+ * function.
110
+ */
111
+ export declare function isTestScopeBoundary(node: TSESTree.Node): boolean;
112
+ /**
113
+ * The innermost test callback or named function containing `node`, which is
114
+ * where a lookback over preceding statements has to stop. Falls back to the
115
+ * `Program` for a gesture written at the top level of a file.
116
+ */
117
+ export declare function enclosingTestScope(node: TSESTree.Node): TSESTree.Node;
@@ -10,6 +10,8 @@ exports.isRightClick = isRightClick;
10
10
  exports.matchSelectorInteraction = matchSelectorInteraction;
11
11
  exports.extractStaticSelectorText = extractStaticSelectorText;
12
12
  exports.combineStaticSelectorText = combineStaticSelectorText;
13
+ exports.isTestScopeBoundary = isTestScopeBoundary;
14
+ exports.enclosingTestScope = enclosingTestScope;
13
15
  const utils_1 = require("@typescript-eslint/utils");
14
16
  /**
15
17
  * Playwright locator-producing methods.
@@ -304,3 +306,81 @@ function combineStaticSelectorText(match) {
304
306
  }
305
307
  return parts.length > 0 ? parts.join(' ') : null;
306
308
  }
309
+ /**
310
+ * Calls whose callback is stored and run later. Statements next to such a call
311
+ * say nothing about the state its body starts in.
312
+ */
313
+ const DEFERRED_CALLBACK_CALLEES = new Set([
314
+ 'test',
315
+ 'it',
316
+ 'describe',
317
+ 'suite',
318
+ 'beforeAll',
319
+ 'beforeEach',
320
+ 'afterAll',
321
+ 'afterEach'
322
+ ]);
323
+ /**
324
+ * The expression a callee is written on, or null once the name itself is
325
+ * reached. A parameterized test is called twice, `test.each(cases)('name',
326
+ * cb)`, and the table form tags a template first, `` test.each`a | b`('name',
327
+ * cb) ``. Stopping at the inner call would read no name and leave `cb` outside
328
+ * any test scope, so one test's state would reach the next.
329
+ */
330
+ function calleeReceiver(node) {
331
+ switch (node.type) {
332
+ case 'MemberExpression':
333
+ return node.object;
334
+ case 'CallExpression':
335
+ return node.callee;
336
+ case 'TaggedTemplateExpression':
337
+ return node.tag;
338
+ default:
339
+ return null;
340
+ }
341
+ }
342
+ function rootCalleeName(node) {
343
+ let current = node;
344
+ let receiver = calleeReceiver(current);
345
+ while (receiver) {
346
+ current = receiver;
347
+ receiver = calleeReceiver(current);
348
+ }
349
+ return current.type === 'Identifier' ? current.name : null;
350
+ }
351
+ /**
352
+ * Whether `node` bounds the statements a rule may read as "what ran before".
353
+ *
354
+ * A rule that reasons about UI state — which menu is open, what was selected —
355
+ * reads the statements preceding a gesture. That reading has to stop somewhere,
356
+ * and the boundary is the unit that runs as one: a test callback or a named
357
+ * function.
358
+ */
359
+ function isTestScopeBoundary(node) {
360
+ if (node.type === 'FunctionDeclaration') {
361
+ return true;
362
+ }
363
+ if (node.type !== 'FunctionExpression' &&
364
+ node.type !== 'ArrowFunctionExpression') {
365
+ return false;
366
+ }
367
+ const parent = node.parent;
368
+ if (parent?.type === 'VariableDeclarator' || parent?.type === 'Property') {
369
+ return true;
370
+ }
371
+ return (parent?.type === 'CallExpression' &&
372
+ parent.arguments.includes(node) &&
373
+ DEFERRED_CALLBACK_CALLEES.has(rootCalleeName(parent.callee) ?? ''));
374
+ }
375
+ /**
376
+ * The innermost test callback or named function containing `node`, which is
377
+ * where a lookback over preceding statements has to stop. Falls back to the
378
+ * `Program` for a gesture written at the top level of a file.
379
+ */
380
+ function enclosingTestScope(node) {
381
+ let scope = node;
382
+ while (scope.parent && !isTestScopeBoundary(scope)) {
383
+ scope = scope.parent;
384
+ }
385
+ return scope;
386
+ }
@@ -1,4 +1,5 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
+ import { TSESLint } from '@typescript-eslint/utils';
2
3
  import * as ts from 'typescript';
3
4
  export type JupyterPluginKind = 'frontend' | 'service-manager';
4
5
  /**
@@ -12,9 +13,23 @@ export declare function getJupyterPluginKind(node: TSESTree.VariableDeclarator,
12
13
  */
13
14
  export declare function getObjectProperties(obj: TSESTree.ObjectExpression): Map<string, TSESTree.Property>;
14
15
  /**
15
- * Gets the plugin ID from an object expression
16
+ * Gets the plugin ID from an object expression. Without a scope only a
17
+ * literal, a template literal without substitutions or a `+` chain of literals
18
+ * resolves. With a scope, a `const` string and a member of a `const` object
19
+ * resolve too, and with a checker so does anything with a string literal
20
+ * type, such as a `const` imported from another module.
16
21
  */
17
- export declare function getPluginId(obj: TSESTree.ObjectExpression): string | null;
22
+ export declare function getPluginId(obj: TSESTree.ObjectExpression, scope?: TSESLint.Scope.Scope | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): string | null;
23
+ /**
24
+ * Resolves an expression to the string it holds at lint time.
25
+ * `getStaticValue` folds the plain JavaScript part: a literal, a template
26
+ * literal, a `+` chain, a variable that is never reassigned and a member of an
27
+ * object literal that is never mutated, with TypeScript casts stripped. The
28
+ * checker then answers for the TypeScript part: a `const` imported from
29
+ * another module, a namespace member, an enum member or a `static readonly`
30
+ * class property.
31
+ */
32
+ export declare function resolveStaticString(node: TSESTree.Node, scope?: TSESLint.Scope.Scope | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): string | null;
18
33
  export interface TokenEntry {
19
34
  name: string;
20
35
  node: TSESTree.Node;
@@ -30,7 +45,14 @@ export declare function extractParameterType(param: TSESTree.Identifier): string
30
45
  * depth, so arrays, unions and wrappers such as `Promise<...>` are recognised.
31
46
  * Resolves import aliases through the TypeScript checker when it is available.
32
47
  */
33
- export declare function typeMentionsJupyterPlugin(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null, depth?: number): boolean;
48
+ export declare function typeMentionsJupyterPlugin(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): boolean;
49
+ /**
50
+ * Returns true when a type annotation mentions the MIME renderer extension
51
+ * entry type at any depth, with the same wrappers as
52
+ * `typeMentionsJupyterPlugin`. JupyterLab registers each entry as a plugin
53
+ * whose ID is the entry's `id`, so the entry follows the plugin ID convention.
54
+ */
55
+ export declare function typeMentionsMimeExtension(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): boolean;
34
56
  /**
35
57
  * Returns true when a property holds something callable: a function written in
36
58
  * place, or a name referring to one declared elsewhere.
@@ -40,6 +62,14 @@ export declare function isCallableProperty(property: TSESTree.Property | undefin
40
62
  * Returns true when an object literal has the shape of a JupyterLab plugin:
41
63
  * a string `id`, an `activate` function, and at least one of the properties
42
64
  * which only plugins carry. Used for plugin objects written without a type
43
- * annotation.
65
+ * annotation. A caller that resolves the ID itself passes whether one is
66
+ * present, so this check needs no type information.
67
+ */
68
+ export declare function looksLikePluginObject(node: TSESTree.ObjectExpression, hasId?: boolean): boolean;
69
+ /**
70
+ * Returns true when an object literal has the shape of a MIME renderer
71
+ * extension entry: a string `id` and a `rendererFactory`. Used for entries
72
+ * written without a type annotation. A caller that resolves the ID itself
73
+ * passes whether one is present.
44
74
  */
45
- export declare function looksLikePluginObject(node: TSESTree.ObjectExpression): boolean;
75
+ export declare function looksLikeMimeExtensionObject(node: TSESTree.ObjectExpression, hasId?: boolean): boolean;
@@ -40,12 +40,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.getJupyterPluginKind = getJupyterPluginKind;
41
41
  exports.getObjectProperties = getObjectProperties;
42
42
  exports.getPluginId = getPluginId;
43
+ exports.resolveStaticString = resolveStaticString;
43
44
  exports.extractArrayTokens = extractArrayTokens;
44
45
  exports.isNullableAnnotation = isNullableAnnotation;
45
46
  exports.extractParameterType = extractParameterType;
46
47
  exports.typeMentionsJupyterPlugin = typeMentionsJupyterPlugin;
48
+ exports.typeMentionsMimeExtension = typeMentionsMimeExtension;
47
49
  exports.isCallableProperty = isCallableProperty;
48
50
  exports.looksLikePluginObject = looksLikePluginObject;
51
+ exports.looksLikeMimeExtensionObject = looksLikeMimeExtensionObject;
52
+ const utils_1 = require("@typescript-eslint/utils");
49
53
  const ts = __importStar(require("typescript"));
50
54
  /**
51
55
  * Gets plugin kind from a variable declaration type annotation.
@@ -104,28 +108,46 @@ function getObjectProperties(obj) {
104
108
  return props;
105
109
  }
106
110
  /**
107
- * Gets the plugin ID from an object expression
111
+ * Gets the plugin ID from an object expression. Without a scope only a
112
+ * literal, a template literal without substitutions or a `+` chain of literals
113
+ * resolves. With a scope, a `const` string and a member of a `const` object
114
+ * resolve too, and with a checker so does anything with a string literal
115
+ * type, such as a `const` imported from another module.
108
116
  */
109
- function getPluginId(obj) {
110
- for (const prop of obj.properties) {
111
- if (prop.type === 'Property') {
112
- let keyName = null;
113
- if (prop.key.type === 'Identifier') {
114
- keyName = prop.key.name;
115
- }
116
- else if (prop.key.type === 'Literal' &&
117
- typeof prop.key.value === 'string') {
118
- keyName = prop.key.value;
119
- }
120
- if (keyName === 'id' && prop.value.type === 'Literal') {
121
- const value = prop.value.value;
122
- if (typeof value === 'string') {
123
- return value;
124
- }
125
- }
117
+ function getPluginId(obj, scope, checker, getTSNode) {
118
+ const idProperty = getObjectProperties(obj).get('id');
119
+ return idProperty
120
+ ? resolveStaticString(idProperty.value, scope, checker, getTSNode)
121
+ : null;
122
+ }
123
+ /**
124
+ * Resolves an expression to the string it holds at lint time.
125
+ * `getStaticValue` folds the plain JavaScript part: a literal, a template
126
+ * literal, a `+` chain, a variable that is never reassigned and a member of an
127
+ * object literal that is never mutated, with TypeScript casts stripped. The
128
+ * checker then answers for the TypeScript part: a `const` imported from
129
+ * another module, a namespace member, an enum member or a `static readonly`
130
+ * class property.
131
+ */
132
+ function resolveStaticString(node, scope, checker, getTSNode) {
133
+ const folded = utils_1.ASTUtils.getStaticValue(node, scope ?? undefined);
134
+ if (typeof folded?.value === 'string') {
135
+ return folded.value;
136
+ }
137
+ if (!checker || !getTSNode) {
138
+ return null;
139
+ }
140
+ try {
141
+ const tsNode = getTSNode(node);
142
+ if (!tsNode) {
143
+ return null;
126
144
  }
145
+ const type = checker.getTypeAtLocation(tsNode);
146
+ return type.isStringLiteral() ? type.value : null;
147
+ }
148
+ catch {
149
+ return null;
127
150
  }
128
- return null;
129
151
  }
130
152
  /**
131
153
  * Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
@@ -207,44 +229,89 @@ function isPluginTypeName(name) {
207
229
  return PLUGIN_TYPE_NAMES.includes(lastSegment);
208
230
  }
209
231
  /**
210
- * Returns true when a type annotation mentions a JupyterLab plugin type at any
211
- * depth, so arrays, unions and wrappers such as `Promise<...>` are recognised.
212
- * Resolves import aliases through the TypeScript checker when it is available.
232
+ * Returns true when `matches` accepts a type reference found at any depth of
233
+ * a type annotation, so arrays, unions and wrappers such as `Promise<...>` are
234
+ * recognised.
213
235
  */
214
- function typeMentionsJupyterPlugin(typeNode, checker, getTSNode, depth = 0) {
236
+ function typeMentions(typeNode, matches, depth = 0) {
215
237
  if (!typeNode || depth > 6) {
216
238
  return false;
217
239
  }
218
240
  switch (typeNode.type) {
219
- case 'TSTypeReference': {
220
- if (isPluginTypeName(extractTypeName(typeNode.typeName))) {
221
- return true;
222
- }
223
- if (checker &&
224
- getTSNode &&
225
- typeNode.typeName.type === 'Identifier' &&
226
- isPluginTypeName(resolveTypeAlias(typeNode.typeName, checker, getTSNode))) {
241
+ case 'TSTypeReference':
242
+ if (matches(typeNode)) {
227
243
  return true;
228
244
  }
229
- return (typeNode.typeArguments?.params ?? []).some(param => typeMentionsJupyterPlugin(param, checker, getTSNode, depth + 1));
230
- }
245
+ return (typeNode.typeArguments?.params ?? []).some(param => typeMentions(param, matches, depth + 1));
231
246
  case 'TSArrayType':
232
- return typeMentionsJupyterPlugin(typeNode.elementType, checker, getTSNode, depth + 1);
247
+ return typeMentions(typeNode.elementType, matches, depth + 1);
233
248
  case 'TSUnionType':
234
249
  case 'TSIntersectionType':
235
- return typeNode.types.some(type => typeMentionsJupyterPlugin(type, checker, getTSNode, depth + 1));
250
+ return typeNode.types.some(type => typeMentions(type, matches, depth + 1));
236
251
  case 'TSTupleType':
237
- return typeNode.elementTypes.some(type => typeMentionsJupyterPlugin(type, checker, getTSNode, depth + 1));
252
+ return typeNode.elementTypes.some(type => typeMentions(type, matches, depth + 1));
238
253
  case 'TSTypeOperator':
239
254
  case 'TSRestType':
240
255
  case 'TSOptionalType':
241
- return typeMentionsJupyterPlugin(typeNode.typeAnnotation ?? null, checker, getTSNode, depth + 1);
256
+ return typeMentions(typeNode.typeAnnotation ?? null, matches, depth + 1);
242
257
  case 'TSNamedTupleMember':
243
- return typeMentionsJupyterPlugin(typeNode.elementType, checker, getTSNode, depth + 1);
258
+ return typeMentions(typeNode.elementType, matches, depth + 1);
244
259
  default:
245
260
  return false;
246
261
  }
247
262
  }
263
+ /**
264
+ * Returns true when a type annotation mentions a JupyterLab plugin type at any
265
+ * depth, so arrays, unions and wrappers such as `Promise<...>` are recognised.
266
+ * Resolves import aliases through the TypeScript checker when it is available.
267
+ */
268
+ function typeMentionsJupyterPlugin(typeNode, checker, getTSNode) {
269
+ return typeMentions(typeNode, reference => {
270
+ if (isPluginTypeName(extractTypeName(reference.typeName))) {
271
+ return true;
272
+ }
273
+ return (!!checker &&
274
+ !!getTSNode &&
275
+ reference.typeName.type === 'Identifier' &&
276
+ isPluginTypeName(resolveTypeAlias(reference.typeName, checker, getTSNode)));
277
+ });
278
+ }
279
+ /** The namespace and interface which type a MIME renderer extension entry. */
280
+ const MIME_EXTENSION_NAMESPACE = 'IRenderMime';
281
+ const MIME_EXTENSION_TYPE_NAME = 'IExtension';
282
+ /**
283
+ * Returns true when a type reference is `IRenderMime.IExtension`. Only the
284
+ * qualified spelling counts, because a bare `IExtension` is too common a name
285
+ * to mean anything on its own. The namespace may sit behind a module import
286
+ * (`Interfaces.IRenderMime.IExtension`), and a renamed import such as
287
+ * `import { IRenderMime as RM }` is resolved through the TypeScript checker
288
+ * when it is available.
289
+ */
290
+ function isMimeExtensionReference(reference, checker, getTSNode) {
291
+ const typeName = reference.typeName;
292
+ if (typeName.type !== 'TSQualifiedName' ||
293
+ typeName.right.name !== MIME_EXTENSION_TYPE_NAME) {
294
+ return false;
295
+ }
296
+ const namespace = extractTypeName(typeName.left)?.split('.').pop();
297
+ if (namespace === MIME_EXTENSION_NAMESPACE) {
298
+ return true;
299
+ }
300
+ return (!!checker &&
301
+ !!getTSNode &&
302
+ typeName.left.type === 'Identifier' &&
303
+ resolveTypeAlias(typeName.left, checker, getTSNode) ===
304
+ MIME_EXTENSION_NAMESPACE);
305
+ }
306
+ /**
307
+ * Returns true when a type annotation mentions the MIME renderer extension
308
+ * entry type at any depth, with the same wrappers as
309
+ * `typeMentionsJupyterPlugin`. JupyterLab registers each entry as a plugin
310
+ * whose ID is the entry's `id`, so the entry follows the plugin ID convention.
311
+ */
312
+ function typeMentionsMimeExtension(typeNode, checker, getTSNode) {
313
+ return typeMentions(typeNode, reference => isMimeExtensionReference(reference, checker, getTSNode));
314
+ }
248
315
  /**
249
316
  * Resolves an identifier through the TypeScript checker to the name it aliases,
250
317
  * e.g. `import { JupyterFrontEndPlugin as JFEP }` gives back the original name.
@@ -297,14 +364,12 @@ function isCallableProperty(property) {
297
364
  * Returns true when an object literal has the shape of a JupyterLab plugin:
298
365
  * a string `id`, an `activate` function, and at least one of the properties
299
366
  * which only plugins carry. Used for plugin objects written without a type
300
- * annotation.
367
+ * annotation. A caller that resolves the ID itself passes whether one is
368
+ * present, so this check needs no type information.
301
369
  */
302
- function looksLikePluginObject(node) {
370
+ function looksLikePluginObject(node, hasId = getPluginId(node) !== null) {
303
371
  const properties = getObjectProperties(node);
304
- const id = properties.get('id');
305
- if (!id ||
306
- id.value.type !== 'Literal' ||
307
- typeof id.value.value !== 'string') {
372
+ if (!hasId || !properties.has('id')) {
308
373
  return false;
309
374
  }
310
375
  if (!isCallableProperty(properties.get('activate'))) {
@@ -312,3 +377,13 @@ function looksLikePluginObject(node) {
312
377
  }
313
378
  return PLUGIN_SHAPE_PROPERTIES.some(name => properties.has(name));
314
379
  }
380
+ /**
381
+ * Returns true when an object literal has the shape of a MIME renderer
382
+ * extension entry: a string `id` and a `rendererFactory`. Used for entries
383
+ * written without a type annotation. A caller that resolves the ID itself
384
+ * passes whether one is present.
385
+ */
386
+ function looksLikeMimeExtensionObject(node, hasId = getPluginId(node) !== null) {
387
+ const properties = getObjectProperties(node);
388
+ return hasId && properties.has('id') && properties.has('rendererFactory');
389
+ }
@@ -40,6 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.getHostProvidedPackages = getHostProvidedPackages;
41
41
  const fs = __importStar(require("fs"));
42
42
  const path = __importStar(require("path"));
43
+ const package_json_1 = require("./package-json");
43
44
  /** How far to look upwards for the labextension manifest. */
44
45
  const MAX_LEVELS = 12;
45
46
  const manifestCache = new Map();
@@ -55,26 +56,15 @@ const manifestPathCache = new Map();
55
56
  * which removes the package from the shared scope altogether.
56
57
  */
57
58
  function readManifest(manifestPath) {
58
- let mtimeMs;
59
- try {
60
- mtimeMs = fs.statSync(manifestPath).mtimeMs;
61
- }
62
- catch {
59
+ const manifest = (0, package_json_1.readPackageJson)(manifestPath);
60
+ if (!manifest) {
63
61
  return null;
64
62
  }
65
63
  const cached = manifestCache.get(manifestPath);
66
- if (cached && cached.mtimeMs === mtimeMs) {
64
+ if (cached && cached.mtimeMs === manifest.mtimeMs) {
67
65
  return cached;
68
66
  }
69
- let data;
70
- try {
71
- data = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
72
- }
73
- catch {
74
- manifestCache.set(manifestPath, null);
75
- return null;
76
- }
77
- const jupyterlab = data.jupyterlab;
67
+ const jupyterlab = manifest.data.jupyterlab;
78
68
  if (!jupyterlab || typeof jupyterlab !== 'object') {
79
69
  // Not a labextension manifest, so keep looking further up.
80
70
  manifestCache.set(manifestPath, null);
@@ -89,7 +79,7 @@ function readManifest(manifestPath) {
89
79
  hostProvided.push(name);
90
80
  }
91
81
  }
92
- const info = { mtimeMs, hostProvided };
82
+ const info = { mtimeMs: manifest.mtimeMs, hostProvided };
93
83
  manifestCache.set(manifestPath, info);
94
84
  return info;
95
85
  }
@@ -1,18 +1,13 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
2
  import { ParserServices } from '@typescript-eslint/utils';
3
3
  import * as ts from 'typescript';
4
+ export { walkFrom } from './ast';
5
+ export type { WalkAction } from './ast';
4
6
  export type ClassLike = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
5
7
  export type SignalClassification = 'signal' | 'not-signal' | 'unknown';
6
8
  type ConnectCallExpression = TSESTree.CallExpression & {
7
9
  callee: TSESTree.MemberExpression;
8
10
  };
9
- export type WalkAction = 'skip-children' | 'stop' | undefined;
10
- /**
11
- * Iterative AST walk from `root`, visiting every node. The visitor may return
12
- * 'skip-children' to avoid descending into a node, or 'stop' to abort the
13
- * whole walk.
14
- */
15
- export declare function walkFrom(root: TSESTree.Node, visit: (node: TSESTree.Node) => WalkAction): void;
16
11
  /**
17
12
  * Checks if a node represents `<expr>.connect(...)`.
18
13
  */
@@ -140,4 +135,3 @@ export declare function looksLikeSignalByName(objectNode: TSESTree.Expression):
140
135
  * - 'unknown': no type information, `any`/`unknown`, or resolution failure
141
136
  */
142
137
  export declare function classifySignalReceiver(objectNode: TSESTree.Expression, checker: ts.TypeChecker | null, services: ParserServices | null): SignalClassification;
143
- export {};
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  };
38
38
  })();
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.walkFrom = walkFrom;
40
+ exports.walkFrom = void 0;
41
41
  exports.isConnectCall = isConnectCall;
42
42
  exports.isDisconnectCall = isDisconnectCall;
43
43
  exports.isDisposedSignalWiring = isDisposedSignalWiring;
@@ -54,45 +54,10 @@ exports.typeExtendsLuminoWidget = typeExtendsLuminoWidget;
54
54
  exports.methodUsesThis = methodUsesThis;
55
55
  exports.looksLikeSignalByName = looksLikeSignalByName;
56
56
  exports.classifySignalReceiver = classifySignalReceiver;
57
- const visitor_keys_1 = require("@typescript-eslint/visitor-keys");
57
+ const ast_1 = require("./ast");
58
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
- }
59
+ var ast_2 = require("./ast");
60
+ Object.defineProperty(exports, "walkFrom", { enumerable: true, get: function () { return ast_2.walkFrom; } });
96
61
  /**
97
62
  * Checks if a call expression is a non-computed `<expr>.<name>(...)` call.
98
63
  */
@@ -354,7 +319,7 @@ function resolveUnboundThisMethodConnect(node) {
354
319
  */
355
320
  function classHasCleanupEvidence(classNode, signalLocalNames, extraMethodNames = []) {
356
321
  let found = false;
357
- walkFrom(classNode.body, node => {
322
+ (0, ast_1.walkFrom)(classNode.body, node => {
358
323
  if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
359
324
  return 'skip-children';
360
325
  }
@@ -385,7 +350,7 @@ const RECEIVER_CLEANUP_STATICS = [
385
350
  */
386
351
  function classUsesReceiverBasedCleanup(classNode, signalLocalNames) {
387
352
  let found = false;
388
- walkFrom(classNode.body, node => {
353
+ (0, ast_1.walkFrom)(classNode.body, node => {
389
354
  if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
390
355
  return 'skip-children';
391
356
  }
@@ -487,7 +452,7 @@ function typeExtendsLuminoWidget(type, checker) {
487
452
  */
488
453
  function methodUsesThis(fn) {
489
454
  let found = false;
490
- walkFrom(fn.body, node => {
455
+ (0, ast_1.walkFrom)(fn.body, node => {
491
456
  if (node.type === 'FunctionExpression' ||
492
457
  node.type === 'FunctionDeclaration' ||
493
458
  node.type === 'TSDeclareFunction' ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/eslint-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "ESLint plugin for Jupyter core and extensions with early error catching and best practices enforcement",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",